commit 52150096b772e3e8c946c1eb1958bf0010d9ac99 Author: Damian Johnson atagar@torproject.org Date: Mon Nov 17 11:47:22 2014 -0800
Supporting reason attribute in HS_DESC events
New attribute being added to HS_DESC events...
https://gitweb.torproject.org/torspec.git/commitdiff/7908c8d --- docs/change_log.rst | 1 + stem/__init__.py | 21 +++++++++++++++++++++ stem/response/events.py | 5 +++++ test/unit/response/events.py | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 172b206..1724497 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -48,6 +48,7 @@ The following are only available within Stem's `git repository * Added :func:`~stem.control.BaseController.connection_time` to the :class:`~stem.control.BaseController` * Changed :func:`~stem.control.Controller.get_microdescriptor`, :func:`~stem.control.Controller.get_server_descriptor`, and :func:`~stem.control.Controller.get_network_status` to get our own descriptor if no fingerprint or nickname is provided. * Added :class:`~stem.exit_policy.ExitPolicy` methods for more easily handling 'private' policies (the `default prefix https://www.torproject.org/docs/tor-manual.html.en#ExitPolicyRejectPrivate`_) and the defaultly appended suffix. This includes :func:`~stem.exit_policy.ExitPolicy.has_private`, :func:`~stem.exit_policy.ExitPolicy.strip_private`, :func:`~stem.exit_policy.ExitPolicy.has_default`, and :func:`~stem.exit_policy.ExitPolicy.strip_default` :class:`~stem.exit_policy.ExitPolicy` methods in addition to :func:`~stem.exit_policy.ExitPolicyRule.is_private` and :func:`~stem.exit_policy.ExitPolicyRule.is_default` for the :class:`~stem.exit_policy.ExitPolicyRule`. (:trac:`10107`) + * Added the reason attribute to the :class:`~stem.response.events.HSDescEvent` (:spec:`7908c8d`) * :func:`~stem.process.launch_tor_with_config` could cause a "Too many open files" OSError if called too many times (:trac:`13141`)
* **Descriptors** diff --git a/stem/__init__.py b/stem/__init__.py index f020342..eb84be7 100644 --- a/stem/__init__.py +++ b/stem/__init__.py @@ -409,6 +409,19 @@ Library for working with the tor process. **FAILED** we were unable to retrieve the descriptor =============== ===========
+.. data:: HSDescReason (enum) + + Reason for the hidden service descriptor to fail to be fetched. + + =================== =========== + HSDescReason Description + =================== =========== + **BAD_DESC** descriptor was unparseable + **QUERY_REJECTED** hidden service directory refused to provide the descriptor + **NOT_FOUND** descriptor with the given identifier wasn't found + **UNEXPECTED** failure type is unknown + =================== =========== + .. data:: HSAuth (enum)
Type of authentication being used for a HS_DESC event. @@ -460,6 +473,7 @@ __all__ = [ 'HiddenServiceState', 'HSAuth', 'HSDescAction', + 'HSDescReason', 'RelayEndReason', 'StreamStatus', 'StreamClosureReason', @@ -776,6 +790,13 @@ HSDescAction = stem.util.enum.UppercaseEnum( 'FAILED', )
+HSDescReason = stem.util.enum.UppercaseEnum( + 'BAD_DESC', + 'QUERY_REJECTED', + 'NOT_FOUND', + 'UNEXPECTED', +) + HSAuth = stem.util.enum.UppercaseEnum( 'NO_AUTH', 'BASIC_AUTH', diff --git a/stem/response/events.py b/stem/response/events.py index b640d2d..0df830b 100644 --- a/stem/response/events.py +++ b/stem/response/events.py @@ -615,6 +615,9 @@ class HSDescEvent(Event):
.. versionadded:: 1.2.0
+ .. versionchanged:: 1.3.0 + Added the reason attribute. + :var stem.HSDescAction action: what is happening with the descriptor :var str address: hidden service address :var stem.HSAuth authentication: service's authentication method @@ -622,10 +625,12 @@ class HSDescEvent(Event): :var str directory_fingerprint: hidden service directory's finterprint :var str directory_nickname: hidden service directory's nickname if it was provided :var str descriptor_id: descriptor identifier + :var stem.HSDescReason reason: reason the descriptor failed to be fetched """
_VERSION_ADDED = stem.version.Requirement.EVENT_HS_DESC _POSITIONAL_ARGS = ('action', 'address', 'authentication', 'directory', 'descriptor_id') + _KEYWORD_ARGS = {'REASON': 'reason'}
def _parse(self): self.directory_fingerprint = None diff --git a/test/unit/response/events.py b/test/unit/response/events.py index a44d536..054a9ff 100644 --- a/test/unit/response/events.py +++ b/test/unit/response/events.py @@ -198,6 +198,10 @@ $67B2BDA4264D8A189D9270E28B1D30A262838243=europa1 b3oeducbhjmbqmgw2i3jtz4fekkrin HS_DESC_NO_DESC_ID = '650 HS_DESC REQUESTED ajhb7kljbiru65qo NO_AUTH \ $67B2BDA4264D8A189D9270E28B1D30A262838243'
+HS_DESC_FAILED = '650 HS_DESC FAILED ajhb7kljbiru65qo NO_AUTH \ +$67B2BDA4264D8A189D9270E28B1D30A262838243 \ +b3oeducbhjmbqmgw2i3jtz4fekkrinwj REASON=NOT_FOUND' + # NEWCONSENSUS event from v0.2.1.30.
NEWCONSENSUS_EVENT = """650+NEWCONSENSUS @@ -748,6 +752,7 @@ class TestEvents(unittest.TestCase): self.assertEqual('67B2BDA4264D8A189D9270E28B1D30A262838243', event.directory_fingerprint) self.assertEqual('europa1', event.directory_nickname) self.assertEqual('b3oeducbhjmbqmgw2i3jtz4fekkrinwj', event.descriptor_id) + self.assertEqual(None, event.reason)
event = _get_event(HS_DESC_NO_DESC_ID)
@@ -755,6 +760,20 @@ class TestEvents(unittest.TestCase): self.assertEqual('67B2BDA4264D8A189D9270E28B1D30A262838243', event.directory_fingerprint) self.assertEqual(None, event.directory_nickname) self.assertEqual(None, event.descriptor_id) + self.assertEqual(None, event.reason) + + event = _get_event(HS_DESC_FAILED) + + self.assertTrue(isinstance(event, stem.response.events.HSDescEvent)) + self.assertEqual(HS_DESC_FAILED.lstrip('650 '), str(event)) + self.assertEqual(HSDescAction.FAILED, event.action) + self.assertEqual('ajhb7kljbiru65qo', event.address) + self.assertEqual(HSAuth.NO_AUTH, event.authentication) + self.assertEqual('$67B2BDA4264D8A189D9270E28B1D30A262838243', event.directory) + self.assertEqual('67B2BDA4264D8A189D9270E28B1D30A262838243', event.directory_fingerprint) + self.assertEqual(None, event.directory_nickname) + self.assertEqual('b3oeducbhjmbqmgw2i3jtz4fekkrinwj', event.descriptor_id) + self.assertEqual(HSDescReason.NOT_FOUND, event.reason)
def test_newdesc_event(self): event = _get_event(NEWDESC_SINGLE)
tor-commits@lists.torproject.org