[or-cvs] r20115: {arm} Another small grab bag update. added: version status to head (in arm/trunk: . interface)
atagar at seul.org
atagar at seul.org
Wed Jul 22 19:41:21 UTC 2009
Author: atagar
Date: 2009-07-22 15:41:20 -0400 (Wed, 22 Jul 2009)
New Revision: 20115
Modified:
arm/trunk/interface/connPanel.py
arm/trunk/interface/controller.py
arm/trunk/interface/headerPanel.py
arm/trunk/readme.txt
Log:
Another small grab bag update.
added: version status to header panel
change: noted "Common *nix commands including: ps, pidof, host, and netstat" among requirements in readme
change: took some tricks from Mike's ConsensusTracker to further improve match rate
fix: type mismatch that greatly diminished fingerprint matching
fix: accidently used idhash rather than idhex for fingerprints when updating cache with the contents of a NEWDESC event
Modified: arm/trunk/interface/connPanel.py
===================================================================
--- arm/trunk/interface/connPanel.py 2009-07-22 16:52:40 UTC (rev 20114)
+++ arm/trunk/interface/connPanel.py 2009-07-22 19:41:20 UTC (rev 20115)
@@ -154,9 +154,9 @@
if orportMatch: self.fingerprintMappings[nsEntry.ip].remove(orportMatch)
# add new entry
- self.fingerprintMappings[nsEntry.ip].append((nsEntry.orport, nsEntry.idhash))
+ self.fingerprintMappings[nsEntry.ip].append((nsEntry.orport, nsEntry.idhex))
else:
- self.fingerprintMappings[nsEntry.ip] = [(nsEntry.orport, nsEntry.idhash)]
+ self.fingerprintMappings[nsEntry.ip] = [(nsEntry.orport, nsEntry.idhex)]
def reset(self):
"""
@@ -325,19 +325,46 @@
returns "UNKNOWN".
"""
+ port = int(port)
if (ipAddr, port) in self.fingerprintLookupCache:
return self.fingerprintLookupCache[(ipAddr, port)]
else:
- match = "UNKNOWN"
+ match = None
if ipAddr in self.fingerprintMappings.keys():
potentialMatches = self.fingerprintMappings[ipAddr]
if len(potentialMatches) == 1: match = potentialMatches[0][1]
- else:
+
+ if not match:
+ # multiple potential matches - look for exact match with port
for (entryPort, entryFingerprint) in potentialMatches:
- if entryPort == port: match = entryFingerprint
-
+ if entryPort == port:
+ match = entryFingerprint
+ break
+
+ if not match:
+ # still haven't found it - use trick from Mike's ConsensusTracker,
+ # excluding possiblities that have...
+ # ... lost their Running flag
+ # ... list a bandwidth of 0
+ # ... have 'opt hibernating' set
+ operativeMatches = list(potentialMatches)
+ for (entryPort, entryFingerprint) in potentialMatches:
+ # gets router description to see if 'down' is set
+ try:
+ nsData = self.conn.get_network_status("id/%s" % entryFingerprint)
+ if len(nsData) != 1: continue # ns lookup failed... weird
+ else: nsEntry = nsData[0]
+
+ descLookupCmd = "desc/id/%s" % entryFingerprint
+ descEntry = TorCtl.Router.build_from_desc(self.conn.get_info(descLookupCmd)[descLookupCmd].split("\n"), nsEntry)
+ if descEntry.down: operativeMatches.remove((entryPort, entryFingerprint))
+ except TorCtl.ErrorReply: pass # ns or desc lookup fails... also weird
+
+ if len(operativeMatches) == 1: match = operativeMatches[0][1]
+
+ if not match: match = "UNKNOWN"
self.fingerprintLookupCache[(ipAddr, port)] = match
return match
Modified: arm/trunk/interface/controller.py
===================================================================
--- arm/trunk/interface/controller.py 2009-07-22 16:52:40 UTC (rev 20114)
+++ arm/trunk/interface/controller.py 2009-07-22 19:41:20 UTC (rev 20115)
@@ -537,11 +537,10 @@
nsEntry = nsData[0]
- # desc lookup fails... also weird
try:
descLookupCmd = "desc/id/%s" % fingerprint
descEntry = TorCtl.Router.build_from_desc(conn.get_info(descLookupCmd)[descLookupCmd].split("\n"), nsEntry)
- except TorCtl.ErrorReply: break
+ except TorCtl.ErrorReply: break # desc lookup fails... also weird
relayLookupCache[selection] = (nsEntry, descEntry)
Modified: arm/trunk/interface/headerPanel.py
===================================================================
--- arm/trunk/interface/headerPanel.py 2009-07-22 16:52:40 UTC (rev 20114)
+++ arm/trunk/interface/headerPanel.py 2009-07-22 19:41:20 UTC (rev 20115)
@@ -14,6 +14,9 @@
"Stable": "blue", "Running": "yellow", "Unnamed": "magenta", "Valid": "green",
"V2Dir": "cyan", "V3Dir": "white"}
+VERSION_STATUS_COLORS = {"new": "blue", "new in series": "blue", "recommended": "green",
+ "old": "red", "obsolete": "red", "unrecommended": "red"}
+
class HeaderPanel(util.Panel):
"""
Draws top area containing static information.
@@ -51,8 +54,11 @@
# Line 1
self.addstr(0, 0, "arm - %s (%s %s)" % (self.vals["sys-name"], self.vals["sys-os"], self.vals["sys-version"]))
- self.addstr(0, 45, "Tor %s" % self.vals["version"])
+ versionStatus = self.vals["status/version/current"]
+ versionColor = VERSION_STATUS_COLORS[versionStatus] if versionStatus in VERSION_STATUS_COLORS else "white"
+ self.addfstr(0, 43, "Tor %s (<%s>%s</%s>)" % (self.vals["version"], versionColor, versionStatus, versionColor))
+
# Line 2 (authentication label red if open, green if credentials required)
dirPortLabel = "Dir Port: %s, " % self.vals["DirPort"] if self.vals["DirPort"] != "0" else ""
@@ -96,7 +102,7 @@
"""
Updates mapping of static Tor settings and system information to their
corresponding string values. Keys include:
- info - version, *address, *fingerprint, *flags
+ info - version, *address, *fingerprint, *flags, status/version/current
sys - sys-name, sys-os, sys-version
ps - *%cpu, *rss, *%mem, *pid, *etime
config - Nickname, ORPort, DirPort, ControlPort
@@ -106,9 +112,10 @@
already set)
"""
+ infoFields = ["address", "fingerprint"] # keys for which get_info will be called
if len(self.vals) <= 1:
- # only contains 'pid' - retrieves static params
- self.vals["version"] = self.conn.get_info(["version"])["version"]
+ # first call (only contasns 'pid' mapping) - retrieve static params
+ infoFields += ["version", "status/version/current"]
# populates with some basic system information
unameVals = os.uname()
@@ -127,7 +134,7 @@
self.vals["IsAccountingEnabled"] = self.conn.get_info('accounting/enabled')['accounting/enabled'] == "1"
# gets parameters that throw errors if unavailable
- for param in ["address", "fingerprint"]:
+ for param in infoFields:
try: self.vals.update(self.conn.get_info(param))
except TorCtl.ErrorReply: self.vals[param] = "Unknown"
except TorCtl.TorCtlClosed:
Modified: arm/trunk/readme.txt
===================================================================
--- arm/trunk/readme.txt 2009-07-22 16:52:40 UTC (rev 20114)
+++ arm/trunk/readme.txt 2009-07-22 19:41:20 UTC (rev 20115)
@@ -8,6 +8,7 @@
Requirements:
Python 2.5
TorCtl (retrieved in svn checkout)
+Common *nix commands including: ps, pidof, host, and netstat
Tor is running with an available control port. This means either...
... starting Tor with '--controlport <PORT>'
... or including 'ControlPort <PORT>' in your torrc
More information about the tor-commits
mailing list