[or-cvs] r24226: {arm} fix: The header panel displayed the wrong IP address if it c (in arm/trunk: . src/interface src/util)

Damian Johnson atagar1 at gmail.com
Mon Feb 14 04:54:54 UTC 2011


Author: atagar
Date: 2011-02-14 04:54:54 +0000 (Mon, 14 Feb 2011)
New Revision: 24226

Modified:
   arm/trunk/TODO
   arm/trunk/src/interface/headerPanel.py
   arm/trunk/src/util/torTools.py
Log:
fix: The header panel displayed the wrong IP address if it changed since we first started.



Modified: arm/trunk/TODO
===================================================================
--- arm/trunk/TODO	2011-02-14 00:36:29 UTC (rev 24225)
+++ arm/trunk/TODO	2011-02-14 04:54:54 UTC (rev 24226)
@@ -70,9 +70,6 @@
   * When saving the config the Log entry should be filtered out if unnecessary.
   * The config write dialog (ie, the one for saving the config) has its a
     misaligned border when it's smaller than the top detail section.
-  * The arm header panel doesn't properly reflect when the ip address
-    changes. This provides a notice event saying:
-    "Our IP Address has changed from X to Y; rebuilding descriptor (source Z)."
   * The cpu usage spikes for scrollable content when the key's held. Try
     coalescing the events.
   * The manpage layout is system dependent, so the scraper needs to be more

Modified: arm/trunk/src/interface/headerPanel.py
===================================================================
--- arm/trunk/src/interface/headerPanel.py	2011-02-14 00:36:29 UTC (rev 24225)
+++ arm/trunk/src/interface/headerPanel.py	2011-02-14 04:54:54 UTC (rev 24226)
@@ -37,8 +37,8 @@
   Top area contenting tor settings and system information. Stats are stored in
   the vals mapping, keys including:
     tor/  version, versionStatus, nickname, orPort, dirPort, controlPort,
-          exitPolicy, isAuthPassword (bool), isAuthCookie (bool)
-          *address, *fingerprint, *flags, pid, startTime
+          exitPolicy, isAuthPassword (bool), isAuthCookie (bool),
+          orListenAddr, *address, *fingerprint, *flags, pid, startTime
     sys/  hostname, os, version
     stat/ *%torCpu, *%armCpu, *rss, *%mem
   
@@ -127,10 +127,14 @@
     
     # Line 2 / Line 2 Left (tor ip/port information)
     if self.vals["tor/orPort"]:
+      myAddress = "Unknown"
+      if self.vals["tor/orListenAddr"]: myAddress = self.vals["tor/orListenAddr"]
+      elif self.vals["tor/address"]: myAddress = self.vals["tor/address"]
+      
       # acting as a relay (we can assume certain parameters are set
       entry = ""
       dirPortLabel = ", Dir Port: %s" % self.vals["tor/dirPort"] if self.vals["tor/dirPort"] != "0" else ""
-      for label in (self.vals["tor/nickname"], " - " + self.vals["tor/address"], ":" + self.vals["tor/orPort"], dirPortLabel):
+      for label in (self.vals["tor/nickname"], " - " + myAddress, ":" + self.vals["tor/orPort"], dirPortLabel):
         if len(entry) + len(label) <= leftWidth: entry += label
         else: break
     else:
@@ -329,15 +333,15 @@
       if self.vals["tor/orPort"] == "0": self.vals["tor/orPort"] = ""
       
       # overwrite address if ORListenAddress is set (and possibly orPort too)
-      self.vals["tor/address"] = "Unknown"
+      self.vals["tor/orListenAddr"] = ""
       listenAddr = conn.getOption("ORListenAddress")
       if listenAddr:
         if ":" in listenAddr:
           # both ip and port overwritten
-          self.vals["tor/address"] = listenAddr[:listenAddr.find(":")]
+          self.vals["tor/orListenAddr"] = listenAddr[:listenAddr.find(":")]
           self.vals["tor/orPort"] = listenAddr[listenAddr.find(":") + 1:]
         else:
-          self.vals["tor/address"] = listenAddr
+          self.vals["tor/orListenAddr"] = listenAddr
       
       # fetch exit policy (might span over multiple lines)
       policyEntries = []
@@ -368,8 +372,7 @@
     # sets volatile parameters
     # TODO: This can change, being reported by STATUS_SERVER -> EXTERNAL_ADDRESS
     # events. Introduce caching via torTools?
-    if self.vals["tor/address"] == "Unknown":
-      self.vals["tor/address"] = conn.getInfo("address", self.vals["tor/address"])
+    self.vals["tor/address"] = conn.getInfo("address", "")
     
     self.vals["tor/fingerprint"] = conn.getInfo("fingerprint", self.vals["tor/fingerprint"])
     self.vals["tor/flags"] = conn.getMyFlags(self.vals["tor/flags"])

Modified: arm/trunk/src/util/torTools.py
===================================================================
--- arm/trunk/src/util/torTools.py	2011-02-14 00:36:29 UTC (rev 24225)
+++ arm/trunk/src/util/torTools.py	2011-02-14 04:54:54 UTC (rev 24226)
@@ -53,10 +53,20 @@
 # options (unchangable, even with a SETCONF) and other useful stats
 CACHE_ARGS = ("version", "config-file", "exit-policy/default", "fingerprint",
               "config/names", "info/names", "features/names", "events/names",
-              "nsEntry", "descEntry", "bwRate", "bwBurst", "bwObserved",
-              "bwMeasured", "flags", "pid", "pathPrefix", "startTime",
-              "authorities")
+              "nsEntry", "descEntry", "address", "bwRate", "bwBurst",
+              "bwObserved", "bwMeasured", "flags", "pid", "pathPrefix",
+              "startTime", "authorities")
 
+# Tor has a couple messages (in or/router.c) for when our ip address changes:
+# "Our IP Address has changed from <previous> to <current>; rebuilding
+#   descriptor (source: <source>)."
+# "Guessed our IP address as <current> (source: <source>)."
+# 
+# It would probably be preferable to use the EXTERNAL_ADDRESS event, but I'm
+# not quite sure why it's not provided by check_descriptor_ipaddress_changed
+# so erring on the side of inclusiveness by using the notice event instead.
+ADDR_CHANGED_MSG_PREFIX = ("Our IP Address has changed from", "Guessed our IP address as")
+
 TOR_CTL_CLOSE_MSG = "Tor closed control connection. Exiting event thread."
 UNKNOWN = "UNKNOWN" # value used by cached information if undefined
 CONFIG = {"torrc.map": {},
@@ -1205,6 +1215,15 @@
     
     # checks if TorCtl is providing a notice that control port is closed
     if TOR_CTL_CLOSE_MSG in msg: self.close()
+    
+    # if the message is informing us of our ip address changing then clear
+    # its cached value
+    isAddrChangeEvent = False
+    for prefix in ADDR_CHANGED_MSG_PREFIX:
+      isAddrChangeEvent |= msg.startswith(prefix)
+    
+    if isAddrChangeEvent and "address" in self._cachedParam:
+      del self._cachedParam["address"]
   
   def _updateHeartbeat(self):
     """



More information about the tor-commits mailing list