commit cdf2c13bbe5db5a85670760572f425dffb6ca897 Author: Damian Johnson atagar@torproject.org Date: Mon Dec 31 00:33:30 2012 -0800
Server descriptor parsing for 'ipv6-policy' lines
Adding support for IPv6 exit policies in server descriptors. Descriptors with these are already in the wild.
https://trac.torproject.org/7826 --- stem/descriptor/server_descriptor.py | 4 ++++ test/unit/descriptor/server_descriptor.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index aad5e5e..634a705 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -146,6 +146,7 @@ class ServerDescriptor(stem.descriptor.Descriptor): :var int uptime: uptime when published in seconds :var str contact: contact information :var stem.exit_policy.ExitPolicy exit_policy: ***** stated exit policy + :var stem.exit_policy.MicrodescriptorExitPolicy exit_policy_v6: ***** exit policy for IPv6 :var list family: ***** nicknames or fingerprints of declared family
:var int average_bandwidth: ***** average rate it's willing to relay in bytes/s @@ -212,6 +213,7 @@ class ServerDescriptor(stem.descriptor.Descriptor): self.uptime = None self.contact = None self.exit_policy = None + self.exit_policy_v6 = None self.family = []
self.average_bandwidth = None @@ -472,6 +474,8 @@ class ServerDescriptor(stem.descriptor.Descriptor): self.family = value.split(" ") elif keyword == "eventdns": self.eventdns = value == "1" + elif keyword == "ipv6-policy": + self.exit_policy_v6 = stem.exit_policy.MicrodescriptorExitPolicy(value) elif keyword == "or-address": or_address_entries = [value for (value, _) in values]
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py index 9b0528a..e0a86fb 100644 --- a/test/unit/descriptor/server_descriptor.py +++ b/test/unit/descriptor/server_descriptor.py @@ -6,8 +6,9 @@ import datetime import StringIO import unittest
-import stem.prereq import stem.descriptor.server_descriptor +import stem.exit_policy +import stem.prereq import test.runner
from stem.descriptor.server_descriptor import RelayDescriptor, BridgeDescriptor @@ -258,6 +259,15 @@ class TestServerDescriptor(unittest.TestCase): desc_text = get_relay_server_descriptor({"opt fingerprint": fingerprint}, content = True) self._expect_invalid_attr(desc_text, "fingerprint", fingerprint.replace(" ", ""))
+ def test_ipv6_policy(self): + """ + Checks a 'ipv6-policy' line. + """ + + expected = stem.exit_policy.MicrodescriptorExitPolicy("accept 22-23,53,80,110") + desc = get_relay_server_descriptor({"ipv6-policy": "accept 22-23,53,80,110"}) + self.assertEquals(expected, desc.exit_policy_v6) + def test_minimal_bridge_descriptor(self): """ Basic sanity check that we can parse a descriptor with minimal attributes.