commit d70fa9cdd85924ef2e24ceebc2ce348f50634d80 Author: Damian Johnson atagar@torproject.org Date: Sun Mar 23 14:24:09 2014 -0700
Controller sometimes provides microdescriptor router status entries
As pointed out by mr-4 on...
https://trac.torproject.org/7646
Tor's 'GETINFO ns/*' methods provide standard v3 router status entries when Tor isn't using microdescriptors, and microdescriptor flavored entries when it is. Changing our Controller's get_netword_status() and get_network_statuses() methods to provide the right return type.
This is a clunkier for our users but there's not much that Stem can do about that. Oh well. :( --- docs/change_log.rst | 1 + docs/faq.rst | 2 +- stem/control.py | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 6b90ca9..a02750c 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -49,6 +49,7 @@ The following are only available within Stem's `git repository * Added `support for CELL_STATS events <api/response.html#stem.response.events.CellStatsEvent>`_ (:spec:`6f2919a`) * Added `support for TB_EMPTY events <api/response.html#stem.response.events.TokenBucketEmptyEvent>`_ (:spec:`6f2919a`) * Added `support for HS_DESC events <api/response.html#stem.response.events.HSDescEvent>`_ (:spec:`a67ac4d`, :trac:`10807`) + * Changed :func:`~stem.control.Controller.get_network_status` and :func:`~stem.control.Controller.get_network_statuses` to provide :class:`~stem.descriptor.router_status_entry.RouterStatusEntryMicroV3` if Tor is using microdescriptors (:trac:`7646`)
* **Utilities**
diff --git a/docs/faq.rst b/docs/faq.rst index 4e79251..cb70ba5 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -184,7 +184,7 @@ To get the credential for your AUTHENTICATE command we will use **hexdump**... **I'm using password authentication** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Tor's other method of authentication is a credential you know. To use it you ask Tor to hash your password, then use that in your torrc... +Tor's other method of authentication is a credential you know. To use it ask Tor to hash your password, then use that in your torrc...
::
diff --git a/stem/control.py b/stem/control.py index 0d91587..8ea9fe7 100644 --- a/stem/control.py +++ b/stem/control.py @@ -1413,10 +1413,21 @@ class Controller(BaseController): or nickname. If the relay identifier could be either a fingerprint *or* nickname then it's queried as a fingerprint.
+ This provides + :class:`~stem.descriptor.router_status_entry.RouterStatusEntryMicroV3` + instances if tor is using microdescriptors... + + :: + + controller.get_conf('UseMicrodescriptors', '0') == '1' + + ... and :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3` + otherwise. + :param str relay: fingerprint or nickname of the relay to be queried :param object default: response if the query fails
- :returns: :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3` + :returns: :class:`~stem.descriptor.router_status_entry.RouterStatusEntry` for the given relay
:raises: @@ -1441,7 +1452,11 @@ class Controller(BaseController): raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
desc_content = self.get_info(query, get_bytes = True) - return stem.descriptor.router_status_entry.RouterStatusEntryV3(desc_content) + + if self.get_conf('UseMicrodescriptors', '0') == '1': + return stem.descriptor.router_status_entry.RouterStatusEntryMicroV3(desc_content) + else: + return stem.descriptor.router_status_entry.RouterStatusEntryV3(desc_content) except Exception as exc: if default == UNDEFINED: raise exc @@ -1453,6 +1468,17 @@ class Controller(BaseController): Provides an iterator for all of the router status entries that tor presently knows about.
+ This provides + :class:`~stem.descriptor.router_status_entry.RouterStatusEntryMicroV3` + instances if tor is using microdescriptors... + + :: + + controller.get_conf('UseMicrodescriptors', '0') == '1' + + ... and :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3` + otherwise. + :param list default: items to provide if the query fails
:returns: iterates over @@ -1463,6 +1489,11 @@ class Controller(BaseController): default was provided """
+ if self.get_conf('UseMicrodescriptors', '0') == '1': + desc_class = stem.descriptor.router_status_entry.RouterStatusEntryMicroV3 + else: + desc_class = stem.descriptor.router_status_entry.RouterStatusEntryV3 + try: # TODO: We should iterate over the descriptors as they're read from the # socket rather than reading the whole thing into memory. @@ -1474,7 +1505,7 @@ class Controller(BaseController): desc_iterator = stem.descriptor.router_status_entry._parse_file( io.BytesIO(desc_content), True, - entry_class = stem.descriptor.router_status_entry.RouterStatusEntryV3, + entry_class = desc_class, )
for desc in desc_iterator: