[or-cvs] r20090: {arm} Fixed a couple bugs, the most interesting being when netstat (arm/trunk/interface)

atagar at seul.org atagar at seul.org
Sun Jul 19 17:54:12 UTC 2009


Author: atagar
Date: 2009-07-19 13:54:11 -0400 (Sun, 19 Jul 2009)
New Revision: 20090

Modified:
   arm/trunk/interface/connPanel.py
   arm/trunk/interface/controller.py
   arm/trunk/interface/headerPanel.py
Log:
Fixed a couple bugs, the most interesting being when netstat can't resolve a connections listing (spotted by phobos).


Modified: arm/trunk/interface/connPanel.py
===================================================================
--- arm/trunk/interface/connPanel.py	2009-07-19 17:03:34 UTC (rev 20089)
+++ arm/trunk/interface/connPanel.py	2009-07-19 17:54:11 UTC (rev 20090)
@@ -257,62 +257,63 @@
         self.clear()
         if self.showLabel: self.addstr(0, 0, "Connections (%i inbound, %i outbound, %i control):" % tuple(self.connectionCount), util.LABEL_ATTR)
         
-        listingHeight = self.maxY - 1
-        if self.showingDetails: listingHeight -= 8
-        
-        # ensure cursor location and scroll top are within bounds
-        self.cursorLoc = max(min(self.cursorLoc, len(self.connections) - 1), 0)
-        self.scroll = max(min(self.scroll, len(self.connections) - listingHeight), 0)
-        
-        if self.isCursorEnabled:
-          # update cursorLoc with selection (or vice versa if selection not found)
-          if self.cursorSelection not in self.connections:
-            self.cursorSelection = self.connections[self.cursorLoc]
-          else: self.cursorLoc = self.connections.index(self.cursorSelection)
+        if self.connections:
+          listingHeight = self.maxY - 1
+          if self.showingDetails: listingHeight -= 8
           
-          # shift scroll if necessary for cursor to be visible
-          if self.cursorLoc < self.scroll: self.scroll = self.cursorLoc
-          elif self.cursorLoc - listingHeight + 1 > self.scroll: self.scroll = self.cursorLoc - listingHeight + 1
-        
-        lineNum = (-1 * self.scroll) + 1
-        for entry in self.connections:
-          if lineNum >= 1:
-            type = entry[CONN_TYPE]
-            color = TYPE_COLORS[type]
+          # ensure cursor location and scroll top are within bounds
+          self.cursorLoc = max(min(self.cursorLoc, len(self.connections) - 1), 0)
+          self.scroll = max(min(self.scroll, len(self.connections) - listingHeight), 0)
+          
+          if self.isCursorEnabled:
+            # update cursorLoc with selection (or vice versa if selection not found)
+            if self.cursorSelection not in self.connections:
+              self.cursorSelection = self.connections[self.cursorLoc]
+            else: self.cursorLoc = self.connections.index(self.cursorSelection)
             
-            if self.listingType == LIST_IP:
-              src = "%s:%s" % (entry[CONN_L_IP], entry[CONN_L_PORT])
-              dst = "%s:%s %s" % (entry[CONN_F_IP], entry[CONN_F_PORT], "" if type == "control" else "(%s)" % entry[CONN_COUNTRY])
-              src, dst = "%-26s" % src, "%-26s" % dst
-            elif self.listingType == LIST_HOSTNAME:
-              src = "localhost:%-5s" % entry[CONN_L_PORT]
-              hostname = self.resolver.resolve(entry[CONN_F_IP])
+            # shift scroll if necessary for cursor to be visible
+            if self.cursorLoc < self.scroll: self.scroll = self.cursorLoc
+            elif self.cursorLoc - listingHeight + 1 > self.scroll: self.scroll = self.cursorLoc - listingHeight + 1
+          
+          lineNum = (-1 * self.scroll) + 1
+          for entry in self.connections:
+            if lineNum >= 1:
+              type = entry[CONN_TYPE]
+              color = TYPE_COLORS[type]
               
-              # truncates long hostnames
-              portDigits = len(str(entry[CONN_F_PORT]))
-              if hostname and (len(hostname) + portDigits) > 36: hostname = hostname[:(33 - portDigits)] + "..."
+              if self.listingType == LIST_IP:
+                src = "%s:%s" % (entry[CONN_L_IP], entry[CONN_L_PORT])
+                dst = "%s:%s %s" % (entry[CONN_F_IP], entry[CONN_F_PORT], "" if type == "control" else "(%s)" % entry[CONN_COUNTRY])
+                src, dst = "%-26s" % src, "%-26s" % dst
+              elif self.listingType == LIST_HOSTNAME:
+                src = "localhost:%-5s" % entry[CONN_L_PORT]
+                hostname = self.resolver.resolve(entry[CONN_F_IP])
+                
+                # truncates long hostnames
+                portDigits = len(str(entry[CONN_F_PORT]))
+                if hostname and (len(hostname) + portDigits) > 36: hostname = hostname[:(33 - portDigits)] + "..."
+                
+                dst = "%s:%s" % (hostname if hostname else entry[CONN_F_IP], entry[CONN_F_PORT])
+                dst = "%-37s" % dst
+              elif self.listingType == LIST_FINGERPRINT:
+                src = "localhost  "
+                if entry[CONN_TYPE] == "control": dst = "localhost"
+                else: dst = self.getFingerprint(entry[CONN_F_IP], entry[CONN_F_PORT])
+                dst = "%-41s" % dst
+              else:
+                src = "%-11s" % self.nickname
+                if entry[CONN_TYPE] == "control": dst = self.nickname
+                else: dst = self.getNickname(entry[CONN_F_IP], entry[CONN_F_PORT])
+                dst = "%-41s" % dst
               
-              dst = "%s:%s" % (hostname if hostname else entry[CONN_F_IP], entry[CONN_F_PORT])
-              dst = "%-37s" % dst
-            elif self.listingType == LIST_FINGERPRINT:
-              src = "localhost  "
-              if entry[CONN_TYPE] == "control": dst = "localhost"
-              else: dst = self.getFingerprint(entry[CONN_F_IP], entry[CONN_F_PORT])
-              dst = "%-41s" % dst
-            else:
-              src = "%-11s" % self.nickname
-              if entry[CONN_TYPE] == "control": dst = self.nickname
-              else: dst = self.getNickname(entry[CONN_F_IP], entry[CONN_F_PORT])
-              dst = "%-41s" % dst
-            
-            if type == "inbound": src, dst = dst, src
-            lineEntry = "<%s>%s -->   %s   (<b>%s</b>)</%s>" % (color, src, dst, type.upper(), color)
-            if self.isCursorEnabled and entry == self.cursorSelection:
-              lineEntry = "<h>%s</h>" % lineEntry
-            
-            offset = 0 if not self.showingDetails else 8
-            self.addfstr(lineNum + offset, 0, lineEntry)
-          lineNum += 1
+              if type == "inbound": src, dst = dst, src
+              lineEntry = "<%s>%s -->   %s   (<b>%s</b>)</%s>" % (color, src, dst, type.upper(), color)
+              if self.isCursorEnabled and entry == self.cursorSelection:
+                lineEntry = "<h>%s</h>" % lineEntry
+              
+              offset = 0 if not self.showingDetails else 8
+              self.addfstr(lineNum + offset, 0, lineEntry)
+            lineNum += 1
         
         self.refresh()
       finally:

Modified: arm/trunk/interface/controller.py
===================================================================
--- arm/trunk/interface/controller.py	2009-07-19 17:03:34 UTC (rev 20089)
+++ arm/trunk/interface/controller.py	2009-07-19 17:54:11 UTC (rev 20090)
@@ -499,15 +499,22 @@
             # fingerprint found - retrieve related data
             if selection in relayLookupCache.keys(): nsEntry, descEntry = relayLookupCache[selection]
             else:
-              nsData = conn.get_network_status("id/%s" % fingerprint)
+              # ns lookup fails... weird
+              try: nsData = conn.get_network_status("id/%s" % fingerprint)
+              except TorCtl.ErrorReply: break
               
               if len(nsData) > 1:
                 # multiple records for fingerprint (shouldn't happen)
                 panels["log"].monitor_event("WARN", "Multiple consensus entries for fingerprint: %s" % fingerprint)
               
               nsEntry = nsData[0]
-              descLookupCmd = "desc/id/%s" % fingerprint
-              descEntry = TorCtl.Router.build_from_desc(conn.get_info(descLookupCmd)[descLookupCmd].split("\n"), nsEntry)
+              
+              # 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
+              
               relayLookupCache[selection] = (nsEntry, descEntry)
             
             popup.addstr(2, 15, "fingerprint: %s" % fingerprint, format)

Modified: arm/trunk/interface/headerPanel.py
===================================================================
--- arm/trunk/interface/headerPanel.py	2009-07-19 17:03:34 UTC (rev 20089)
+++ arm/trunk/interface/headerPanel.py	2009-07-19 17:54:11 UTC (rev 20090)
@@ -142,6 +142,7 @@
     if self.vals["fingerprint"] != "Unknown":
       try: self.vals["flags"] = self.conn.get_network_status("id/%s" % self.vals["fingerprint"])[0].flags
       except TorCtl.TorCtlClosed: pass
+      except TorCtl.ErrorReply: pass
       except socket.error: pass
     
     # ps call provides header followed by params for tor



More information about the tor-commits mailing list