diff options
| author | Damian Johnson <atagar@torproject.org> | 2018-04-17 09:46:17 -0700 |
|---|---|---|
| committer | Damian Johnson <atagar@torproject.org> | 2018-04-17 09:47:58 -0700 |
| commit | c305b7f6fc203568f3cb4a71ca61fb33c8e7423c (patch) | |
| tree | 6325ffd3701dad7f0274c3e0019bfbb09b10f5d5 | |
| parent | 82b22046f40f49579ff37c4247db50050334998a (diff) | |
| parent | 9370b14bae9daae1ec917f2cd52e2d3ea6634cd1 (diff) | |
ExitPolicy cache fixes and related corrections
Lot of great catches from dmr on #25423. Snagging the most important ones from
his branch.
https://trac.torproject.org/projects/tor/ticket/25423
| -rw-r--r-- | stem/control.py | 20 | ||||
| -rw-r--r-- | stem/exit_policy.py | 6 |
2 files changed, 15 insertions, 11 deletions
diff --git a/stem/control.py b/stem/control.py index 3db4d35a..a91e9588 100644 --- a/stem/control.py +++ b/stem/control.py @@ -1072,8 +1072,7 @@ class Controller(BaseController): if self.is_caching_enabled(): self._set_cache(dict((k, None) for k in event.config), 'getconf') - if 'exitpolicy' in event.config.keys(): - self._set_cache({'exitpolicy': None}) + self._set_cache({'exit_policy': None}) # numerous options can change our policy self.add_event_listener(_confchanged_listener, EventType.CONF_CHANGED) @@ -1284,14 +1283,13 @@ class Controller(BaseController): An exception is only raised if we weren't provided a default response. """ - with self._msg_lock: - policy = self._get_cache('exit_policy') + policy = self._get_cache('exit_policy') - if not policy: - policy = stem.exit_policy.ExitPolicy(*self.get_info('exit-policy/full').splitlines()) - self._set_cache({'exit_policy': policy}) + if not policy: + policy = stem.exit_policy.ExitPolicy(*self.get_info('exit-policy/full').splitlines()) + self._set_cache({'exit_policy': policy}) - return policy + return policy @with_default() def get_ports(self, listener_type, default = UNDEFINED): @@ -2410,9 +2408,7 @@ class Controller(BaseController): to_cache[param] = value - if param == 'exitpolicy': - self._set_cache({'exitpolicy': None}) - elif 'hidden' in param: + if 'hidden' in param: self._set_cache({'hidden_service_conf': None}) # reset any getinfo parameters that can be changed by a SETCONF @@ -2422,6 +2418,8 @@ class Controller(BaseController): self._set_cache(to_cache, 'getconf') self._set_cache({'get_custom_options': None}) + + self._set_cache({'exit_policy': None}) # numerous options can change our policy else: log.debug('%s (failed, code: %s, message: %s)' % (query, response.code, response.message)) immutable_params = [k for k, v in params if stem.util.str_tools._to_unicode(k).lower() in IMMUTABLE_CONFIG_OPTIONS] diff --git a/stem/exit_policy.py b/stem/exit_policy.py index 3c13be7e..e921fb3c 100644 --- a/stem/exit_policy.py +++ b/stem/exit_policy.py @@ -110,6 +110,12 @@ def get_config_policy(rules, ip_address = None): * ports being optional * the 'private' keyword + .. deprecated:: 1.7.0 + + Tor's torrc parameters lack a formal spec, making it difficult for this + method to be reliable. Callers are encouraged to move to + :func:`~stem.control.Controller.get_exit_policy` instead. + :param str,list rules: comma separated rules or list to be converted :param str ip_address: this relay's IP address for the 'private' policy if it's present, this defaults to the local address |
