commit 365d6b611262f5a9ec85ce49e98757bfef4a0931 Author: Damian Johnson atagar@torproject.org Date: Wed May 7 08:25:04 2014 -0700
Supporting microdescriptor's new 'id' parameter
Not something our callers will care about (the parameter's just present for collision prevention), so just adding for completeness. --- docs/change_log.rst | 4 ++++ stem/descriptor/microdescriptor.py | 12 ++++++++++++ test/unit/descriptor/microdescriptor.py | 11 +++++++++++ 3 files changed, 27 insertions(+)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 482f056..f89de76 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -55,6 +55,10 @@ The following are only available within Stem's `git repository * The :func:`~stem.control.Controller.add_event_listener` method couldn't accept event types that Stem didn't already recognize. * The :class:`~stem.exit_policy.ExitPolicy` class couldn't be pickled.
+ * **Descriptors** + + * Added microdescriptor's new identity and identity_type attributes (:spec:`22cda72`) + * **Utilities**
* Added :func:`stem.util.connection.port_usage` diff --git a/stem/descriptor/microdescriptor.py b/stem/descriptor/microdescriptor.py index 4c05df7..37e49f1 100644 --- a/stem/descriptor/microdescriptor.py +++ b/stem/descriptor/microdescriptor.py @@ -164,6 +164,8 @@ class Microdescriptor(Descriptor): :var list family: ***** nicknames or fingerprints of declared family :var stem.exit_policy.MicroExitPolicy exit_policy: ***** relay's exit policy :var stem.exit_policy.MicroExitPolicy exit_policy_v6: ***** exit policy for IPv6 + :var str identifier_type: identity digest key type + :var str identifier: base64 encoded identity digest, this is only used for collision prevention (:trac:`11743`)
***** attribute is required when we're parsed with validation """ @@ -180,6 +182,8 @@ class Microdescriptor(Descriptor): self.family = [] self.exit_policy = stem.exit_policy.MicroExitPolicy("reject 1-65535") self.exit_policy_v6 = None + self.identifier_type = None + self.identifier = None
self._unrecognized_lines = []
@@ -266,6 +270,14 @@ class Microdescriptor(Descriptor): stem.descriptor.router_status_entry._parse_p_line(self, value, validate) elif keyword == "p6": self.exit_policy_v6 = stem.exit_policy.MicroExitPolicy(value) + elif keyword == "id": + value_comp = value.split() + + if len(value_comp) >= 2: + self.identifier_type = value_comp[0] + self.identifier = value_comp[1] + elif validate: + raise ValueError("'id' lines should contain both the key type and digest: %s" % line) else: self._unrecognized_lines.append(line)
diff --git a/test/unit/descriptor/microdescriptor.py b/test/unit/descriptor/microdescriptor.py index 2644ffe..cd42f78 100644 --- a/test/unit/descriptor/microdescriptor.py +++ b/test/unit/descriptor/microdescriptor.py @@ -26,6 +26,8 @@ class TestMicrodescriptor(unittest.TestCase): self.assertEquals([], desc.family) self.assertEquals(stem.exit_policy.MicroExitPolicy("reject 1-65535"), desc.exit_policy) self.assertEquals(None, desc.exit_policy_v6) + self.assertEquals(None, desc.identifier_type) + self.assertEquals(None, desc.identifier) self.assertEquals([], desc.get_unrecognized_lines())
def test_unrecognized_line(self): @@ -92,3 +94,12 @@ class TestMicrodescriptor(unittest.TestCase):
desc = get_microdescriptor({"p": "accept 80,110,143,443"}) self.assertEquals(stem.exit_policy.MicroExitPolicy("accept 80,110,143,443"), desc.exit_policy) + + def test_identifier(self): + """ + Basic check for 'id' lines. + """ + + desc = get_microdescriptor({"id": "rsa1024 Cd47okjCHD83YGzThGBDptXs9Z4"}) + self.assertEquals('rsa1024', desc.identifier_type) + self.assertEquals('Cd47okjCHD83YGzThGBDptXs9Z4', desc.identifier)
tor-commits@lists.torproject.org