[or-cvs] r18722: {torctl} Fix a warn with nicknames not being present in the map, and (torctl/trunk/python/TorCtl)

mikeperry at seul.org mikeperry at seul.org
Sat Feb 28 15:08:12 UTC 2009


Author: mikeperry
Date: 2009-02-28 10:08:12 -0500 (Sat, 28 Feb 2009)
New Revision: 18722

Modified:
   torctl/trunk/python/TorCtl/PathSupport.py
   torctl/trunk/python/TorCtl/StatsSupport.py
   torctl/trunk/python/TorCtl/TorCtl.py
Log:

Fix a warn with nicknames not being present in the map, and 
another sync warn.



Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py	2009-02-28 14:20:29 UTC (rev 18721)
+++ torctl/trunk/python/TorCtl/PathSupport.py	2009-02-28 15:08:12 UTC (rev 18722)
@@ -1359,10 +1359,12 @@
       for r in circ.path:
         r.refcount -= 1
         if r.deleted and r.refcount == 0:
-          plog("INFO", "Removing expired descriptor for "+r.idhex)
-          self.sorted_r.remove(self.routers[r.idhex])
+          # XXX: This shouldn't happen with StatsRouters.. 
+          if r.__class__.__name__ == "StatsRouter":
+            plog("WARN", "Purging expired StatsRouter "+r.idhex)
+          else:
+            plog("INFO", "Purging expired router "+r.idhex)
           del self.routers[r.idhex]
-          for i in xrange(len(self.sorted_r)): self.sorted_r[i].list_rank = i
           self.selmgr.new_consensus(self.current_consensus())
       del self.circuits[c.circ_id]
       for stream in circ.pending_streams:

Modified: torctl/trunk/python/TorCtl/StatsSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/StatsSupport.py	2009-02-28 14:20:29 UTC (rev 18721)
+++ torctl/trunk/python/TorCtl/StatsSupport.py	2009-02-28 15:08:12 UTC (rev 18722)
@@ -195,7 +195,7 @@
     self.reset()
     # StatsRouters should not be destroyed when Tor forgets about them
     # Give them an extra refcount:
-    self.refcount += 1 
+    self.refcount += 1
   
   def reset(self):
     "Reset all stats on this Router"

Modified: torctl/trunk/python/TorCtl/TorCtl.py
===================================================================
--- torctl/trunk/python/TorCtl/TorCtl.py	2009-02-28 14:20:29 UTC (rev 18721)
+++ torctl/trunk/python/TorCtl/TorCtl.py	2009-02-28 15:08:12 UTC (rev 18722)
@@ -351,15 +351,9 @@
     'new' """
     if self.idhex != new.idhex:
       plog("ERROR", "Update of router "+self.nickname+"changes idhex!")
-    self.idhex = new.idhex
-    self.nickname = new.nickname
-    self.bw = new.bw
-    self.exitpolicy = new.exitpolicy
-    self.flags = new.flags
-    self.ip = new.ip
-    self.version = new.version
-    self.os = new.os
-    self.uptime = new.uptime
+    for i in new.__dict__.iterkeys():
+      if i == "refcount": pass
+      self.__dict__[i] = new.__dict__[i]
 
   def will_exit_to(self, ip, port):
     """ Check the entire exitpolicy to see if the router will allow
@@ -1116,6 +1110,18 @@
     routers = self.c.read_routers(nslist) # Sets .down if 3,4,5
     old_idhexes = sets.Set(self.routers.keys())
     new_idhexes = sets.Set(map(lambda r: r.idhex, routers)) 
+    for r in routers:
+      if r.idhex in self.routers:
+        if self.routers[r.idhex].nickname != r.nickname:
+          plog("NOTICE", "Router "+r.idhex+" changed names from "
+             +self.routers[r.idhex].nickname+" to "+r.nickname)
+        # Must do IN-PLACE update to keep all the refs to this router
+        # valid and current (especially for stats)
+        self.routers[r.idhex].update_to(r)
+      else:
+        rc = self.RouterClass(r)
+        self.routers[rc.idhex] = rc
+
     removed_idhexes = old_idhexes - new_idhexes
     removed_idhexes.union_update(sets.Set(map(lambda r: r.idhex,
                       filter(lambda r: r.down, routers))))
@@ -1127,33 +1133,36 @@
         self.routers[i].flags.remove("Running")
       if self.routers[i].refcount == 0:
         self.routers[i].deleted = True
-        plog("INFO", "Expiring non-running router "+i)
+        if self.routers[i].__class__.__name__ == "StatsRouter":
+          plog("WARN", "Expiring non-running StatsRouter "+i)
+        else:
+          plog("INFO", "Expiring non-running router "+i)
         del self.routers[i]
       else:
         plog("INFO", "Postponing expiring non-running router "+i)
         self.routers[i].deleted = True
 
-    for r in routers:
-      self.name_to_key[r.nickname] = "$"+r.idhex
-      if r.idhex in self.routers:
-        if self.routers[r.idhex].nickname != r.nickname:
-          plog("NOTICE", "Router "+r.idhex+" changed names from "
-             +self.routers[r.idhex].nickname+" to "+r.nickname)
-        # Must do IN-PLACE update to keep all the refs to this router
-        # valid and current (especially for stats)
-        self.routers[r.idhex].update_to(r)
-      else:
-        rc = self.RouterClass(r)
-        self.routers[rc.idhex] = rc
-
     self.sorted_r = filter(lambda r: not r.down, self.routers.itervalues())
     self.sorted_r.sort(lambda x, y: cmp(y.bw, x.bw))
     for i in xrange(len(self.sorted_r)): self.sorted_r[i].list_rank = i
 
+    # XXX: Verification only. Can be removed.
+    self._sanity_check(self.sorted_r)
+
+  def _sanity_check(self, list):
+    downed =  filter(lambda r: r.down, list)
+    for d in downed:
+      plog("WARN", "Router "+d.idhex+" still present but is down. Del: "+str(d.deleted)+", flags: "+str(d.flags)+", bw: "+str(d.bw))
+ 
+    deleted =  filter(lambda r: r.deleted, list)
+    for d in deleted:
+      plog("WARN", "Router "+d.idhex+" still present but is deleted. Down: "+str(d.down)+", flags: "+str(d.flags)+", bw: "+str(d.bw))
+ 
   def _update_consensus(self, nslist):
     self.ns_map = {}
     for n in nslist:
       self.ns_map[n.idhex] = n
+      self.name_to_key[n.nickname] = "$"+n.idhex
    
   def update_consensus(self):
     self._update_consensus(self.c.get_network_status())
@@ -1177,6 +1186,7 @@
         plog("WARN", "Multiple descs for "+i+" after NEWDESC")
       r = r[0]
       ns = ns[0]
+      self.name_to_key[ns.nickname] = "$"+ns.idhex
       if r and r.idhex in self.ns_map:
         if ns.orhash != self.ns_map[r.idhex].orhash:
           plog("WARN", "Getinfo and consensus disagree for "+r.idhex)



More information about the tor-commits mailing list