[tor-commits] [bridgedb/develop] Add subring numbers to their names to improve log clarity.

isis at torproject.org isis at torproject.org
Thu Jun 25 07:10:55 UTC 2015


commit aecbe451d65f55e92de3554ef8a17bb858dda3e1
Author: Isis Lovecruft <isis at torproject.org>
Date:   Tue Apr 21 02:47:09 2015 +0000

    Add subring numbers to their names to improve log clarity.
    
     * CHANGE bridgedb.Filters.filterAssignBridgesToRing() to rename
       generated filter functions to include the subring number and the
       total number of subrings, e.g.
         filter.__name__ = "filterAssignBridgesToRing3of4"
    
     * CHANGE bridgedb.Bridges.FilteredBridgeSplitter.addRing() to name
       subrings based on their number.  For example, if an HTTPSDistributor
       has 3 total subrings and subring 3/3 is for known-proxy users, then
       the subrings would be named like:
         - HTTPS-IP4-1of3
         - HTTPS-IP4-2of3
         - HTTPS-IP4-Proxy
         - HTTPS-IP6-1of3
         - HTTPS-IP6-2of3
         - HTTPS-IP6-Proxy
---
 lib/bridgedb/Bridges.py |   18 +++++++++++++-----
 lib/bridgedb/Filters.py |   10 ++++------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index 4b77cdc..507013d 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -613,13 +613,21 @@ class FilteredBridgeSplitter(object):
 
         filterNames = self.extractFilterNames(ringname)
         subringName = [self.distributorName]
+        subringNumber = None
         for filterName in filterNames:
-            if filterName != 'filterAssignBridgesToRing':
-                subringName.append(filterName.strip('filterBridgesBy'))
+            if filterName.startswith('filterAssignBridgesToRing'):
+                subringNumber = filterName.lstrip('filterAssignBridgesToRing')
+            else:
+                subringName.append(filterName.lstrip('filterBridgesBy'))
+        if subring.name and 'Proxy' in subring.name:
+            subringName.append('Proxy')
+        elif subringNumber:
+            subringName.append(subringNumber)
         subringName = '-'.join([x for x in subringName])
         subring.setName(subringName)
 
-        logging.info("Adding subring to %s hashring..." % subring.name)
+        logging.info("Adding %s subring %s to the %s Distributor's hashring..." %
+                     (subring.name, subringNumber, self.distributorName))
         logging.info("  Subring filters: %s" % filterNames)
 
         #TODO: drop LRU ring if len(self.filterRings) > self.max_cached_rings
@@ -631,8 +639,8 @@ class FilteredBridgeSplitter(object):
                 if isinstance(bridge, Bridge) and filterFn(bridge):
                     subring.insert(bridge)
                     inserted += 1
-            logging.info("Bridges inserted into %s subring: %d"
-                         % (subring.name, inserted))
+            logging.info("Bridges inserted into %s subring %s: %d"
+                         % (subring.name, subringNumber, inserted))
 
         return True
 
diff --git a/lib/bridgedb/Filters.py b/lib/bridgedb/Filters.py
index fb0197b..cb5e782 100644
--- a/lib/bridgedb/Filters.py
+++ b/lib/bridgedb/Filters.py
@@ -8,11 +8,9 @@ import logging
 funcs = {}
 
 def filterAssignBridgesToRing(hmac, numRings, assignedRing):
-    #XXX: ruleset should have a key unique to this function
-    # ruleset ensures that the same 
-    logging.debug("Creating a filter for assigning bridges to hashrings...")
+    logging.debug(("Creating a filter for assigning bridges to subhashring "
+                   "%s-of-%s...") % (assignedRing, numRings))
     ruleset = frozenset([hmac, numRings, assignedRing]) 
-
     try: 
         return funcs[ruleset]
     except KeyError:
@@ -24,8 +22,8 @@ def filterAssignBridgesToRing(hmac, numRings, assignedRing):
             if which == assignedRing:
                 return True
             return False
-        _assignBridgesToRing.__name__ = ("filterAssignBridgesToRing(%s, %s, %s)"
-                                         % (hmac, numRings, assignedRing))
+        _assignBridgesToRing.__name__ = ("filterAssignBridgesToRing%sof%s"
+                                         % (assignedRing, numRings))
         # XXX The `description` attribute must contain an `=`, or else
         # dumpAssignments() will not work correctly.
         setattr(_assignBridgesToRing, "description", "ring=%d" % assignedRing)





More information about the tor-commits mailing list