commit 52b1370e80f42a39322c7609da72c7c12759476a Author: Damian Johnson atagar@torproject.org Date: Wed Jan 30 15:49:07 2019 -0800
Download gzip compressed descriptors by default
Good point from starlight that we should default to downloading compressed rather than plaintext descriptors...
https://trac.torproject.org/projects/tor/ticket/29186
I purposefully chose a plaintext default because when I added Stem compression support tor had relability issues with it...
https://trac.torproject.org/projects/tor/ticket/9379
... but that hasn't been the case for years. DocTor has been downloading compressed descriptors since 2015 so it's well past time we took some confidence in changing the default.
https://gitweb.torproject.org/doctor.git/commit/?id=a8e954f --- docs/change_log.rst | 1 + stem/descriptor/remote.py | 7 +++++-- test/unit/descriptor/remote.py | 4 ---- 3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index c851f7fe..0d0ce864 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -54,6 +54,7 @@ The following are only available within Stem's `git repository * **Descriptors**
* `Bandwidth file support <api/descriptor/bandwidth_file.html>`_ (:trac:`29056`) + * Download compressed descriptors by default (:trac:`29186`) * Added :func:`stem.descriptor.remote.get_microdescriptors` * Added :class:`~stem.descriptor.networkstatus.DetachedSignature` parsing (:trac:`28495`) * Added :func:`~stem.descriptor.__init__.Descriptor.from_str` method (:trac:`28450`) diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py index 6ff1e794..d3e07b6a 100644 --- a/stem/descriptor/remote.py +++ b/stem/descriptor/remote.py @@ -334,6 +334,9 @@ class Query(object): Serge has replaced Bifroest as our bridge authority. Avoiding descriptor downloads from it instead.
+ .. versionchanged:: 1.8.0 + Defaulting to gzip compression rather than plaintext downloads. + :var str resource: resource being fetched, such as '/tor/server/all' :var str descriptor_type: type of descriptors being fetched (for options see :func:`~stem.descriptor.__init__.parse_file`), this is guessed from the @@ -377,14 +380,14 @@ class Query(object): the same as running **query.run(True)** (default is **False**) """
- def __init__(self, resource, descriptor_type = None, endpoints = None, compression = None, retries = 2, fall_back_to_authority = False, timeout = None, start = True, block = False, validate = False, document_handler = stem.descriptor.DocumentHandler.ENTRIES, **kwargs): + def __init__(self, resource, descriptor_type = None, endpoints = None, compression = (Compression.GZIP,), retries = 2, fall_back_to_authority = False, timeout = None, start = True, block = False, validate = False, document_handler = stem.descriptor.DocumentHandler.ENTRIES, **kwargs): if not resource.startswith('/'): raise ValueError("Resources should start with a '/': %s" % resource)
if resource.endswith('.z'): compression = [Compression.GZIP] resource = resource[:-2] - elif compression is None: + elif not compression: compression = [Compression.PLAINTEXT] else: if isinstance(compression, str): diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py index 858ad702..e26934b3 100644 --- a/test/unit/descriptor/remote.py +++ b/test/unit/descriptor/remote.py @@ -180,10 +180,6 @@ class TestDescriptorDownloader(unittest.TestCase): self.assertEqual(5, len(reply.reply_headers))
def test_gzip_url_override(self): - query = stem.descriptor.remote.Query(TEST_RESOURCE, start = False) - self.assertEqual([Compression.PLAINTEXT], query.compression) - self.assertEqual(TEST_RESOURCE, query.resource) - query = stem.descriptor.remote.Query(TEST_RESOURCE + '.z', compression = Compression.PLAINTEXT, start = False) self.assertEqual([Compression.GZIP], query.compression) self.assertEqual(TEST_RESOURCE, query.resource)