[tor-commits] [stem/master] Drop v1 fallback directory parsing
atagar at torproject.org
atagar at torproject.org
Fri Jan 12 18:16:53 UTC 2018
commit 88800b93911d8041d38f4ea06081fb053b2aab09
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Jan 7 11:32:26 2018 -0800
Drop v1 fallback directory parsing
We only need parsing for the present format (since the old format isn't
available anywhere). This is only used for fetching and caching from github
after all.
---
stem/descriptor/remote.py | 62 +-----------------------------------------
test/unit/descriptor/remote.py | 41 ++--------------------------
2 files changed, 4 insertions(+), 99 deletions(-)
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index 8e4fa219..13fa2893 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -1049,67 +1049,7 @@ class FallbackDirectory(Directory):
exc = sys.exc_info()[1]
raise IOError("Unable to download tor's fallback directories from %s: %s" % (GITWEB_FALLBACK_DIR_URL, exc))
- if '/* nickname=' in fallback_dir_page:
- return FallbackDirectory._parse_v2(fallback_dir_page)
- else:
- return FallbackDirectory._parse_v1(fallback_dir_page)
-
- @staticmethod
- def _parse_v1(fallback_dir_page):
- # Example of an entry...
- #
- # "5.175.233.86:80 orport=443 id=5525D0429BFE5DC4F1B0E9DE47A4CFA169661E33"
- # " ipv6=[2a03:b0c0:0:1010::a4:b001]:9001"
- # " weight=43680",
-
- # TODO: this method can be removed once gitweb provides a v2 formatted document
-
- results, attr = {}, {}
-
- for line in fallback_dir_page.splitlines():
- if line.startswith('"'):
- addr_line_match = re.match('"([\d\.]+):(\d+) orport=(\d+) id=([\dA-F]{40}).*', line)
- ipv6_line_match = re.match('" ipv6=\[([\da-f:]+)\]:(\d+)"', line)
-
- if addr_line_match:
- address, dir_port, or_port, fingerprint = addr_line_match.groups()
-
- if not connection.is_valid_ipv4_address(address):
- raise IOError('%s has an invalid IPv4 address: %s' % (fingerprint, address))
- elif not connection.is_valid_port(or_port):
- raise IOError('%s has an invalid or_port: %s' % (fingerprint, or_port))
- elif not connection.is_valid_port(dir_port):
- raise IOError('%s has an invalid dir_port: %s' % (fingerprint, dir_port))
- elif not tor_tools.is_valid_fingerprint(fingerprint):
- raise IOError('%s has an invalid fingerprint: %s' % (fingerprint, fingerprint))
-
- attr = {
- 'address': address,
- 'or_port': int(or_port),
- 'dir_port': int(dir_port),
- 'fingerprint': fingerprint,
- }
- elif ipv6_line_match:
- address, port = ipv6_line_match.groups()
-
- if not connection.is_valid_ipv6_address(address):
- raise IOError('%s has an invalid IPv6 address: %s' % (fingerprint, address))
- elif not connection.is_valid_port(port):
- raise IOError('%s has an invalid ORPort for its IPv6 endpoint: %s' % (fingerprint, port))
-
- attr['orport_v6'] = (address, int(port))
- elif line.startswith('" weight=') and 'fingerprint' in attr:
- results[attr.get('fingerprint')] = FallbackDirectory(
- address = attr.get('address'),
- or_port = attr.get('or_port'),
- dir_port = attr.get('dir_port'),
- fingerprint = attr.get('fingerprint'),
- orport_v6 = attr.get('orport_v6'),
- )
-
- attr = {}
-
- return results
+ return FallbackDirectory._parse_v2(fallback_dir_page)
@staticmethod
def _parse_v2(fallback_dir_page):
diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py
index 69ffd8e3..414be7e8 100644
--- a/test/unit/descriptor/remote.py
+++ b/test/unit/descriptor/remote.py
@@ -58,19 +58,7 @@ iO3EUE0AEYah2W9gdz8t+i3Dtr0zgqLS841GC/TyDKCm+MKmN8d098qnwK0NGF9q
-----END SIGNATURE-----
"""
-FALLBACK_DIR_CONTENT_V1 = b"""\
-/* Trial fallbacks for 0.2.8.1-alpha with ADDRESS_AND_PORT_STABLE_DAYS = 30
- * This works around an issue where relays post a descriptor without a DirPort
- * when restarted. If these relays stay up, they will have been up for 120 days
- * by the 0.2.8 stable release -- teor */
-"5.175.233.86:80 orport=443 id=5525D0429BFE5DC4F1B0E9DE47A4CFA169661E33"
-" weight=43680",
-"62.210.124.124:9130 orport=9101 id=2EBD117806EE43C3CC885A8F1E4DC60F207E7D3E"
-" ipv6=[2001:bc8:3f23:100::1]:9101"
-" weight=43680",
-"""
-
-FALLBACK_DIR_CONTENT_V2 = b"""\
+FALLBACK_DIR_CONTENT = b"""\
"5.9.110.236:9030 orport=9001 id=0756B7CD4DFC8182BE23143FAC0642F515182CEB"
" ipv6=[2a01:4f8:162:51e2::2]:9001"
/* nickname=rueckgrat */
@@ -185,31 +173,8 @@ class TestDescriptorDownloader(unittest.TestCase):
self.assertEqual('5.39.92.199', fallback_directories['0BEA4A88D069753218EAAAD6D22EA87B9A1319D6'].address)
@patch(URL_OPEN)
- def test_fallback_directories_from_remote_v1(self, urlopen_mock):
- urlopen_mock.return_value = io.BytesIO(FALLBACK_DIR_CONTENT_V1)
- fallback_directories = stem.descriptor.remote.FallbackDirectory.from_remote()
-
- expected = {
- '5525D0429BFE5DC4F1B0E9DE47A4CFA169661E33': stem.descriptor.remote.FallbackDirectory(
- address = '5.175.233.86',
- or_port = 443,
- dir_port = 80,
- fingerprint = '5525D0429BFE5DC4F1B0E9DE47A4CFA169661E33',
- ),
- '2EBD117806EE43C3CC885A8F1E4DC60F207E7D3E': stem.descriptor.remote.FallbackDirectory(
- address = '62.210.124.124',
- or_port = 9101,
- dir_port = 9130,
- fingerprint = '2EBD117806EE43C3CC885A8F1E4DC60F207E7D3E',
- orport_v6 = ('2001:bc8:3f23:100::1', 9101),
- ),
- }
-
- self.assertEqual(expected, fallback_directories)
-
- @patch(URL_OPEN)
- def test_fallback_directories_from_remote_v2(self, urlopen_mock):
- urlopen_mock.return_value = io.BytesIO(FALLBACK_DIR_CONTENT_V2)
+ def test_fallback_directories_from_remote(self, urlopen_mock):
+ urlopen_mock.return_value = io.BytesIO(FALLBACK_DIR_CONTENT)
fallback_directories = stem.descriptor.remote.FallbackDirectory.from_remote()
expected = {
More information about the tor-commits
mailing list