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

[tor-commits] [stem/master] Parsing transport lines in non-bridge relays



commit 3f380f95876baffe48725828c23706dd9b46b760
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Aug 4 19:49:39 2012 -0700

    Parsing transport lines in non-bridge relays
    
    Spotted a relay in the wild with a transport line and asn thinks that, though
    it's an oddity and doesn't make sense for non-bridges, this isn't a bug...
    extra-info toorvoid 0B37323298FF98CD86ED404895BB27B7426E8AE1
    published 2012-08-04 12:19:13
    transport obfs2 83.212.96.201:33570
    
    Expanding the parser to allow for it in any extrainfo descriptor.
---
 stem/descriptor/extrainfo_descriptor.py      |   29 ++++++++++++++-----------
 test/unit/descriptor/extrainfo_descriptor.py |    8 +++++-
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index be2a6dc..8d66df6 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -179,6 +179,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
   :var str fingerprint: **\*** identity key fingerprint
   :var datetime published: **\*** time in GMT when this descriptor was made
   :var str geoip_db_digest: sha1 of geoIP database file
+  :var list transport: transport method recognized by the bridge (ex. obfs3)
   
   **Bi-directional connection usage:**
   
@@ -287,6 +288,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
     self.fingerprint = None
     self.published = None
     self.geoip_db_digest = None
+    self.transport = None
     
     self.conn_bi_direct_end = None
     self.conn_bi_direct_interval = None
@@ -421,6 +423,19 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
           raise ValueError("Geoip digest line had an invalid sha1 digest: %s" % line)
         
         self.geoip_db_digest = value
+      elif keyword == "transport":
+        # "transport" transportname address:port [arglist]
+        # Everything after the transportname is scrubbed in published bridge
+        # descriptors, so we'll never see it in practice.
+        #
+        # These entries really only make sense for bridges, but have been seen
+        # on non-bridges in the wild when the relay operator configured it this
+        # way.
+        
+        if self.transport is None:
+          self.transport = []
+        
+        self.transport.append(value)
       elif keyword == "cell-circuits-per-decile":
         # "cell-circuits-per-decile" num
         
@@ -746,12 +761,10 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
   """
   Bridge extra-info descriptor (`specification <https://metrics.torproject.org/formats.html#bridgedesc>`_)
   
-  :var list transport: transport method recognized by the bridge (ex. obfs3)
   """
   
   def __init__(self, raw_contents, validate = True):
     self._digest = None
-    self.transport = None
     
     super(BridgeExtraInfoDescriptor, self).__init__(raw_contents, validate)
   
@@ -766,17 +779,7 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
       value, _ = values[0]
       line = "%s %s" % (keyword, value) # original line
       
-      if keyword == "transport":
-        # "transport" transportname address:port [arglist]
-        # Everything after the transportname is scrubbed in published bridge
-        # descriptors, so we'll never see it in practice.
-        
-        if self.transport is None:
-          self.transport = []
-        
-        self.transport.append(value)
-        del entries["transport"]
-      elif keyword == "router-digest":
+      if keyword == "router-digest":
         if validate and not stem.util.tor_tools.is_hex_digits(value, 40):
           raise ValueError("Router digest line had an invalid sha1 digest: %s" % line)
         
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index c40ac94..1008af7 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -522,14 +522,18 @@ class TestExtraInfoDescriptor(unittest.TestCase):
   
   def test_transport_line(self):
     """
-    Basic exercise of the bridge descriptor's transport entry.
-    attributes.
+    Basic exercise for both a bridge and relay's transport entry.
     """
     
     desc_text = _make_descriptor({"transport": "obfs3"}, is_bridge = True)
     desc = BridgeExtraInfoDescriptor(desc_text)
     self.assertEquals(["obfs3"], desc.transport)
     self.assertEquals([], desc.get_unrecognized_lines())
+    
+    desc_text = _make_descriptor({"transport": "obfs2 83.212.96.201:33570"})
+    desc = RelayExtraInfoDescriptor(desc_text)
+    self.assertEquals(["obfs2 83.212.96.201:33570"], desc.transport)
+    self.assertEquals([], desc.get_unrecognized_lines())
   
   def _expect_invalid_attr(self, desc_text, attr = None, expected_value = None):
     """

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