[or-cvs] r12880: Implement support for networkstatus files. Right now, we onl (in bridgedb/trunk: . lib/bridgedb)

nickm at seul.org nickm at seul.org
Thu Dec 20 04:50:00 UTC 2007


Author: nickm
Date: 2007-12-19 23:50:00 -0500 (Wed, 19 Dec 2007)
New Revision: 12880

Modified:
   bridgedb/trunk/
   bridgedb/trunk/lib/bridgedb/Bridges.py
   bridgedb/trunk/lib/bridgedb/Main.py
Log:
 r17266 at catbus:  nickm | 2007-12-19 23:49:57 -0500
 Implement support for networkstatus files.  Right now, we only use them if present, and only decline to hand outbridges that are listed and listed as non-running.  Later, we should decline to hand out unlisted bridges too.



Property changes on: bridgedb/trunk
___________________________________________________________________
 svk:merge ticket from /bridgedb/trunk [r17266] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: bridgedb/trunk/lib/bridgedb/Bridges.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Bridges.py	2007-12-19 22:57:56 UTC (rev 12879)
+++ bridgedb/trunk/lib/bridgedb/Bridges.py	2007-12-20 04:50:00 UTC (rev 12880)
@@ -106,6 +106,7 @@
         self.nickname = nickname
         self.ip = ip
         self.orport = orport
+        self.running = None
         if id_digest is not None:
             assert fingerprint is None
             if len(id_digest) != DIGEST_LEN:
@@ -137,6 +138,11 @@
         assert is_valid_fingerprint(self.fingerprint)
         assert 1 <= self.orport <= 65535
 
+    def setStatus(self, running=None):
+        if running is not None:
+            self.running = running
+
+
 def parseDescFile(f, bridge_purpose='bridge'):
     """Generator. Parses a cached-descriptors file 'f', and yields a Bridge
        object for every entry whose purpose matches bridge_purpose.
@@ -168,6 +174,28 @@
                 yield b
             nickname = ip = orport = fingerprint = purpose = None
 
+def parseStatusFile(f):
+    """DOCDOC"""
+    result = None
+    ID = None
+    for line in f:
+        line = line.strip()
+        if line.startswith("opt "):
+            line = line[4:]
+
+        if line.startswith("r "):
+            try:
+                ID = binascii.a2b_base64(line.split()[2]+"=")
+            except binascii.Error:
+                logging.warn("Unparseable base64 ID %r", line.split()[2])
+        elif ID and line.startswith("s "):
+            flags = line.split()
+            if "Running" in flags:
+                yield ID, True
+            else:
+                yield ID, False
+            ID = None
+
 class BridgeHolder:
     """Abstract base class for all classes that hold bridges."""
     def insert(self, bridge):
@@ -394,6 +422,10 @@
         assert self.rings
         for s in self.statsHolders:
             s.insert(bridge)
+        if bridge.running == False:
+            #XXXX Turn this to False or None.
+            return
+
         bridgeID = bridge.getID()
         ringname = self.store.get(bridgeID, "")
         ring = self.ringsByName.get(ringname)

Modified: bridgedb/trunk/lib/bridgedb/Main.py
===================================================================
--- bridgedb/trunk/lib/bridgedb/Main.py	2007-12-19 22:57:56 UTC (rev 12879)
+++ bridgedb/trunk/lib/bridgedb/Main.py	2007-12-20 04:50:00 UTC (rev 12880)
@@ -35,6 +35,7 @@
     LOGLEVEL = "DEBUG",
 
     BRIDGE_FILES = [ "./cached-descriptors", "./cached-descriptors.new" ],
+    STATUS_FILE = "networkstatus-bridges",
     BRIDGE_PURPOSE = "bridge",
     DB_FILE = "./bridgedist.db",
     DB_LOG_FILE = "./bridgedist.log",
@@ -113,9 +114,17 @@
     """Read all the bridge files from cfg, and pass them into a splitter
        object.
     """
+    status = {}
+    if cfg.STATUS_FILE:
+        f = open(cfg.STATUS_FILE, 'r')
+        for ID, running in Bridges.parseStatusFile(f):
+            status[ID] = running
     for fname in cfg.BRIDGE_FILES:
         f = open(fname, 'r')
         for bridge in Bridges.parseDescFile(f, cfg.BRIDGE_PURPOSE):
+            running = status.get(bridge.getID())
+            if running is not None:
+                bridge.setStatus(running=running)
             splitter.insert(bridge)
         f.close()
 



More information about the tor-commits mailing list