commit 68f5a6b2907cd42414f363e6afa89381cbb0e8a5 Author: Damian Johnson atagar@torproject.org Date: Sat Sep 23 19:02:50 2017 -0700
If exiting is disallowed then don't check rules
There's no point in iterating over our rules in can_exit_to() when we already know that no exiting is allowed. The is_exiting_allowed() is only ever invoked once due to caching, whereas can_exit_to() is invoked for every new input. --- stem/exit_policy.py | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/stem/exit_policy.py b/stem/exit_policy.py index 25ed16ec..fd8c15c2 100644 --- a/stem/exit_policy.py +++ b/stem/exit_policy.py @@ -282,6 +282,9 @@ class ExitPolicy(object): :returns: **True** if exiting to this destination is allowed, **False** otherwise """
+ if not self.is_exiting_allowed(): + return False + for rule in self._get_rules(): if rule.is_match(address, port, strict): return rule.is_accept