[or-cvs] r19660: {bridgedb} Clear the bridge lists before reloading. This should keep us (bridgedb/trunk/lib/bridgedb)

nickm at seul.org nickm at seul.org
Mon Jun 8 15:37:42 UTC 2009


Author: nickm
Date: 2009-06-08 11:37:41 -0400 (Mon, 08 Jun 2009)
New Revision: 19660

Modified:
   bridgedb/trunk/lib/bridgedb/Bridges.py
   bridgedb/trunk/lib/bridgedb/Dist.py
   bridgedb/trunk/lib/bridgedb/Main.py
Log:
Clear the bridge lists before reloading.  This should keep us from leaving delisted bridges in the list forever.

Modified: bridgedb/trunk/lib/bridgedb/Bridges.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Bridges.py	2009-06-08 15:21:13 UTC (rev 19659)
+++ bridgedb/trunk/lib/bridgedb/Bridges.py	2009-06-08 15:37:41 UTC (rev 19660)
@@ -100,6 +100,7 @@
     ##   orport -- The bridge's OR port.
     ##   fingerprint -- The bridge's identity digest, in lowercase hex, with
     ##       no spaces.
+    ##   running,stable -- DOCDOC
     def __init__(self, nickname, ip, orport, fingerprint=None, id_digest=None):
         """Create a new Bridge.  One of fingerprint and id_digest must be
            set."""
@@ -199,6 +200,9 @@
     def insert(self, bridge):
         raise NotImplemented()
 
+    def clear(self):
+        pass
+
     def assignmentsArePersistent(self):
         return True
 
@@ -262,6 +266,11 @@
     def __len__(self):
         return len(self.bridges)
 
+    def clear(self):
+        self.bridges = {}
+        self.bridgesByID = {}
+        self.sortedKeys = []
+
     def insert(self, bridge):
         """Add a bridge to the ring.  If the bridge is already there,
            replace the old one."""
@@ -406,6 +415,10 @@
         which = pos % len(self.rings)
         self.rings[which].insert(bridge)
 
+    def clear(self):
+        for r in self.rings:
+            r.clear()
+
     def __len__(self):
         n = 0
         for r in self.rings:
@@ -482,6 +495,10 @@
         """
         self.statsHolders.append(t)
 
+    def clear(self):
+        for r in self.rings:
+            r.clear()
+
     def insert(self, bridge):
         assert self.rings
         for s in self.statsHolders:

Modified: bridgedb/trunk/lib/bridgedb/Dist.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Dist.py	2009-06-08 15:21:13 UTC (rev 19659)
+++ bridgedb/trunk/lib/bridgedb/Dist.py	2009-06-08 15:37:41 UTC (rev 19660)
@@ -65,6 +65,9 @@
         key4 = bridgedb.Bridges.get_hmac(key, "Assign-Areas-To-Rings")
         self.areaClusterHmac = bridgedb.Bridges.get_hmac_fn(key4, hex=True)
 
+    def clear(self):
+        self.splitter.clear()
+
     def insert(self, bridge):
         """Assign a bridge to this distributor."""
         self.splitter.insert(bridge)
@@ -215,6 +218,9 @@
         self.domainmap = domainmap
         self.domainrules = domainrules
 
+    def clear(self):
+        self.ring.clear()
+
     def insert(self, bridge):
         """Assign a bridge to this distributor."""
         self.ring.insert(bridge)

Modified: bridgedb/trunk/lib/bridgedb/Main.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Main.py	2009-06-08 15:21:13 UTC (rev 19659)
+++ bridgedb/trunk/lib/bridgedb/Main.py	2009-06-08 15:37:41 UTC (rev 19660)
@@ -121,10 +121,13 @@
 
     return k
 
-def load(cfg, splitter):
+def load(cfg, splitter, clear=False):
     """Read all the bridge files from cfg, and pass them into a splitter
        object.
     """
+    if clear:
+        logging.info("Clearing old bridges")
+        splitter.clear()
     logging.info("Loading bridges")
     status = {}
     if hasattr(cfg, "STATUS_FILE"):
@@ -269,7 +272,7 @@
     # Make the parse-bridges function get re-called on SIGHUP.
     def reload():
         logging.info("Caught SIGHUP")
-        load(cfg, splitter)
+        load(cfg, splitter, clear=True)
         proxyList.replaceProxyList(loadProxyList(cfg))
         logging.info("%d bridges loaded", len(splitter))
         if emailDistributor:



More information about the tor-commits mailing list