[tor-commits] [arm/master] Dropping getTorCtl()

atagar at torproject.org atagar at torproject.org
Mon Dec 17 04:25:17 UTC 2012


commit 7591d4ad2350cd42de1e452c0951e8072241d1c9
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Dec 16 14:12:25 2012 -0800

    Dropping getTorCtl()
    
    Dropping the method that allowed for raw TorCtl usage. We were only using this
    at a couple places: to make SAVECONF calls and for the interpretor. The
    interpretor still needs raw controller access (that's kinda what it's there
    for), so swapped it over to stem's msg() method.
    
    This also fixes a bug where raw controller commands would spew their output on
    a single line. For instance...
    
    >>> PROTOCOLINFO
    PROTOCOLINFO 1AUTH METHODS=NULLVERSION Tor="0.2.1.30"OK
    
    ... rather than...
    
    >>> PROTOCOLINFO
    PROTOCOLINFO 1
    AUTH METHODS=NULL
    VERSION Tor="0.2.1.30"
    OK
---
 src/util/torConfig.py      |    2 +-
 src/util/torInterpretor.py |   16 ++++++++--------
 src/util/torTools.py       |   25 ++++++++++++-------------
 3 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/util/torConfig.py b/src/util/torConfig.py
index fc08393..c9ae6ef 100644
--- a/src/util/torConfig.py
+++ b/src/util/torConfig.py
@@ -463,7 +463,7 @@ def saveConf(destination = None, contents = None):
   # attempts SAVECONF if we're updating our torrc with the current state
   if isSaveconf:
     try:
-      torTools.getConn().getTorCtl().save_conf()
+      torTools.getConn().saveConf()
       
       try: getTorrc().load()
       except IOError: pass
diff --git a/src/util/torInterpretor.py b/src/util/torInterpretor.py
index d88c137..674e5e2 100644
--- a/src/util/torInterpretor.py
+++ b/src/util/torInterpretor.py
@@ -9,6 +9,8 @@ import sys
 
 import version
 
+import stem
+
 # TODO: util should never import from the cli. This is being done as a hack to
 # simplify event listening, but we should later move the TorEventObserver into
 # the util.
@@ -929,18 +931,16 @@ class ControlInterpretor:
         outputEntry.append((MULTILINE_UNIMPLEMENTED_NOTICE + "\n", ERROR_FORMAT))
       else:
         try:
-          response = conn.getTorCtl().sendAndRecv("%s\r\n" % input)
+          controller = conn.controller
+          if controller is None: raise stem.SocketClosed()
+          
+          response = controller.msg(input)
           
           if cmd == "QUIT":
             raise InterpretorClosed("Closing the connection")
           
-          for entry in response:
-            # Response entries are tuples with the response code, body, and
-            # extra info. For instance:
-            # ('250', 'version=0.2.2.23-alpha (git-b85eb949b528f4d7)', None)
-            
-            if len(entry) == 3:
-              outputEntry.append((entry[1], OUTPUT_FORMAT))
+          for _, _, content in response.content():
+            outputEntry.append((content + '\n', OUTPUT_FORMAT))
         except Exception, exc:
           if isinstance(exc, InterpretorClosed):
             raise exc
diff --git a/src/util/torTools.py b/src/util/torTools.py
index 5eb04ad..36cb70f 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -636,19 +636,6 @@ class Controller(TorCtl.PostEventListener):
     
     return self.lastHeartbeat
   
-  def getTorCtl(self):
-    """
-    Provides the current TorCtl connection. If unset or closed then this
-    returns None.
-    """
-    
-    self.connLock.acquire()
-    result = None
-    if self.isAlive(): result = self.conn
-    self.connLock.release()
-    
-    return result
-  
   def getInfo(self, param, default = UNDEFINED):
     """
     Queries the control port for the given GETINFO option, providing the
@@ -760,6 +747,18 @@ class Controller(TorCtl.PostEventListener):
     finally:
       self.connLock.release()
   
+  def saveConf(self):
+    """
+    Calls tor's SAVECONF method.
+    """
+    
+    self.connLock.acquire()
+    
+    if self.isAlive():
+      self.controller.save_conf()
+    
+    self.connLock.release()
+  
   def sendNewnym(self):
     """
     Sends a newnym request to Tor. These are rate limited so if it occures





More information about the tor-commits mailing list