[or-cvs] r18571: {torflow} Use new ConsensusTracker in the rest of TorFlow. (in torflow/trunk: . CircuitAnalysis/BuildTimes NetworkScanners)

mikeperry at seul.org mikeperry at seul.org
Mon Feb 16 11:46:13 UTC 2009


Author: mikeperry
Date: 2009-02-16 06:46:12 -0500 (Mon, 16 Feb 2009)
New Revision: 18571

Modified:
   torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py
   torflow/trunk/NetworkScanners/soat.py
   torflow/trunk/metatroller.py
Log:

Use new ConsensusTracker in the rest of TorFlow.



Modified: torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py
===================================================================
--- torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py	2009-02-16 11:45:43 UTC (rev 18570)
+++ torflow/trunk/CircuitAnalysis/BuildTimes/buildtimes.py	2009-02-16 11:46:12 UTC (rev 18571)
@@ -114,7 +114,7 @@
         self.failfile.flush()
     StatsHandler.circ_status_event(self,circ_event)
 
-  def newconsensus_event(self, n):
+  def new_consensus_event(self, n):
     # Record previous rank and history.
     for ns in n.nslist:
       if not ns.idhex in self.routers:
@@ -123,9 +123,8 @@
       r.bw_history.append(r.bw)
     for r in self.sorted_r:
       r.rank_history.append(r.list_rank)
-    StatsHandler.newconsensus_event(self, n)
+    StatsHandler.new_consensus_event(self, n)
 
-
 def cleanup():
   s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   s.connect((control_host,control_port))
@@ -154,7 +153,7 @@
   c.set_events([TorCtl.EVENT_TYPE.STREAM,
                 TorCtl.EVENT_TYPE.BW,
                 TorCtl.EVENT_TYPE.NEWCONSENSUS,
-                #TorCtl.EVENT_TYPE.NEWDESC,
+                TorCtl.EVENT_TYPE.NEWDESC,
                 TorCtl.EVENT_TYPE.CIRC,
                 TorCtl.EVENT_TYPE.STREAM_BW], True)
   return c

Modified: torflow/trunk/NetworkScanners/soat.py
===================================================================
--- torflow/trunk/NetworkScanners/soat.py	2009-02-16 11:45:43 UTC (rev 18570)
+++ torflow/trunk/NetworkScanners/soat.py	2009-02-16 11:46:12 UTC (rev 18571)
@@ -55,7 +55,7 @@
 from TorCtl.TorUtil import meta_port, meta_host, control_port, control_host, tor_port, tor_host
 from TorCtl.TorUtil import *
 from TorCtl.PathSupport import *
-from TorCtl.TorCtl import Connection, EventHandler
+from TorCtl.TorCtl import Connection, EventHandler, ConsensusTracker
 
 import OpenSSL
 from OpenSSL import *
@@ -2051,24 +2051,19 @@
       response = response[:-1]
     return response 
 
-class NodeManager(EventHandler):
-  # FIXME: Periodically check to see if we are accumulating stalte
-  # descriptors and prune them..
+class NodeManager(ConsensusTracker):
   ''' 
   A tor control event handler extending TorCtl.EventHandler.
   Monitors NS and NEWDESC events, and updates each test
   with new nodes
   '''
   def __init__(self, c):
-    EventHandler.__init__(self)
-    self.c = c
-    self.routers = {}
-    self.sorted_r = []
+    ConsensusTracker.__init__(self, c)
     self.rlock = threading.Lock()
-    self._read_routers(self.c.get_network_status())
     self.new_nodes=True
     c.set_event_handler(self)
-    c.set_events([TorCtl.EVENT_TYPE.NEWCONSENSUS], True)
+    c.set_events([TorCtl.EVENT_TYPE.NEWCONSENSUS,
+                  TorCtl.EVENT_TYPE.NEWDESC], True)
 
   def has_new_nodes(self):
     ret = False
@@ -2095,30 +2090,26 @@
     plog("DEBUG", "get_nodes_for_port end")
     return ret
  
-  def _read_routers(self, nslist):
-    routers = self.c.read_routers(nslist)
-    self.sorted_r = []
-    self.routers = {}
-    for r in routers:
-      self.routers[r.idhex] = r
-      self.sorted_r.append(r)
-
-    self.sorted_r.sort(lambda x, y: cmp(y.bw, x.bw))
-    # This is an OK update because of the GIL (also we don't touch it)
-    for i in xrange(len(self.sorted_r)): self.sorted_r[i].list_rank = i
-
-  def newconsensus_event(self, n):
+  def new_consensus_event(self, n):
     plog("DEBUG", "newconsensus_event begin")
     try:
       self.rlock.acquire()
-      self._read_routers(n.nslist)
+      ConsensusTracker.new_consensus_event(self, n)
       self.new_nodes = True
     finally:
       self.rlock.release()
-    plog("DEBUG", "Read " + str(len(n.nslist))+" NC => " 
-       + str(len(self.sorted_r)) + " routers")
- 
+    plog("DEBUG", "newconsensus_event end")
 
+  def new_desc_event(self, d):
+    plog("DEBUG", "newdesc_event begin")
+    try:
+      self.rlock.acquire()
+      if ConsensusTracker.new_desc_event(self, d):
+        self.new_nodes = True
+    finally:
+      self.rlock.release()
+    plog("DEBUG", "newdesc_event end")
+
 class DNSRebindScanner(EventHandler):
   ''' 
   A tor control event handler extending TorCtl.EventHandler 

Modified: torflow/trunk/metatroller.py
===================================================================
--- torflow/trunk/metatroller.py	2009-02-16 11:45:43 UTC (rev 18570)
+++ torflow/trunk/metatroller.py	2009-02-16 11:46:12 UTC (rev 18571)
@@ -254,7 +254,7 @@
   c.set_events([TorCtl.EVENT_TYPE.STREAM,
           TorCtl.EVENT_TYPE.BW,
           TorCtl.EVENT_TYPE.NEWCONSENSUS,
-          #TorCtl.EVENT_TYPE.NEWDESC,
+          TorCtl.EVENT_TYPE.NEWDESC,
           TorCtl.EVENT_TYPE.CIRC,
           TorCtl.EVENT_TYPE.STREAM_BW], True)
   c.set_option("__LeaveStreamsUnattached", "1") 



More information about the tor-commits mailing list