[tor-commits] [stem/master] Having get_server_descriptor() warn when using microdescriptors
atagar at torproject.org
atagar at torproject.org
Sun Aug 4 23:35:25 UTC 2013
commit e78f1b74efac02ed09f963c65a652b87ea80f5f2
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Aug 4 16:25:09 2013 -0700
Having get_server_descriptor() warn when using microdescriptors
Tor presently gets microdescriptors rather than server descriptors by default.
More than one person has been confused by this, so adding a warning to our
Controller when server descriptors are unavailable...
>>> controller.get_server_descriptor('9695DFC35FFEB861329B9F1AB04C46397020CE31')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "stem/control.py", line 1207, in get_server_descriptor
raise ValueError(SERVER_DESCRIPTORS_UNSUPPORTED)
ValueError: Tor is presently not configured to retrieve server descriptors. As
of Tor version 0.2.3.25 it downloads microdescriptors instead unless you set
'UseMicrodescriptors 0' in your torrc.
This was suggested by Robert in...
https://lists.torproject.org/pipermail/tor-dev/2013-July/005196.html
---
stem/control.py | 18 ++++++++++++++++++
test/integ/control/controller.py | 3 +++
2 files changed, 21 insertions(+)
diff --git a/stem/control.py b/stem/control.py
index 0f589e1..7e7aab4 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -222,6 +222,10 @@ CACHEABLE_GETINFO_PARAMS = (
# is unavailable
GEOIP_FAILURE_THRESHOLD = 5
+SERVER_DESCRIPTORS_UNSUPPORTED = "Tor is presently not configured to retrieve \
+server descriptors. As of Tor version 0.2.3.25 it downloads microdescriptors \
+instead unless you set 'UseMicrodescriptors 0' in your torrc."
+
class BaseController(object):
"""
@@ -1199,6 +1203,9 @@ class Controller(BaseController):
return stem.descriptor.server_descriptor.RelayDescriptor(desc_content)
except Exception as exc:
if default == UNDEFINED:
+ if not self._is_server_descriptors_available():
+ raise ValueError(SERVER_DESCRIPTORS_UNSUPPORTED)
+
raise exc
else:
return default
@@ -1231,6 +1238,9 @@ class Controller(BaseController):
desc_content = self.get_info("desc/all-recent", get_bytes = True)
+ if not desc_content and not self._is_server_descriptors_available():
+ raise ValueError(SERVER_DESCRIPTORS_UNSUPPORTED)
+
for desc in stem.descriptor.server_descriptor._parse_file(io.BytesIO(desc_content)):
yield desc
except Exception as exc:
@@ -1241,6 +1251,14 @@ class Controller(BaseController):
for entry in default:
yield entry
+ def _is_server_descriptors_available(self):
+ """
+ Checks to see if tor server descriptors should be available or not.
+ """
+
+ return self.get_version() < stem.version.Requirement.MICRODESCRIPTOR_IS_DEFAULT or \
+ self.get_conf('UseMicrodescriptors', None) == '0'
+
def get_network_status(self, relay, default = UNDEFINED):
"""
Provides the router status entry for the relay with the given fingerprint
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 801d979..69112cf 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -921,6 +921,9 @@ class TestController(unittest.TestCase):
if test.runner.require_control(self):
return
+ elif runner.get_tor_version() >= Requirement.MICRODESCRIPTOR_IS_DEFAULT:
+ test.runner.skip(self, "(requires server descriptors)")
+ return
with runner.get_tor_controller() as controller:
count = 0
More information about the tor-commits
mailing list