commit cb883a0cb3d62fd16bad740041ed28516cc27e79 Author: Damian Johnson atagar@torproject.org Date: Thu Jan 11 09:20:48 2018 -0800
Include fallback header metadata
Presently only included when parsing. Adding persistence next. --- stem/descriptor/remote.py | 11 +++++++---- test/unit/descriptor/remote.py | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py index 0a372dce..8f5e5cc3 100644 --- a/stem/descriptor/remote.py +++ b/stem/descriptor/remote.py @@ -948,8 +948,8 @@ class FallbackDirectory(Directory): .. versionadded:: 1.5.0
.. versionchanged:: 1.7.0 - Added the nickname and has_extrainfo attributes, which are part of the - `second version of the fallback directories + Added the nickname, has_extrainfo, and header attributes which are part of + the `second version of the fallback directories https://lists.torproject.org/pipermail/tor-dev/2017-December/012721.html`_.
:var str nickname: relay nickname @@ -957,14 +957,16 @@ class FallbackDirectory(Directory): extrainfo descriptors, **False** otherwise. :var str orport_v6: **(address, port)** tuple for the directory's IPv6 ORPort, or **None** if it doesn't have one + :var dict header: metadata about the fallback directory file this originated from """
- def __init__(self, address = None, or_port = None, dir_port = None, fingerprint = None, nickname = None, has_extrainfo = False, orport_v6 = None): + def __init__(self, address = None, or_port = None, dir_port = None, fingerprint = None, nickname = None, has_extrainfo = False, orport_v6 = None, header = None): super(FallbackDirectory, self).__init__(address, or_port, dir_port, fingerprint)
self.nickname = nickname self.has_extrainfo = has_extrainfo self.orport_v6 = orport_v6 + self.header = header if header else {}
@staticmethod def from_cache(): @@ -1086,6 +1088,7 @@ class FallbackDirectory(Directory): if section: try: fallback = FallbackDirectory.from_str('\n'.join(section)) + fallback.header = header results[fallback.fingerprint] = fallback except ValueError as exc: raise IOError(str(exc)) @@ -1177,7 +1180,7 @@ class FallbackDirectory(Directory): return section_lines
def __hash__(self): - return _hash_attr(self, 'address', 'or_port', 'dir_port', 'fingerprint', 'nickname', 'has_extrainfo', 'orport_v6', parent = Directory) + return _hash_attr(self, 'address', 'or_port', 'dir_port', 'fingerprint', 'nickname', 'has_extrainfo', 'orport_v6', 'header', parent = Directory)
def __eq__(self, other): return hash(self) == hash(other) if isinstance(other, FallbackDirectory) else False diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py index 7789ed21..cc0d51b1 100644 --- a/test/unit/descriptor/remote.py +++ b/test/unit/descriptor/remote.py @@ -209,6 +209,7 @@ class TestDescriptorDownloader(unittest.TestCase): 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() + header = {'type': 'fallback', 'version': '2.0.0', 'timestamp': '20170526090242'}
expected = { '0756B7CD4DFC8182BE23143FAC0642F515182CEB': stem.descriptor.remote.FallbackDirectory( @@ -219,6 +220,7 @@ class TestDescriptorDownloader(unittest.TestCase): nickname = 'rueckgrat', has_extrainfo = True, orport_v6 = ('2a01:4f8:162:51e2::2', 9001), + header = header, ), '01A9258A46E97FF8B2CAC7910577862C14F2C524': stem.descriptor.remote.FallbackDirectory( address = '193.171.202.146', @@ -228,6 +230,7 @@ class TestDescriptorDownloader(unittest.TestCase): nickname = None, has_extrainfo = False, orport_v6 = None, + header = header, ), }