[tor-commits] [arm/master] Using stem's new newnym methods

atagar at torproject.org atagar at torproject.org
Mon Jan 27 03:50:15 UTC 2014


commit 36507a4c239383971c7559171b68d1896f10ef0c
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Jan 26 19:24:26 2014 -0800

    Using stem's new newnym methods
    
    Moved this capability to stem so no need to keep our couterparts.
---
 arm/header_panel.py   |    8 ++++----
 arm/util/tor_tools.py |   39 ---------------------------------------
 2 files changed, 4 insertions(+), 43 deletions(-)

diff --git a/arm/header_panel.py b/arm/header_panel.py
index b4c6a1d..8621fb3 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -21,6 +21,7 @@ import threading
 
 import arm.util.tracker
 
+from stem import Signal
 from stem.control import State
 from stem.util import conf, log, str_tools
 
@@ -146,7 +147,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
     Requests a new identity and provides a visual queue.
     """
 
-    tor_tools.get_conn().send_newnym()
+    tor_controller().signal(Signal.NEWNYM)
 
     # If we're wide then the newnym label in this panel will give an
     # indication that the signal was sent. Otherwise use a msg.
@@ -159,7 +160,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
   def handle_key(self, key):
     is_keystroke_consumed = True
 
-    if key in (ord('n'), ord('N')) and tor_tools.get_conn().is_newnym_available():
+    if key in (ord('n'), ord('N')) and tor_controller().is_newnym_available():
       self.send_newnym()
     elif key in (ord('r'), ord('R')) and not self._is_tor_connected:
       #oldSocket = tor_tools.get_conn().get_controller().get_socket()
@@ -440,8 +441,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
       # (Client only) Undisplayed / Line 2 Right (new identity option)
 
       if is_wide:
-        conn = tor_tools.get_conn()
-        newnym_wait = conn.get_newnym_wait()
+        newnym_wait = tor_controller().get_newnym_wait()
 
         msg = "press 'n' for a new identity"
 
diff --git a/arm/util/tor_tools.py b/arm/util/tor_tools.py
index a7945fd..0e7aaec 100644
--- a/arm/util/tor_tools.py
+++ b/arm/util/tor_tools.py
@@ -48,7 +48,6 @@ class Controller:
     self._address_lookup_cache = {}       # lookup cache with fingerprint -> (ip address, or port) mappings
     self._consensus_lookup_cache = {}     # lookup cache with network status entries
     self._descriptor_lookup_cache = {}    # lookup cache with relay descriptors
-    self._last_newnym = 0                 # time we last sent a NEWNYM signal
 
   def init(self, controller):
     """
@@ -84,10 +83,6 @@ class Controller:
       self._consensus_lookup_cache = {}
       self._descriptor_lookup_cache = {}
 
-      # time that we sent our last newnym signal
-
-      self._last_newnym = 0
-
       self.conn_lock.release()
 
   def close(self):
@@ -224,40 +219,6 @@ class Controller:
 
     self.conn_lock.release()
 
-  def send_newnym(self):
-    """
-    Sends a newnym request to Tor. These are rate limited so if it occures
-    more than once within a ten second window then the second is delayed.
-    """
-
-    self.conn_lock.acquire()
-
-    if self.is_alive():
-      self._last_newnym = time.time()
-      self.controller.signal(stem.Signal.NEWNYM)
-
-    self.conn_lock.release()
-
-  def is_newnym_available(self):
-    """
-    True if Tor will immediately respect a newnym request, false otherwise.
-    """
-
-    if self.is_alive():
-      return self.get_newnym_wait() == 0
-    else:
-      return False
-
-  def get_newnym_wait(self):
-    """
-    Provides the number of seconds until a newnym signal would be respected.
-    """
-
-    # newnym signals can occure at the rate of one every ten seconds
-    # TODO: this can't take other controllers into account :(
-
-    return max(0, math.ceil(self._last_newnym + 10 - time.time()))
-
   def get_circuits(self, default = []):
     """
     This provides a list with tuples of the form:





More information about the tor-commits mailing list