commit 60eccbc9008c8f08c8a6e973980884e6a90f442f Author: Damian Johnson atagar@torproject.org Date: Mon May 11 12:46:12 2015 -0700
Version checks for new hidden service features
Now that tor bumped its version to 0.2.7.1-alpha in its codebase we can uncomment version checks for these new features. --- stem/control.py | 35 +++++++++++++---------------------- stem/response/events.py | 3 +-- test/integ/control/controller.py | 20 +++++--------------- 3 files changed, 19 insertions(+), 39 deletions(-)
diff --git a/stem/control.py b/stem/control.py index 44a0b7d..1c31dda 100644 --- a/stem/control.py +++ b/stem/control.py @@ -1741,11 +1741,6 @@ class Controller(BaseController): An exception is only raised if we weren't provided a default response. """
- # TODO: It would be great to add support for v3 router status entries. This - # is pending... - # - # https://trac.torproject.org/7953 - if relay is None: try: relay = self.get_info('fingerprint') @@ -1804,16 +1799,16 @@ 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 - # TODO: We should iterate over the descriptors as they're read from the # socket rather than reading the whole thing into memory. # # https://trac.torproject.org/8248
+ if self.get_conf('UseMicrodescriptors', '0') == '1': + desc_class = stem.descriptor.router_status_entry.RouterStatusEntryMicroV3 + else: + desc_class = stem.descriptor.router_status_entry.RouterStatusEntryV3 + desc_content = self.get_info('ns/all', get_bytes = True)
if not desc_content: @@ -1865,9 +1860,8 @@ class Controller(BaseController): if not stem.util.tor_tools.is_valid_hidden_service_address(address): raise ValueError("'%s.onion' isn't a valid hidden service address" % address)
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # if self.get_version() < stem.version.Requirement.HSFETCH: - # raise stem.UnsatisfiableRequest(message = 'HSFETCH was added in tor version %s' % stem.version.Requirement.HSFETCH) + if self.get_version() < stem.version.Requirement.HSFETCH: + raise stem.UnsatisfiableRequest(message = 'HSFETCH was added in tor version %s' % stem.version.Requirement.HSFETCH)
hs_desc_queue, hs_desc_listener = queue.Queue(), None hs_desc_content_queue, hs_desc_content_listener = queue.Queue(), None @@ -2560,9 +2554,8 @@ class Controller(BaseController): provided a default response """
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # if self.get_version() < stem.version.Requirement.ADD_ONION: - # raise stem.UnsatisfiableRequest(message = 'Ephemeral hidden services were added in tor version %s' % stem.version.Requirement.ADD_ONION) + if self.get_version() < stem.version.Requirement.ADD_ONION: + raise stem.UnsatisfiableRequest(message = 'Ephemeral hidden services were added in tor version %s' % stem.version.Requirement.ADD_ONION)
result = []
@@ -2627,9 +2620,8 @@ class Controller(BaseController): :raises: :class:`stem.ControllerError` if the call fails """
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # if self.get_version() < stem.version.Requirement.ADD_ONION: - # raise stem.UnsatisfiableRequest(message = 'Ephemeral hidden services were added in tor version %s' % stem.version.Requirement.ADD_ONION) + if self.get_version() < stem.version.Requirement.ADD_ONION: + raise stem.UnsatisfiableRequest(message = 'Ephemeral hidden services were added in tor version %s' % stem.version.Requirement.ADD_ONION)
hs_desc_queue, hs_desc_listener = queue.Queue(), None
@@ -2708,9 +2700,8 @@ class Controller(BaseController): :raises: :class:`stem.ControllerError` if the call fails """
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # if self.get_version() < stem.version.Requirement.ADD_ONION: - # raise stem.UnsatisfiableRequest(message = 'Ephemeral hidden services were added in tor version %s' % stem.version.Requirement.ADD_ONION) + if self.get_version() < stem.version.Requirement.ADD_ONION: + raise stem.UnsatisfiableRequest(message = 'Ephemeral hidden services were added in tor version %s' % stem.version.Requirement.ADD_ONION)
response = self.msg('DEL_ONION %s' % service_id) stem.response.convert('SINGLELINE', response) diff --git a/stem/response/events.py b/stem/response/events.py index e03f269..9c38649 100644 --- a/stem/response/events.py +++ b/stem/response/events.py @@ -674,8 +674,7 @@ class HSDescContentEvent(Event): :var stem.descriptor.hidden_service_descriptor.HiddenServiceDescriptor descriptor: descriptor that was retrieved """
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # _VERSION_ADDED = stem.version.Requirement.EVENT_HS_DESC_CONTENT + _VERSION_ADDED = stem.version.Requirement.EVENT_HS_DESC_CONTENT _POSITIONAL_ARGS = ('address', 'descriptor_id', 'directory')
def _parse(self): diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index 7890dcc..82da71b 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -578,10 +578,8 @@ class TestController(unittest.TestCase): except: pass
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # @require_version(Requirement.ADD_ONION) - @require_controller + @require_version(Requirement.ADD_ONION) def test_without_ephemeral_hidden_services(self): """ Exercises ephemeral hidden service methods when none are present. @@ -592,10 +590,8 @@ class TestController(unittest.TestCase): self.assertEqual([], controller.list_ephemeral_hidden_services(detached = True)) self.assertEqual(False, controller.remove_ephemeral_hidden_service('gfzprpioee3hoppz'))
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # @require_version(Requirement.ADD_ONION) - @require_controller + @require_version(Requirement.ADD_ONION) def test_with_ephemeral_hidden_services(self): """ Exercises creating ephemeral hidden services and methods when they're @@ -646,10 +642,8 @@ class TestController(unittest.TestCase): self.assertEqual(2, len(controller.list_ephemeral_hidden_services())) self.assertEqual(0, len(second_controller.list_ephemeral_hidden_services()))
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # @require_version(Requirement.ADD_ONION) - @require_controller + @require_version(Requirement.ADD_ONION) def test_with_detached_ephemeral_hidden_services(self): """ Exercises creating detached ephemeral hidden services and methods when @@ -684,11 +678,9 @@ class TestController(unittest.TestCase): self.assertEqual([response.service_id], controller.list_ephemeral_hidden_services(detached = True)) controller.remove_ephemeral_hidden_service(response.service_id)
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # @require_version(Requirement.ADD_ONION) - @require_online @require_controller + @require_version(Requirement.ADD_ONION) def test_using_ephemeral_hidden_services(self): """ Create and use a live ephemeral hidden service. @@ -1277,11 +1269,9 @@ class TestController(unittest.TestCase): if count > 10: break
- # TODO: Uncomment the below when tor makes its 0.2.7.1 release. - # @require_version(Requirement.HSFETCH) - @require_controller @require_online + @require_version(Requirement.HSFETCH) def test_get_hidden_service_descriptor(self): """ Fetches a few descriptors via the get_hidden_service_descriptor() method.