[tor-commits] [arm/release] Moving connection component fetching to TorCtl

atagar at torproject.org atagar at torproject.org
Sun Jul 17 06:08:25 UTC 2011


commit 26231dd6ccddc0659acb295a68b972d2ad979bab
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Jun 16 07:58:00 2011 -0700

    Moving connection component fetching to TorCtl
    
    The TorCtl.connect method is highly inflexable...
    https://trac.torproject.org/projects/tor/ticket/3409
    
    so I've been using a custom implementation that duplicated most of the work
    that TorCtl was already doing. I've moved this higher visability version into
    TorCtl to negate the need for this hack. This relies on the following TorCtl
    change:
    https://gitweb.torproject.org/atagar/pytorctl.git/commit/565e18a6ff6189dd11d8a43ca77eed287743b479
---
 src/cli/headerPanel.py |    6 ++++--
 src/starter.py         |    4 ++--
 src/util/torTools.py   |   42 ------------------------------------------
 3 files changed, 6 insertions(+), 46 deletions(-)

diff --git a/src/cli/headerPanel.py b/src/cli/headerPanel.py
index decf975..93930b1 100644
--- a/src/cli/headerPanel.py
+++ b/src/cli/headerPanel.py
@@ -19,6 +19,8 @@ import time
 import curses
 import threading
 
+import TorCtl.TorCtl
+
 import cli.popups
 
 from util import log, panel, sysTools, torTools, uiTools
@@ -117,9 +119,9 @@ class HeaderPanel(panel.Panel, threading.Thread):
     if key in (ord('r'), ord('R')) and not self._isTorConnected:
       try:
         ctlAddr, ctlPort = self._config["startup.interface.ipAddress"], self._config["startup.interface.port"]
-        tmpConn, authType, authValue = torTools.getConnectionComponents(ctlAddr, ctlPort)
+        tmpConn, authType, authValue = TorCtl.TorCtl.connectionComp(ctlAddr, ctlPort)
         
-        if authType == torTools.AUTH_TYPE.PASSWORD:
+        if authType == TorCtl.TorCtl.AUTH_TYPE.PASSWORD:
           authValue = cli.popups.inputPrompt("Controller Password: ")
           if not authValue: raise IOError() # cancel reconnection
         
diff --git a/src/starter.py b/src/starter.py
index d2ac910..94bb30b 100644
--- a/src/starter.py
+++ b/src/starter.py
@@ -358,9 +358,9 @@ if __name__ == '__main__':
     # making this a much bigger hack).
     
     try:
-      tmpConn, authType, cookiePath = util.torTools.getConnectionComponents(controlAddr, controlPort)
+      tmpConn, authType, cookiePath = TorCtl.TorCtl.connectionComp(controlAddr, controlPort)
       
-      if authType == util.torTools.AUTH_TYPE.COOKIE:
+      if authType == TorCtl.TorCtl.AUTH_TYPE.COOKIE:
         torPid = util.torTools.getPid(controlPort)
         
         if torPid and cookiePath[0] != "/":
diff --git a/src/util/torTools.py b/src/util/torTools.py
index 14f24a0..d0d658a 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -20,9 +20,6 @@ from util import enum, log, procTools, sysTools, uiTools
 # CLOSED - control port closed
 State = enum.Enum("INIT", "CLOSED")
 
-# enums for authentication on the tor control port
-AUTH_TYPE = enum.Enum("NONE", "COOKIE", "PASSWORD")
-
 # Addresses of the default directory authorities for tor version 0.2.3.0-alpha
 # (this comes from the dirservers array in src/or/config.c).
 DIR_SERVERS = [("86.59.21.38", "80"),         # tor26
@@ -298,45 +295,6 @@ def parseVersion(versionStr):
   
   return result
 
-def getConnectionComponents(controlAddr="127.0.0.1", controlPort=9051):
-  """
-  Provides an uninitiated torctl connection for the control port. This returns
-  a tuple with the...
-  (torctl connection, authType, authValue)
-  
-  The authValue corresponds to the cookie path if using an authentication
-  cookie. Otherwise this is the empty string. This raises an IOError if unable
-  to connect.
-  
-  Arguments:
-    controlAddr - ip address belonging to the controller
-    controlPort - port belonging to the controller
-  """
-  
-  try:
-    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    s.connect((controlAddr, controlPort))
-    conn = TorCtl.Connection(s)
-    authType, authValue = conn.get_auth_type(), ""
-    
-    if authType == TorCtl.AUTH_TYPE.COOKIE:
-      authValue = conn.get_auth_cookie_path()
-    
-    # converts to our enum type
-    if authType == TorCtl.AUTH_TYPE.NONE:
-      authType = AUTH_TYPE.NONE
-    elif authType == TorCtl.AUTH_TYPE.COOKIE:
-      authType = AUTH_TYPE.COOKIE
-    elif authType == TorCtl.AUTH_TYPE.PASSWORD:
-      authType = AUTH_TYPE.PASSWORD
-    
-    return (conn, authType, authValue)
-  except socket.error, exc:
-    if "Connection refused" in exc.args:
-      raise IOError("Connection refused. Is the ControlPort enabled?")
-    else: raise IOError("Failed to establish socket: %s" % exc)
-  except Exception, exc: raise IOError(exc)
-
 def getConn():
   """
   Singleton constructor for a Controller. Be aware that this starts as being





More information about the tor-commits mailing list