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

[tor-commits] [bridgedb/master] 6175 - Return fewer bridges from shorter rings.



commit e35809195e3cbe8aa8fb877e5b246e190120403c
Author: aagbsn <aagbsn@xxxxxxxx>
Date:   Wed Jun 20 04:26:42 2012 -0700

    6175 - Return fewer bridges from shorter rings.
---
 lib/bridgedb/Dist.py |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py
index ec13fb5..0241c32 100644
--- a/lib/bridgedb/Dist.py
+++ b/lib/bridgedb/Dist.py
@@ -31,6 +31,15 @@ def uniformMap(ip):
     else:
         return ".".join( ip.split(".")[:3] )
 
+def getNumBridgesPerAnswer(ring, max_bridges_per_answer=3):
+    if len(ring) < 20: n_bridges_per_answer = 1
+    if 20 < len(ring) < 100: n_bridges_per_answer = min(2, max_bridges_per_answer)
+    if len(ring) > 100: n_bridges_per_answer = max_bridges_per_answer
+
+    logging.debug("Returning %d bridges from ring of len: %d" % \
+            (n_bridges_per_answer, len(ring)))
+    return n_bridges_per_answer
+
 class IPBasedDistributor(bridgedb.Bridges.BridgeHolder):
     """Object that hands out bridges based on the IP address of an incoming
        request and the current time period.
@@ -186,8 +195,8 @@ class IPBasedDistributor(bridgedb.Bridges.BridgeHolder):
             self.splitter.addRing(ring, ruleset, filterBridgesByRules(bridgeFilterRules),
                                   populate_from=self.splitter.bridges)
 
-        # get the bridge.
-        return ring.getBridges(pos, N)
+        # get an appropriate number of bridges
+        return ring.getBridges(pos, getNumBridgesPerAnswer(ring, max_bridges_per_answer=N))
 
     def __len__(self):
         return len(self.splitter)
@@ -195,6 +204,7 @@ class IPBasedDistributor(bridgedb.Bridges.BridgeHolder):
     def dumpAssignments(self, f, description=""):
         self.splitter.dumpAssignments(f, description)
 
+
 # These characters are the ones that RFC2822 allows.
 #ASPECIAL = '!#$%&*+-/=?^_`{|}~'
 #ASPECIAL += "\\\'"
@@ -389,7 +399,7 @@ class EmailBasedDistributor(bridgedb.Bridges.BridgeHolder):
                                   filterBridgesByRules(bridgeFilterRules),
                                   populate_from=self.splitter.bridges)
 
-        result = ring.getBridges(pos, N)
+        result = ring.getBridges(pos, getNumBridgesPerAnswer(ring, max_bridges_per_answer=N))
 
         db.setEmailTime(emailaddress, now)
         db.commit()



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