commit 4a84b47b6ebbd3a740884fd8e24f499b79582028 Author: Damian Johnson atagar@torproject.org Date: Sat Aug 24 10:57:59 2013 -0700
Adding support for extrainfo descriptor's 'bridge-ip-transports'
Support for a new bridge-specific extrainfo descriptor field...
https://gitweb.torproject.org/torspec.git/commitdiff/a01bb8e8e
These are pretty much identical to bridge-ip-versions lines. Like those this is part of the ExtraInfoDescriptor class rather than BridgeExtraInfoDescriptor because the spec doesn't prohibit its appearance in public relays (though it doesn't really make sense there). --- stem/descriptor/extrainfo_descriptor.py | 16 ++++++++++++++++ test/unit/descriptor/extrainfo_descriptor.py | 14 ++++++++++++++ test/unit/descriptor/tordnsel.py | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index a314e86..7bfbd5a 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -310,6 +310,7 @@ class ExtraInfoDescriptor(Descriptor): :var datetime geoip_start_time: replaced by bridge_stats_end (deprecated) :var dict geoip_client_origins: replaced by bridge_ips (deprecated) :var dict ip_versions: mapping of ip protocols to a rounded count for the number of users + :var dict ip_versions: mapping of ip transports to a count for the number of users
***** attribute is either required when we're parsed with validation or has a default value, others are left as **None** if undefined @@ -406,6 +407,7 @@ class ExtraInfoDescriptor(Descriptor): self.geoip_client_origins = None
self.ip_versions = None + self.ip_transports = None
self._unrecognized_lines = []
@@ -803,6 +805,20 @@ class ExtraInfoDescriptor(Descriptor): raise stem.ProtocolError("IP protocol count was non-numeric (%s): %s" % (count, line))
self.ip_versions[protocol] = int(count) + elif keyword == "bridge-ip-transports": + self.ip_transports = {} + + if value: + for entry in value.split(','): + if not '=' in entry: + raise stem.ProtocolError("The bridge-ip-transports should be a comma separated listing of '<protocol>=<count>' mappings: %s" % line) + + protocol, count = entry.split('=', 1) + + if not count.isdigit(): + raise stem.ProtocolError("Transport count was non-numeric (%s): %s" % (count, line)) + + self.ip_transports[protocol] = int(count) else: self._unrecognized_lines.append(line)
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py index 957c861..b2c46b6 100644 --- a/test/unit/descriptor/extrainfo_descriptor.py +++ b/test/unit/descriptor/extrainfo_descriptor.py @@ -474,6 +474,20 @@ class TestExtraInfoDescriptor(unittest.TestCase): desc_text = get_bridge_extrainfo_descriptor({"bridge-ip-versions": "v4=24.5"}, content = True) self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text)
+ def test_bridge_ip_transports_line(self): + """ + Parses the 'bridge-ip-transports' line, which only appears in bridges. + """ + + desc = get_bridge_extrainfo_descriptor({"bridge-ip-transports": "<OR>=16,<??>=40"}) + self.assertEquals({'<OR>': 16, '<??>': 40}, desc.ip_transports) + + desc = get_bridge_extrainfo_descriptor({"bridge-ip-transports": ""}) + self.assertEquals({}, desc.ip_transports) + + desc_text = get_bridge_extrainfo_descriptor({"bridge-ip-transports": "<OR>=24.5"}, content = True) + self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text) + def test_transport_line(self): """ Basic exercise for both a bridge and relay's transport entry. diff --git a/test/unit/descriptor/tordnsel.py b/test/unit/descriptor/tordnsel.py index 4944a4b..af90f6d 100644 --- a/test/unit/descriptor/tordnsel.py +++ b/test/unit/descriptor/tordnsel.py @@ -81,7 +81,7 @@ class TestTorDNSELDescriptor(unittest.TestCase): self.assertRaises(ValueError, list, _parse_file(io.BytesIO(TEST_DESC + MALFORMED_ENTRY_1)))
# skip exit address if malformed date and validate is False - + desc = _parse_file(io.BytesIO(MALFORMED_ENTRY_2), validate=False).next() self.assertTrue(is_valid_fingerprint(desc.fingerprint)) self.assertEqual("030B22437D99B2DB2908B747B6962EAD13AB4038", desc.fingerprint)
tor-commits@lists.torproject.org