commit 1c9727dc1117f6c94cc7b195760a31e48b57111a Author: Damian Johnson atagar@torproject.org Date: Thu Jun 30 09:34:40 2016 -0700
Support server descriptor 'tunnelled-dir-server' lines
Adding support for a small new spec addition...
https://gitweb.torproject.org/torspec.git/commit/?id=8bc30d6 --- docs/change_log.rst | 3 ++- stem/descriptor/server_descriptor.py | 9 +++++++++ test/unit/descriptor/server_descriptor.py | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 291bca2..230533a 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -66,14 +66,15 @@ The following are only available within Stem's `git repository * `Shorthand functions for stem.descriptor.remote <api/descriptor/remote.html#stem.descriptor.remote.get_instance>`_ * Added `fallback directory information <api/descriptor/remote.html#stem.descriptor.remote.FallbackDirectory>`_. * Support for ed25519 descriptor fields (:spec:`5a79d67`) + * Added server descriptor's new allow_tunneled_dir_requests attribute (:spec:`8bc30d6`) * Server descriptor validation fails with 'extra-info-digest line had an invalid value' from additions in proposal 228 (:trac:`16227`) * :class:`~stem.descriptor.server_descriptor.BridgeDescriptor` now has 'ntor_onion_key' like its unsanitized counterparts * Replaced the :class:`~stem.descriptor.microdescriptor.Microdescriptor` identifier and identifier_type attributes with an identifiers hash since it can now appear multiple times (:spec:`09ff9e2`) * Unable to read descriptors from data directories on Windows due to their CRLF newlines (:trac:`17051`) * TypeError under python3 when using 'use_mirrors = True' (:trac:`17083`) * Deprecated hidden service descriptor's *introduction_points_auth* field, which was never implemented in tor (:trac:`15190`, :spec:`9c218f9`) - * :func:`~stem.control.Controller.get_hidden_service_descriptor` errored when provided a *servers* argument (:trac:`18401`) * Deprecated :func:`~stem.descriptor.remote.DescriptorDownloader.get_microdescriptors` as it was never implemented in tor (:trac:`9271`) + * :func:`~stem.control.Controller.get_hidden_service_descriptor` errored when provided a *servers* argument (:trac:`18401`) * Fixed parsing of server descriptor's *allow-single-hop-exits* and *caches-extra-info* lines * Bracketed IPv6 addresses were mistreated as being invalid content * Better validation for non-ascii descriptor content diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index 5749832..931601a 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -95,6 +95,7 @@ SINGLE_FIELDS = ( 'hidden-service-dir', 'protocols', 'allow-single-hop-exits', + 'tunnelled-dir-server', 'onion-key-crosscert', 'ntor-onion-key', 'ntor-onion-key-crosscert', @@ -392,6 +393,7 @@ _parse_read_history_line = functools.partial(_parse_history_line, 'read-history' _parse_write_history_line = functools.partial(_parse_history_line, 'write-history', 'write_history_end', 'write_history_interval', 'write_history_values') _parse_ipv6_policy_line = _parse_simple_line('ipv6-policy', 'exit_policy_v6', func = lambda v: stem.exit_policy.MicroExitPolicy(v)) _parse_allow_single_hop_exits_line = _parse_if_present('allow-single-hop-exits', 'allow_single_hop_exits') +_parse_tunneled_dir_server_line = _parse_if_present('tunnelled-dir-server', 'allow_tunneled_dir_requests') _parse_caches_extra_info_line = _parse_if_present('caches-extra-info', 'extra_info_cache') _parse_family_line = _parse_simple_line('family', 'family', func = lambda v: set(v.split(' '))) _parse_eventdns_line = _parse_simple_line('eventdns', 'eventdns', func = lambda v: v == '1') @@ -436,6 +438,8 @@ class ServerDescriptor(Descriptor): :var list circuit_protocols: circuit protocols supported by the relay :var bool hibernating: ***** hibernating when published :var bool allow_single_hop_exits: ***** flag if single hop exiting is allowed + :var bool allow_tunneled_dir_requests: ***** flag if tunneled directory + requests are accepted :var bool extra_info_cache: ***** flag if a mirror for extra-info documents :var str extra_info_digest: upper-case hex encoded digest of our extra-info document :var bool eventdns: flag for evdns backend (**deprecated**, always unset) @@ -456,6 +460,9 @@ class ServerDescriptor(Descriptor):
***** attribute is either required when we're parsed with validation or has a default value, others are left as **None** if undefined + + .. versionchanged:: 1.5.0 + Added the allow_tunneled_dir_requests attribute. """
ATTRIBUTES = { @@ -485,6 +492,7 @@ class ServerDescriptor(Descriptor): 'circuit_protocols': (None, _parse_protocols_line), 'hibernating': (False, _parse_hibernating_line), 'allow_single_hop_exits': (False, _parse_allow_single_hop_exits_line), + 'allow_tunneled_dir_requests': (False, _parse_tunneled_dir_server_line), 'extra_info_cache': (False, _parse_caches_extra_info_line), 'extra_info_digest': (None, _parse_extrainfo_digest_line), 'hidden_service_dir': (None, _parse_hidden_service_dir_line), @@ -519,6 +527,7 @@ class ServerDescriptor(Descriptor): 'write-history': _parse_write_history_line, 'ipv6-policy': _parse_ipv6_policy_line, 'allow-single-hop-exits': _parse_allow_single_hop_exits_line, + 'tunnelled-dir-server': _parse_tunneled_dir_server_line, 'caches-extra-info': _parse_caches_extra_info_line, 'family': _parse_family_line, 'eventdns': _parse_eventdns_line, diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py index cb587d0..c9d606f 100644 --- a/test/unit/descriptor/server_descriptor.py +++ b/test/unit/descriptor/server_descriptor.py @@ -122,6 +122,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEqual(['1'], desc.circuit_protocols) self.assertEqual(False, desc.hibernating) self.assertEqual(False, desc.allow_single_hop_exits) + self.assertEqual(False, desc.allow_tunneled_dir_requests) self.assertEqual(False, desc.extra_info_cache) self.assertEqual('D225B728768D7EA4B5587C13A7A9D22EBBEE6E66', desc.extra_info_digest) self.assertEqual(['2'], desc.hidden_service_dir) @@ -179,6 +180,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEqual(None, desc.circuit_protocols) self.assertEqual(True, desc.hibernating) self.assertEqual(False, desc.allow_single_hop_exits) + self.assertEqual(False, desc.allow_tunneled_dir_requests) self.assertEqual(False, desc.extra_info_cache) self.assertEqual(None, desc.extra_info_digest) self.assertEqual(None, desc.hidden_service_dir) @@ -225,6 +227,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEqual(['1'], desc.circuit_protocols) self.assertEqual(False, desc.hibernating) self.assertEqual(False, desc.allow_single_hop_exits) + self.assertEqual(False, desc.allow_tunneled_dir_requests) self.assertEqual(False, desc.extra_info_cache) self.assertEqual('56403D838DE152421CD401B8E57DAD4483A3D56B', desc.extra_info_digest) self.assertEqual(['2'], desc.hidden_service_dir) @@ -277,6 +280,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEqual(['1'], desc.circuit_protocols) self.assertEqual(False, desc.hibernating) self.assertEqual(False, desc.allow_single_hop_exits) + self.assertEqual(False, desc.allow_tunneled_dir_requests) self.assertEqual(False, desc.extra_info_cache) self.assertEqual('44E9B679AF0B4EB09296985BAF4066AE9CA5BB93', desc.extra_info_digest) self.assertEqual(['2'], desc.hidden_service_dir) @@ -376,6 +380,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= self.assertEqual(['1'], desc.circuit_protocols) self.assertEqual(False, desc.hibernating) self.assertEqual(False, desc.allow_single_hop_exits) + self.assertEqual(False, desc.allow_tunneled_dir_requests) self.assertEqual(True, desc.extra_info_cache) self.assertEqual('BB1F13AA431421BEA29B840A2E33BB1C31C2990B', desc.extra_info_digest) self.assertEqual(None, desc.hidden_service_dir)