commit 6015cc35b9f54da04213e7198d2d2e515d7f7a5b Author: Isis Lovecruft isis@torproject.org Date: Wed Dec 24 08:39:40 2014 +0000
Add better logging to Filters.filterAssignBridgesToRing(). --- lib/bridgedb/Filters.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/lib/bridgedb/Filters.py b/lib/bridgedb/Filters.py index 79d50f8..ab8b74a 100644 --- a/lib/bridgedb/Filters.py +++ b/lib/bridgedb/Filters.py @@ -10,21 +10,31 @@ 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...") ruleset = frozenset([hmac, numRings, assignedRing]) + logging.debug("Filter created: %s" % ruleset) + try: return funcs[ruleset] except KeyError: - def f(bridge): - digest = hmac(bridge.getID()) + def _assignBridgesToRing(bridge): + digest = hmac(bridge.fingerprint) pos = long( digest[:8], 16 ) which = pos % numRings - if which == assignedRing: return True - return False - f.__name__ = "filterAssignBridgesToRing(%s, %s, %s)" % (hmac, numRings, - assignedRing) - setattr(f, "description", "ring=%d" % assignedRing) - funcs[ruleset] = f - return f + + if which == assignedRing: + return True + else: + logging.debug(("Bridge %s has calculated assignment %d; not " + "in correct ring %d.") + % (bridge, which, assignedRing)) + return False + + _assignBridgesToRing.__name__ = ("filterAssignBridgesToRing(%s, %s, %s)" + % (hmac, numRings, assignedRing)) + setattr(_assignBridgesToRing, "description", "ring=%d" % assignedRing) + funcs[ruleset] = _assignBridgesToRing + return _assignBridgesToRing
def filterBridgesByRules(rules): ruleset = frozenset(rules)