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

[tor-commits] [bridgedb/master] Ignore networkstatus documents (mostly), if configured to do so.



commit ccff2c10464b61d7f4654dd70529de1cc97946dc
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Thu Apr 30 06:16:44 2015 +0000

    Ignore networkstatus documents (mostly), if configured to do so.
    
     * FIXES #15866: https://bugs.torproject.org/15866
---
 lib/bridgedb/Main.py    |   17 +++++++++++++----
 lib/bridgedb/bridges.py |   32 +++++++++++++++++++++++---------
 2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
index 44413d2..88b386b 100644
--- a/lib/bridgedb/Main.py
+++ b/lib/bridgedb/Main.py
@@ -110,6 +110,10 @@ def load(state, splitter, clear=False):
 
     logging.info("Loading bridges...")
 
+    ignoreNetworkstatus = state.IGNORE_NETWORKSTATUS
+    if ignoreNetworkstatus:
+        logging.info("Ignoring BridgeAuthority networkstatus documents.")
+
     bridges = {}
     timestamps = {}
 
@@ -120,8 +124,7 @@ def load(state, splitter, clear=False):
     logging.info("Processing networkstatus descriptors...")
     for router in networkstatuses:
         bridge = Bridge()
-        bridge.updateFromNetworkStatus(router)
-
+        bridge.updateFromNetworkStatus(router, ignoreNetworkstatus)
         try:
             bridge.assertOK()
         except MalformedBridgeInfo as error:
@@ -136,12 +139,18 @@ def load(state, splitter, clear=False):
 
         for router in serverdescriptors:
             try:
-                bridges[router.fingerprint].updateFromServerDescriptor(router)
+                bridge = bridges[router.fingerprint]
             except KeyError:
                 logging.warn(
                     ("Received server descriptor for bridge '%s' which wasn't "
                      "in the networkstatus!") % router.fingerprint)
-                continue
+                if ignoreNetworkstatus:
+                    bridge = Bridge()
+                else:
+                    continue
+
+            try:
+                bridge.updateFromServerDescriptor(router, ignoreNetworkstatus)
             except (ServerDescriptorWithoutNetworkstatus,
                     MissingServerDescriptorDigest,
                     ServerDescriptorDigestMismatch) as error:
diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py
index 93b9fe9..65a462c 100644
--- a/lib/bridgedb/bridges.py
+++ b/lib/bridgedb/bridges.py
@@ -1379,33 +1379,38 @@ class Bridge(BridgeBackwardsCompatibility):
         """
         return list(set([pt.methodname for pt in self.transports]))
 
-    def updateFromNetworkStatus(self, descriptor):
+    def updateFromNetworkStatus(self, descriptor, ignoreNetworkstatus=False):
         """Update this bridge's attributes from a parsed networkstatus
         document.
 
         :type descriptor:
             :api:`stem.descriptors.router_status_entry.RouterStatusEntry`
         :param descriptor: The networkstatus document for this bridge.
+        :param bool ignoreNetworkstatus: If ``True``, then ignore most of the
+           information in the networkstatus document.
         """
         self.descriptors['networkstatus'] = descriptor
 
         # These fields are *only* found in the networkstatus document:
-        self.descriptorDigest = descriptor.digest
         self.flags.update(descriptor.flags)
-        self.bandwidth = descriptor.bandwidth
+        self.descriptorDigest = descriptor.digest
+
+        if not ignoreNetworkstatus:
+            self.bandwidth = descriptor.bandwidth
 
         # These fields are also found in the server-descriptor. We will prefer
         # to use the information taken later from the server-descriptor
         # because it is signed by the bridge. However, for now, we harvest all
         # the info we can:
         self.fingerprint = descriptor.fingerprint
-        self.nickname = descriptor.nickname
-        self.address = descriptor.address
-        self.orPort = descriptor.or_port
 
-        self._updateORAddresses(descriptor.or_addresses)
+        if not ignoreNetworkstatus:
+            self.nickname = descriptor.nickname
+            self.address = descriptor.address
+            self.orPort = descriptor.or_port
+            self._updateORAddresses(descriptor.or_addresses)
 
-    def updateFromServerDescriptor(self, descriptor):
+    def updateFromServerDescriptor(self, descriptor, ignoreNetworkstatus=False):
         """Update this bridge's info from an ``@type bridge-server-descriptor``.
 
         .. info::
@@ -1425,7 +1430,16 @@ class Bridge(BridgeBackwardsCompatibility):
             networkstatus entry, or its **descriptor** digest didn't match the
             expected digest (from the networkstatus entry).
         """
-        self._checkServerDescriptor(descriptor)
+        if ignoreNetworkstatus:
+            try:
+                self._checkServerDescriptor(descriptor)
+            except (ServerDescriptorWithoutNetworkstatus,
+                    MissingServerDescriptorDigest,
+                    ServerDescriptorDigestMismatch) as ignored:
+                logging.warn(ignored)
+        else:
+            self._checkServerDescriptor(descriptor)
+
         self.descriptors['server'] = descriptor
 
         # Replace the values which we harvested from the networkstatus



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