[tor-commits] [stem/master] Support HS_DESC's new replica field
atagar at torproject.org
atagar at torproject.org
Sat Oct 3 18:51:15 UTC 2015
commit 980c8d43adaa3e1f4abaf6bf27badd32348ee31a
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Oct 3 11:50:55 2015 -0700
Support HS_DESC's new replica field
Support for a new event field...
https://gitweb.torproject.org/torspec.git/commit/?id=4989e73
Presently the addition doesn't have quite enough detail to go on, so asking for
clarification...
https://trac.torproject.org/projects/tor/ticket/17226
---
docs/change_log.rst | 1 +
stem/__init__.py | 5 +++++
stem/response/events.py | 12 +++++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 2933345..727b0cb 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.connection.connect` and :func:`~stem.control.Controller.from_port` now connect to both port 9051 (relay's default) and 9151 (Tor Browser's default) (:trac:`16075`)
* Added `support for NETWORK_LIVENESS events <api/response.html#stem.response.events.NetworkLivenessEvent>`_ (:spec:`44aac63`)
* Added :func:`~stem.control.Controller.is_user_traffic_allowed` to the :class:`~stem.control.Controller`
+ * Added the replica attribute to the :class:`~stem.response.events.HSDescEvent` (:spec:`4989e73`)
* IPv6 addresses could trigger errors in :func:`~stem.control.Controller.get_listeners`, :class:`~stem.response.events.ORConnEvent`, and quite a few other things (:trac:`16174`)
* Don't obscure stacktraces, most notably :class:`~stem.control.Controller` getter methods with default values
diff --git a/stem/__init__.py b/stem/__init__.py
index fc07756..ece707a 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -414,6 +414,9 @@ Library for working with the tor process.
.. versionchanged:: 1.4.0
Added the UPLOAD and UPLOADED actions.
+ .. versionchanged:: 1.5.0
+ Added the CREATED action.
+
=============== ===========
HSDescAction Description
=============== ===========
@@ -423,6 +426,7 @@ Library for working with the tor process.
**UPLOADED** descriptor was uploaded with HSPOST
**IGNORE** fetched descriptor was ignored because we already have its v0 descriptor
**FAILED** we were unable to retrieve the descriptor
+ **CREATED** unknown (:trac:`17226`)
=============== ===========
.. data:: HSDescReason (enum)
@@ -834,6 +838,7 @@ HSDescAction = stem.util.enum.UppercaseEnum(
'UPLOADED',
'IGNORE',
'FAILED',
+ 'CREATED',
)
HSDescReason = stem.util.enum.UppercaseEnum(
diff --git a/stem/response/events.py b/stem/response/events.py
index c760b98..98eaa9c 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -630,6 +630,9 @@ class HSDescEvent(Event):
.. versionchanged:: 1.3.0
Added the reason attribute.
+ .. versionchanged:: 1.5.0
+ Added the replica 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
@@ -638,11 +641,12 @@ class HSDescEvent(Event):
: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
+ :var int replica: unknown (:trac:`17226`)
"""
_VERSION_ADDED = stem.version.Requirement.EVENT_HS_DESC
_POSITIONAL_ARGS = ('action', 'address', 'authentication', 'directory', 'descriptor_id')
- _KEYWORD_ARGS = {'REASON': 'reason'}
+ _KEYWORD_ARGS = {'REASON': 'reason', 'REPLICA': 'replica'}
def _parse(self):
self.directory_fingerprint = None
@@ -654,6 +658,12 @@ class HSDescEvent(Event):
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():
+ raise stem.ProtocolError('HS_DESC event got a non-numeric replica count (%s): %s' % (self.replica, self))
+
+ self.replica = int(self.replica)
+
self._log_if_unrecognized('action', stem.HSDescAction)
self._log_if_unrecognized('authentication', stem.HSAuth)
More information about the tor-commits
mailing list