[tor-commits] [stem/master] Checking when EXTENDCIRCUIT is/isn't provided

atagar at torproject.org atagar at torproject.org
Thu Nov 29 06:56:30 UTC 2012


commit 6f2c1c33931b6fda738468d03ee0f835f0caca6b
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Nov 25 13:50:04 2012 -0800

    Checking when EXTENDCIRCUIT is/isn't provided
    
    The EXTENDCIRCUIT's path argument is optional unless...
    
    * the ciruit id is non-zero
    * we're prior to tor version 0.2.2.9 where it was made optional:
      https://gitweb.torproject.org/tor.git/commitdiff/ac68704f07c2b703
    
    Pointed out by robinson and integrates his suggestions on...
    https://trac.torproject.org/6666
---
 stem/control.py |   11 +++++++++--
 stem/version.py |    2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index cd990d8..1476598 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1240,7 +1240,8 @@ class Controller(BaseController):
     path isn't provided, one is automatically selected.
     
     :param int circuit: id of a circuit to be extended
-    :param list,str path: one or more relays to make a circuit through
+    :param list,str path: one or more relays to make a circuit through, this is
+      required if the circuit id is non-zero
     :param str purpose: "general" or "controller"
     
     :returns: int of the circuit id of the created or extended circuit
@@ -1248,6 +1249,12 @@ class Controller(BaseController):
     :raises: :class:`stem.InvalidRequest` if one of the parameters were invalid
     """
     
+    if path is None and circuit == 0:
+      path_opt_version = stem.version.Requirement.EXTENDCIRCUIT_PATH_OPTIONAL
+      
+      if not self.get_version().meets_requirements(path_opt_version):
+        raise stem.InvalidRequest(512, "EXTENDCIRCUIT requires the path prior to version %s" % path_opt_version)
+    
     args = [str(circuit)]
     if type(path) == str: path = [path]
     if path: args.append(",".join(path))
@@ -1262,7 +1269,7 @@ class Controller(BaseController):
         assert extended == "EXTENDED"
       except:
         raise stem.ProtocolError("EXTENDCIRCUIT response invalid:\n%s", str(response))
-    elif response.code == '552':
+    elif response.code == ('512', '552'):
       raise stem.InvalidRequest(response.code, response.message)
     else:
       raise stem.ProtocolError("EXTENDCIRCUIT returned unexpected response code: %s" % response.code)
diff --git a/stem/version.py b/stem/version.py
index 522c9f2..a7f31c3 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -36,6 +36,7 @@ easily parsed and compared, for instance...
   ===================================== ===========
   **AUTH_SAFECOOKIE**                   'SAFECOOKIE' authentication method
   **GETINFO_CONFIG_TEXT**               'GETINFO config-text' query
+  **EXTENDCIRCUIT_PATH_OPTIONAL**       'EXTENDCIRCUIT' queries can omit the path if the circuit is zero
   **LOADCONF**                          'LOADCONF' query
   **TORRC_CONTROL_SOCKET**              'ControlSocket <path>' config option
   **TORRC_DISABLE_DEBUGGER_ATTACHMENT** 'DisableDebuggerAttachment' config option
@@ -254,6 +255,7 @@ safecookie_req.greater_than(Version("0.2.3.13"))
 Requirement = stem.util.enum.Enum(
   ("AUTH_SAFECOOKIE", safecookie_req),
   ("GETINFO_CONFIG_TEXT", Version("0.2.2.7")),
+  ("EXTENDCIRCUIT_PATH_OPTIONAL", Version("0.2.2.9")),
   ("LOADCONF", Version("0.2.1.1")),
   ("TORRC_CONTROL_SOCKET", Version("0.2.0.30")),
   ("TORRC_DISABLE_DEBUGGER_ATTACHMENT", Version("0.2.3.9")),



More information about the tor-commits mailing list