commit b2cc6f27ba424e9ee563bc87635c2c43540ba770 Author: Damian Johnson atagar@torproject.org Date: Wed Mar 25 13:48:57 2015 -0700
Read until 'router-digest' instead of '@type'
Karsten makes the great point that while sanitized bridge descriptors might not have a 'router-signature' line they instead have a 'router-digest'. Better to use this to determine the dividing point between descriptors rather than the @type annotation (which honestly was a bit hacky).
During this discovered that the example we use in our unit tests for a bridge descriptor doesn't seem to be real. I wasn't able to find it in Collector, so swapping us over to one that does. --- stem/descriptor/extrainfo_descriptor.py | 5 +--- stem/descriptor/server_descriptor.py | 5 +--- test/unit/descriptor/data/bridge_descriptor | 21 +++++++--------- test/unit/descriptor/server_descriptor.py | 36 +++++++++++---------------- 4 files changed, 26 insertions(+), 41 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 716340e..607bbbe 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -186,10 +186,7 @@ def _parse_file(descriptor_file, is_bridge = False, validate = False, **kwargs): block_end_prefix = PGP_BLOCK_END.split(' ', 1)[0] extrainfo_content += _read_until_keywords(block_end_prefix, descriptor_file, True) else: - # bridge descriptors lack a well defined ending, so checking for a @type - # annotation - - extrainfo_content = _read_until_keywords('@type', descriptor_file, ignore_first = True) + extrainfo_content = _read_until_keywords('router-digest', descriptor_file, True)
if extrainfo_content: if extrainfo_content[0].startswith(b'@type'): diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index 80245ff..9870cf2 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -153,10 +153,7 @@ def _parse_file(descriptor_file, is_bridge = False, validate = False, **kwargs): block_end_prefix = PGP_BLOCK_END.split(' ', 1)[0] descriptor_content += _read_until_keywords(block_end_prefix, descriptor_file, True) else: - # bridge descriptors lack a well defined ending, so checking for a @type - # annotation - - descriptor_content = _read_until_keywords('@type', descriptor_file, ignore_first = True) + descriptor_content = _read_until_keywords('router-digest', descriptor_file, True)
if descriptor_content: if descriptor_content[0].startswith(b'@type'): diff --git a/test/unit/descriptor/data/bridge_descriptor b/test/unit/descriptor/data/bridge_descriptor index b7dbd92..2f532b0 100644 --- a/test/unit/descriptor/data/bridge_descriptor +++ b/test/unit/descriptor/data/bridge_descriptor @@ -1,15 +1,12 @@ @type bridge-server-descriptor 1.0 -router Unnamed 10.45.227.253 9001 0 0 -router-digest 006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4 -or-address [fd9f:2e19:3bcf::02:9970]:9001 -platform Tor 0.2.3.12-alpha (git-800942b4176ca31c) on Linux x86_64 +router Unnamed 10.18.111.71 9001 0 0 +platform Tor 0.2.0.26-rc (r14597) on Linux i686 opt protocols Link 1 2 Circuit 1 -published 2012-03-22 17:34:38 -opt fingerprint AE54 E28E D069 CDF4 5F30 09F9 63EE 3B3D 6FA2 6A2E -uptime 186 -bandwidth 409600 819200 5120 -opt extra-info-digest 134F81F7A0D270B85FCD481DD10CEA34BA7B15C9 -family $CE396C72A3D0880F74C064FEA79D68C15BD380B9 $AB8B00C00B1347BA80A88E548FAC9EDF701D7D0E $8C8A470D7C23151665A7B84E75E89FCC205A3304 -opt hidden-service-dir -contact somebody +published 2008-05-20 19:45:00 +opt fingerprint 4ED5 7358 2B16 ACDA F6E4 2AA0 44A0 38F8 3A7F 6333 +uptime 204 +bandwidth 3220480 6441984 59408 +opt extra-info-digest BB1F13AA431421BEA29B840A2E33BB1C31C2990B +opt caches-extra-info reject *:* +router-digest 00F1CD29AD308A59A9AB5A88B49ECB46E0F215FD diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py index fd0c032..a0c328b 100644 --- a/test/unit/descriptor/server_descriptor.py +++ b/test/unit/descriptor/server_descriptor.py @@ -285,38 +285,32 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
descriptor_file = open(get_resource('bridge_descriptor'), 'rb')
- expected_family = set([ - '$CE396C72A3D0880F74C064FEA79D68C15BD380B9', - '$AB8B00C00B1347BA80A88E548FAC9EDF701D7D0E', - '$8C8A470D7C23151665A7B84E75E89FCC205A3304', - ]) - desc = next(stem.descriptor.parse_file(descriptor_file, 'bridge-server-descriptor 1.0', validate = True)) self.assertEqual('Unnamed', desc.nickname) - self.assertEqual('AE54E28ED069CDF45F3009F963EE3B3D6FA26A2E', desc.fingerprint) - self.assertEqual('10.45.227.253', desc.address) + self.assertEqual('4ED573582B16ACDAF6E42AA044A038F83A7F6333', desc.fingerprint) + self.assertEqual('10.18.111.71', desc.address) self.assertEqual(9001, desc.or_port) self.assertEqual(None, desc.socks_port) self.assertEqual(None, desc.dir_port) - self.assertEqual(b'Tor 0.2.3.12-alpha (git-800942b4176ca31c) on Linux x86_64', desc.platform) - self.assertEqual(stem.version.Version('0.2.3.12-alpha'), desc.tor_version) - self.assertEqual('Linux x86_64', desc.operating_system) - self.assertEqual(186, desc.uptime) - self.assertEqual(datetime.datetime(2012, 3, 22, 17, 34, 38), desc.published) - self.assertEqual(b'somebody', desc.contact) + self.assertEqual(b'Tor 0.2.0.26-rc (r14597) on Linux i686', desc.platform) + self.assertEqual(stem.version.Version('0.2.0.26-rc'), desc.tor_version) + self.assertEqual('Linux i686', desc.operating_system) + self.assertEqual(204, desc.uptime) + self.assertEqual(datetime.datetime(2008, 5, 20, 19, 45, 0), desc.published) + self.assertEqual(None, desc.contact) self.assertEqual(['1', '2'], desc.link_protocols) self.assertEqual(['1'], desc.circuit_protocols) self.assertEqual(False, desc.hibernating) self.assertEqual(False, desc.allow_single_hop_exits) self.assertEqual(False, desc.extra_info_cache) - self.assertEqual('134F81F7A0D270B85FCD481DD10CEA34BA7B15C9', desc.extra_info_digest) - self.assertEqual(['2'], desc.hidden_service_dir) - self.assertEqual(expected_family, desc.family) - self.assertEqual(409600, desc.average_bandwidth) - self.assertEqual(819200, desc.burst_bandwidth) - self.assertEqual(5120, desc.observed_bandwidth) + self.assertEqual('BB1F13AA431421BEA29B840A2E33BB1C31C2990B', desc.extra_info_digest) + self.assertEqual(None, desc.hidden_service_dir) + self.assertEqual(set(), desc.family) + self.assertEqual(3220480, desc.average_bandwidth) + self.assertEqual(6441984, desc.burst_bandwidth) + self.assertEqual(59408, desc.observed_bandwidth) self.assertEqual(stem.exit_policy.ExitPolicy('reject *:*'), desc.exit_policy) - self.assertEqual('006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4', desc.digest()) + self.assertEqual('00F1CD29AD308A59A9AB5A88B49ECB46E0F215FD', desc.digest()) self.assertEqual([], desc.get_unrecognized_lines())
def test_minimal_relay_descriptor(self):