[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Include bridges when filtering by flag.



commit 2d970fdb60f8b6378d663c967f877194efcabd38
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Feb 24 10:12:49 2014 +0100

    Include bridges when filtering by flag.
    
    Fixes #10908.
---
 src/org/torproject/onionoo/ResponseBuilder.java    |   29 ++++++++++++++++++--
 .../torproject/onionoo/ResourceServletTest.java    |    4 +--
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/org/torproject/onionoo/ResponseBuilder.java b/src/org/torproject/onionoo/ResponseBuilder.java
index 898f957..502b928 100644
--- a/src/org/torproject/onionoo/ResponseBuilder.java
+++ b/src/org/torproject/onionoo/ResponseBuilder.java
@@ -28,7 +28,7 @@ public class ResponseBuilder {
   private static Map<String, String> relayFingerprintSummaryLines = null,
       bridgeFingerprintSummaryLines = null;
   private static Map<String, Set<String>> relaysByCountryCode = null,
-      relaysByASNumber = null, relaysByFlag = null,
+      relaysByASNumber = null, relaysByFlag = null, bridgesByFlag = null,
       relaysByContact = null;
   private static SortedMap<Integer, Set<String>>
       relaysByFirstSeenDays = null, bridgesByFirstSeenDays = null,
@@ -84,6 +84,7 @@ public class ResponseBuilder {
           newRelaysByCountryCode = new HashMap<String, Set<String>>(),
           newRelaysByASNumber = new HashMap<String, Set<String>>(),
           newRelaysByFlag = new HashMap<String, Set<String>>(),
+          newBridgesByFlag = new HashMap<String, Set<String>>(),
           newRelaysByContact = new HashMap<String, Set<String>>();
       SortedMap<Integer, Set<String>>
           newRelaysByFirstSeenDays = new TreeMap<Integer, Set<String>>(),
@@ -200,6 +201,15 @@ public class ResponseBuilder {
         newBridgeFingerprintSummaryLines.put(hashedFingerprint, line);
         newBridgeFingerprintSummaryLines.put(hashedHashedFingerprint,
             line);
+        for (String flag : entry.getRelayFlags()) {
+          String flagLowerCase = flag.toLowerCase();
+          if (!newBridgesByFlag.containsKey(flagLowerCase)) {
+            newBridgesByFlag.put(flagLowerCase, new HashSet<String>());
+          }
+          newBridgesByFlag.get(flagLowerCase).add(hashedFingerprint);
+          newBridgesByFlag.get(flagLowerCase).add(
+              hashedHashedFingerprint);
+        }
         int daysSinceFirstSeen = (int) ((newSummaryFileLastModified
             - entry.getFirstSeenMillis()) / 86400000L);
         if (!newBridgesByFirstSeenDays.containsKey(daysSinceFirstSeen)) {
@@ -227,6 +237,7 @@ public class ResponseBuilder {
       relaysByCountryCode = newRelaysByCountryCode;
       relaysByASNumber = newRelaysByASNumber;
       relaysByFlag = newRelaysByFlag;
+      bridgesByFlag = newBridgesByFlag;
       relaysByContact = newRelaysByContact;
       relaysByFirstSeenDays = newRelaysByFirstSeenDays;
       relaysByLastSeenDays = newRelaysByLastSeenDays;
@@ -569,7 +580,21 @@ public class ResponseBuilder {
         filteredRelays.remove(fingerprint);
       }
     }
-    filteredBridges.clear();
+    if (!this.bridgesByFlag.containsKey(flag)) {
+      filteredBridges.clear();
+    } else {
+      Set<String> bridgesWithFlag = bridgesByFlag.get(flag);
+      Set<String> removeBridges = new HashSet<String>();
+      for (Map.Entry<String, String> e : filteredBridges.entrySet()) {
+        String fingerprint = e.getKey();
+        if (!bridgesWithFlag.contains(fingerprint)) {
+          removeBridges.add(fingerprint);
+        }
+      }
+      for (String fingerprint : removeBridges) {
+        filteredBridges.remove(fingerprint);
+      }
+    }
   }
 
   private void filterNodesByFirstSeenDays(
diff --git a/test/org/torproject/onionoo/ResourceServletTest.java b/test/org/torproject/onionoo/ResourceServletTest.java
index 51ea1b5..37963c8 100644
--- a/test/org/torproject/onionoo/ResourceServletTest.java
+++ b/test/org/torproject/onionoo/ResourceServletTest.java
@@ -819,13 +819,13 @@ public class ResourceServletTest {
   @Test()
   public void testFlagRunning() {
     this.assertSummaryDocument(
-        "/summary?flag=Running", 3, null, 0, null);
+        "/summary?flag=Running", 3, null, 1, null);
   }
 
   @Test()
   public void testFlagValid() {
     this.assertSummaryDocument(
-        "/summary?flag=Valid", 3, null, 0, null);
+        "/summary?flag=Valid", 3, null, 3, null);
   }
 
   @Test()

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits