summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2018-04-18 10:17:08 -0700
committerDamian Johnson <atagar@torproject.org>2018-04-18 10:23:16 -0700
commitf61e91314c81949bb6fb199f14afa0f56d4b4557 (patch)
tree4efe2e48eab38d600276f8a2af0d8b11e94baf4a
parentcc95059da5a8e34d10c16f5a226df21ffb5b43c9 (diff)
Fallback to GETCONF for getting exit policies
As pointed out by dmr on #25423 when tor is unable to determine our address 'GETINFO exit-policy/full' fails. I was able to easily repro this by running our integ tests when disconnected... ====================================================================== ERROR: test_get_exit_policy ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped return func(self, *args, **kwargs) File "/home/atagar/Desktop/stem/test/integ/control/controller.py", line 278, in test_get_exit_policy self.assertEqual(ExitPolicy('reject *:*'), controller.get_exit_policy()) File "/home/atagar/Desktop/stem/stem/control.py", line 481, in wrapped return func(self, *args, **kwargs) File "/home/atagar/Desktop/stem/stem/control.py", line 1289, in get_exit_policy policy = stem.exit_policy.ExitPolicy(*self.get_info('exit-policy/full').splitlines()) File "/home/atagar/Desktop/stem/stem/control.py", line 481, in wrapped return func(self, *args, **kwargs) File "/home/atagar/Desktop/stem/stem/control.py", line 1186, in get_info stem.response.convert('GETINFO', response) File "/home/atagar/Desktop/stem/stem/response/__init__.py", line 124, in convert message._parse_message(**kwargs) File "/home/atagar/Desktop/stem/stem/response/getinfo.py", line 40, in _parse_message raise stem.ProtocolError("GETINFO response didn't have an OK status:\n%s" % self) ProtocolError: GETINFO response didn't have an OK status: router_get_my_routerinfo returned NULL I'll shoot tor a ticket in a bit, but in the meantime when this happens we'll now fall back to our prior method of getting the policy. One small fix for the legacy method is that we now account for 'ExitRelay 0' in our the torrc (otherwise our tests wouldn't pass).
-rw-r--r--stem/control.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/stem/control.py b/stem/control.py
index a91e9588..9229f07c 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1286,7 +1286,33 @@ class Controller(BaseController):
policy = self._get_cache('exit_policy')
if not policy:
- policy = stem.exit_policy.ExitPolicy(*self.get_info('exit-policy/full').splitlines())
+ try:
+ policy = stem.exit_policy.ExitPolicy(*self.get_info('exit-policy/full').splitlines())
+ except stem.ProtocolError:
+ # When tor is unable to determine our address 'GETINFO
+ # exit-policy/full' fails with...
+ #
+ # ProtocolError: GETINFO response didn't have an OK status:
+ # router_get_my_routerinfo returned NULL
+ #
+ # Failing back to the legacy method we used for getting our exit
+ # policy.
+
+ rules = []
+
+ if self.get_conf('ExitRelay') == '0':
+ rules.append('reject *:*')
+
+ if self.get_conf('ExitPolicyRejectPrivate') == '1':
+ rules.append('reject private:*')
+
+ for policy_line in self.get_conf('ExitPolicy', multiple = True):
+ rules += policy_line.split(',')
+
+ rules += self.get_info('exit-policy/default').split(',')
+
+ policy = stem.exit_policy.get_config_policy(rules, self.get_info('address', None))
+
self._set_cache({'exit_policy': policy})
return policy