[tor-commits] [stem/master] Recognizing unknown HSDesc results
atagar at torproject.org
atagar at torproject.org
Mon Jul 3 22:37:36 UTC 2017
commit 03c52f34d9a81b49c2e73044dd816367871806eb
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Jul 3 15:03:56 2017 -0700
Recognizing unknown HSDesc results
Updating our HSDesc parsing to recognize recent changes...
https://gitweb.torproject.org/torspec.git/commit/?id=1412d79159db4a424cef9b255d8f97a32e53f9c8
---
docs/change_log.rst | 1 +
setup.py | 2 +-
stem/__init__.py | 5 +++++
stem/response/events.py | 11 ++++++-----
test/unit/response/events.py | 10 ++++++++++
5 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 96690ac..286d35f 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
* :func:`~stem.process.launch_tor` raised a ValueError if invoked when outside the main thread
* Failure to authenticate could raise an improper response or hang (:trac:`22679`)
* Renamed :class:`~stem.response.events.ConnectionBandwidthEvent` type attribute to conn_type to avoid conflict with parent class (:trac:`21774`)
+ * Added the QUERY_NO_HSDIR :data:`~stem.HSDescReason` and recognizing unknown HSDir results (:spec:`1412d79`)
* Added the GUARD_WAIT :data:`~stem.CircStatus` (:spec:`6446210`)
* Unable to use cookie auth when path includes wide characters (chinese, japanese, etc)
* Tor change caused :func:`~stem.control.Controller.list_ephemeral_hidden_services` to provide empty strings if unset (:trac:`21329`)
diff --git a/setup.py b/setup.py
index 2024826..2508dfa 100644
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@
#
# * Tag the release
# |- Bump stem's version (in stem/__init__.py and docs/index.rst).
-# |- git commit -a -m "Stem release 1.0.0"
+# |- git commit -a -m "Stem release 1.0.0"
# |- git tag -u 9ABBEEC6 -m "stem release 1.0.0" 1.0.0 d0bb81a
# +- git push --tags
#
diff --git a/stem/__init__.py b/stem/__init__.py
index a033745..b6eab37 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -446,6 +446,9 @@ Library for working with the tor process.
.. versionchanged:: 1.4.0
Added the UPLOAD_REJECTED reason.
+ .. versionchanged:: 1.6.0
+ Added the QUERY_NO_HSDIR reason.
+
=================== ===========
HSDescReason Description
=================== ===========
@@ -453,6 +456,7 @@ Library for working with the tor process.
**QUERY_REJECTED** hidden service directory refused to provide the descriptor
**UPLOAD_REJECTED** descriptor was rejected by the hidden service directory
**NOT_FOUND** descriptor with the given identifier wasn't found
+ **QUERY_NO_HSDIR** no hidden service directory was found
**UNEXPECTED** failure type is unknown
=================== ===========
@@ -848,6 +852,7 @@ HSDescReason = stem.util.enum.UppercaseEnum(
'QUERY_REJECTED',
'UPLOAD_REJECTED',
'NOT_FOUND',
+ 'QUERY_NO_HSDIR',
'UNEXPECTED',
)
diff --git a/stem/response/events.py b/stem/response/events.py
index 3aa5673..5cfd9a6 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -657,11 +657,12 @@ class HSDescEvent(Event):
self.directory_fingerprint = None
self.directory_nickname = None
- try:
- self.directory_fingerprint, self.directory_nickname = \
- stem.control._parse_circ_entry(self.directory)
- except stem.ProtocolError:
- raise stem.ProtocolError("HS_DESC's directory doesn't match a ServerSpec: %s" % self)
+ if self.directory != 'UNKNOWN':
+ try:
+ self.directory_fingerprint, self.directory_nickname = \
+ stem.control._parse_circ_entry(self.directory)
+ except stem.ProtocolError:
+ raise stem.ProtocolError("HS_DESC's directory doesn't match a ServerSpec: %s" % self)
if self.replica is not None:
if not self.replica.isdigit():
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index fd2c7a9..ae7fd60 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -264,6 +264,8 @@ $67B2BDA4264D8A189D9270E28B1D30A262838243=europa1 b3oeducbhjmbqmgw2i3jtz4fekkrin
HS_DESC_NO_DESC_ID = '650 HS_DESC REQUESTED ajhb7kljbiru65qo NO_AUTH \
$67B2BDA4264D8A189D9270E28B1D30A262838243'
+HS_DESC_NOT_FOUND = '650 HS_DESC REQUESTED ajhb7kljbiru65qo NO_AUTH UNKNOWN'
+
HS_DESC_FAILED = '650 HS_DESC FAILED ajhb7kljbiru65qo NO_AUTH \
$67B2BDA4264D8A189D9270E28B1D30A262838243 \
b3oeducbhjmbqmgw2i3jtz4fekkrinwj REASON=NOT_FOUND'
@@ -926,6 +928,14 @@ class TestEvents(unittest.TestCase):
self.assertEqual(None, event.descriptor_id)
self.assertEqual(None, event.reason)
+ event = _get_event(HS_DESC_NOT_FOUND)
+
+ self.assertEqual('UNKNOWN', event.directory)
+ self.assertEqual(None, 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))
More information about the tor-commits
mailing list