[tor-commits] [stem/master] Use 'GETINFO exit-policy/full' to get exit policies

atagar at torproject.org atagar at torproject.org
Sat Apr 14 20:29:48 UTC 2018


commit f7a34305929019cefca21a20d6a2334cf85eae4f
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Apr 14 13:21:31 2018 -0700

    Use 'GETINFO exit-policy/full' to get exit policies
    
    Our get_exit_policy() method predates tor's controller command to get it (we
    were in 2013, whereas tor added the 'exit-policy/full' GETINFO option in 2014).
    It has now been long enough that we can expect relays to have this.
    
    This is much simpler and more reliable than attempting to make sense of the
    user's ExitPolicy torrc entries...
    
      https://trac.torproject.org/projects/tor/ticket/25739
    
    I'm a tad uncertain if tor's parsing is correct, but GETINFO should be the
    authoritative source for how tor interprets it...
    
      >>> GETCONF ExitPolicy
      250 ExitPolicy=reject6 2a04:1447:4:3::74/32,accept 123.45.67.89:123,reject *:*
    
      >>> GETINFO exit-policy/full
      250+exit-policy/full=
      reject6 *:*
      accept 123.45.67.89:123
      reject *:*
      .
      250 OK
---
 docs/change_log.rst |  1 +
 stem/control.py     | 28 +++++++++++-----------------
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index e4053d91..b6121982 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -49,6 +49,7 @@ The following are only available within Stem's `git repository
   * Documented v3 hidden service support (:trac:`25124`, :spec:`6bd0a69`)
   * Added support for limiting the maximum number of streams to :func:`~stem.control.Controller.create_ephemeral_hidden_service` (:spec:`2fcb1c2`)
   * Stacktrace if :func:`stem.connection.connect` had a string port argument
+  * More reliable ExitPolicy resolution (:trac:`25739`)
   * Replaced socket's :func:`~stem.socket.ControlPort.get_address`, :func:`~stem.socket.ControlPort.get_port`, and :func:`~stem.socket.ControlSocketFile.get_socket_path` with attributes
   * Removed 'raw' argument from :func:`~stem.socket.ControlSocket.send`
 
diff --git a/stem/control.py b/stem/control.py
index 8d25064b..3db4d35a 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1265,8 +1265,12 @@ class Controller(BaseController):
     """
     get_exit_policy(default = UNDEFINED)
 
-    Effective ExitPolicy for our relay. This accounts for
-    ExitPolicyRejectPrivate and default policies.
+    Effective ExitPolicy for our relay.
+
+    .. versionchanged:: 1.7.0
+       Policies retrieved through 'GETINFO exit-policy/full' rather than
+       parsing the user's torrc entries. This should be more reliable for
+       some edge cases. (:trac:`25739`)
 
     :param object default: response if the query fails
 
@@ -1281,23 +1285,13 @@ class Controller(BaseController):
     """
 
     with self._msg_lock:
-      config_policy = self._get_cache('exit_policy')
-
-      if not config_policy:
-        policy = []
-
-        if self.get_conf('ExitPolicyRejectPrivate') == '1':
-          policy.append('reject private:*')
-
-        for policy_line in self.get_conf('ExitPolicy', multiple = True):
-          policy += policy_line.split(',')
-
-        policy += self.get_info('exit-policy/default').split(',')
+      policy = self._get_cache('exit_policy')
 
-        config_policy = stem.exit_policy.get_config_policy(policy, self.get_info('address', None))
-        self._set_cache({'exit_policy': config_policy})
+      if not policy:
+        policy = stem.exit_policy.ExitPolicy(*self.get_info('exit-policy/full').splitlines())
+        self._set_cache({'exit_policy': policy})
 
-      return config_policy
+      return policy
 
   @with_default()
   def get_ports(self, listener_type, default = UNDEFINED):



More information about the tor-commits mailing list