[tor-commits] [stem/master] Having use_directory_mirrors() return the consensus
atagar at torproject.org
atagar at torproject.org
Fri Jul 26 15:17:28 UTC 2013
commit d7b68d01aabc6fdcd544a479cfa2cac377eaddeb
Author: Damian Johnson <atagar at torproject.org>
Date: Fri Jul 26 08:13:58 2013 -0700
Having use_directory_mirrors() return the consensus
Originally I was planning an on-disk cache so calling get_consensus() after
use_directory_mirrors() would result in an on-disk read. However, that has been
put on hold for now so having use_directory_mirrors() return the consensus it
fetches in order to get the mirrors.
We unfortunately already need to read the full consensus into memory before
processing it due to how urllib2 works, so this shouldn't cause a memory usage
hit. We might someday want to change this though if we get a constant time
download/parsing scheme.
---
stem/descriptor/remote.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index da1df63..8b6497f 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -391,7 +391,7 @@ class DescriptorDownloader(object):
try:
start_time = time.time()
self.use_directory_mirrors()
- log.debug("Retrieve directory mirrors (took %0.2fs)" % (time.time() - start_time))
+ log.debug("Retrieved directory mirrors (took %0.2fs)" % (time.time() - start_time))
except Exception as exc:
log.debug("Unable to retrieve directory mirrors: %s" % exc)
@@ -400,12 +400,17 @@ class DescriptorDownloader(object):
Downloads the present consensus and configures ourselves to use directory
mirrors, in addition to authorities.
+ :returns: :class:`~stem.descriptor.networkstatus.NetworkStatusDocumentV3`
+ from which we got the directory mirrors
+
:raises: **Exception** if unable to determine the directory mirrors
"""
new_endpoints = set(DIRECTORY_AUTHORITIES.values())
- for desc in self.get_consensus().run():
+ consensus = list(self.get_consensus(document_handler = stem.descriptor.DocumentHandler.DOCUMENT).run())[0]
+
+ for desc in consensus.routers:
if Flag.V2DIR in desc.flags:
new_endpoints.add((desc.address, desc.dir_port))
@@ -413,6 +418,8 @@ class DescriptorDownloader(object):
self._endpoints = list(new_endpoints)
+ return consensus
+
def get_server_descriptors(self, fingerprints = None, **query_args):
"""
Provides the server descriptors with the given fingerprints. If no
More information about the tor-commits
mailing list