Skip to content
Snippets Groups Projects
Commit f61e9131 authored by Damian Johnson's avatar Damian Johnson
Browse files

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).
parent cc95059d
No related branches found
No related tags found
No related merge requests found
......@@ -1286,7 +1286,33 @@ class Controller(BaseController):
policy = self._get_cache('exit_policy')
if not policy:
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment