[or-cvs] r17880: {torctl} Fix bug with circuits not being counted if they are still op (torctl/trunk/python/TorCtl)

mikeperry at seul.org mikeperry at seul.org
Sun Jan 4 17:56:41 UTC 2009


Author: mikeperry
Date: 2009-01-04 12:56:40 -0500 (Sun, 04 Jan 2009)
New Revision: 17880

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

Fix bug with circuits not being counted if they are still open when we finish
a speedrace run.



Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py	2009-01-04 15:43:07 UTC (rev 17879)
+++ torctl/trunk/python/TorCtl/PathSupport.py	2009-01-04 17:56:40 UTC (rev 17880)
@@ -900,7 +900,7 @@
     self.built = False
     self.failed = False
     self.dirty = False
-    self.closed = False
+    self.requested_closed = False
     self.detached_cnt = 0
     self.last_extended_at = time.time()
     self.extend_times = []      # List of all extend-durations
@@ -1055,6 +1055,21 @@
         e.g. for generating paths without actually creating any circuits """
     return self.selmgr.path_selector.build_path(self.selmgr.pathlen)
 
+  def close_all_circuits(self):
+    """ Close all open circuits """
+    for circ in self.circuits.itervalues():
+      self.close_circuit(circ.circ_id)
+
+  def close_circuit(self, id):
+    """ Close a circuit with given id """
+    # TODO: Pass streams to another circ before closing?
+    plog("DEBUG", "Requesting close of circuit id: "+str(id))
+    if self.circuits[id].requested_closed: return
+    self.circuits[id].requested_closed = True
+    try: self.c.close_circuit(id)
+    except TorCtl.ErrorReply, e: 
+      plog("ERROR", "Failed closing circuit " + str(id) + ": " + str(e))
+
   def attach_stream_any(self, stream, badcircs):
     "Attach a stream to a valid circuit, avoiding any in 'badcircs'"
     # Newnym, and warn if not built plus pending
@@ -1074,7 +1089,8 @@
         self.circuits[key].dirty = True
       
     for circ in self.circuits.itervalues():
-      if circ.built and not circ.dirty and circ.circ_id not in badcircs:
+      if circ.built and not circ.requested_closed and not circ.dirty \
+          and circ.circ_id not in badcircs:
         if circ.exit.will_exit_to(stream.host, stream.port):
           try:
             self.c.attach_stream(stream.strm_id, circ.circ_id)
@@ -1303,14 +1319,6 @@
         # we have gotten an NS event to notify us they disappeared?
         plog("NOTICE", "Error building circuit: " + str(e.args))
 
-  def close_circuit(self, id):
-    """ Close a circuit with given id """
-    # TODO: Pass streams to another circ before closing?
-    self.circuits[id].closed = True
-    try: self.c.close_circuit(id)
-    except TorCtl.ErrorReply, e: 
-      plog("ERROR", "Failed closing circuit " + str(id) + ": " + str(e))
-
   def circ_status_event(self, c):
     """ Handle circuit status events """
     output = [c.event_name, str(c.circ_id), c.status]
@@ -1425,7 +1433,8 @@
     else: list = self.circuits.values()
     for circ in list:
       # Check each circuit
-      if circ.built and not circ.closed and circ.circ_id not in badcircs and not circ.dirty:
+      if circ.built and not circ.requested_closed and circ.circ_id not in badcircs \
+         and not circ.dirty:
         if circ.exit.will_exit_to(stream.host, stream.port):
           try:
             self.c.attach_stream(stream.strm_id, circ.circ_id)

Modified: torctl/trunk/python/TorCtl/StatsSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/StatsSupport.py	2009-01-04 15:43:07 UTC (rev 17879)
+++ torctl/trunk/python/TorCtl/StatsSupport.py	2009-01-04 17:56:40 UTC (rev 17880)
@@ -495,6 +495,12 @@
     self.failed_reasons.clear()
     for r in self.sorted_r: r.reset()
 
+  def close_circuit(self, id):
+    PathSupport.PathBuilder.close_circuit(self, id)
+    for r in self.circuits[id].path:
+      r.circ_chosen += 1
+      r.circ_succeeded += 1
+
   def circ_status_event(self, c):
     if c.circ_id in self.circuits:
       # TODO: Hrmm, consider making this sane in TorCtl.
@@ -545,19 +551,21 @@
           self.suspect_reasons[reason].add_r(r)
       elif c.status == "CLOSED":
         # Since PathBuilder deletes the circuit on a failed, 
-        # we only get this for a clean close
-        for r in self.circuits[c.circ_id].path:
-          r.circ_chosen += 1
-          if lreason in ("REQUESTED", "FINISHED", "ORIGIN"):
-            r.circ_succeeded += 1
-          else:
-            if not reason in r.reason_suspected:
-              r.reason_suspected[reason] = 1
-            else: r.reason_suspected[reason] += 1
-            r.circ_suspected+= 1
-            if reason not in self.suspect_reasons:
-              self.suspect_reasons[reason] = SuspectRouterList(reason)
-            self.suspect_reasons[reason].add_r(r)
+        # we only get this for a clean close that was not
+        # requested by us
+        if not self.circuits[c.circ_id].requested_closed:
+          for r in self.circuits[c.circ_id].path:
+            r.circ_chosen += 1
+            if lreason in ("REQUESTED", "FINISHED", "ORIGIN"):
+              r.circ_succeeded += 1
+            else:
+              if not reason in r.reason_suspected:
+                r.reason_suspected[reason] = 1
+              else: r.reason_suspected[reason] += 1
+              r.circ_suspected+= 1
+              if reason not in self.suspect_reasons:
+                self.suspect_reasons[reason] = SuspectRouterList(reason)
+              self.suspect_reasons[reason].add_r(r)
     PathBuilder.circ_status_event(self, c)
 
   def count_stream_reason_failed(self, s, reason):

Modified: torctl/trunk/python/TorCtl/TorUtil.py
===================================================================
--- torctl/trunk/python/TorCtl/TorUtil.py	2009-01-04 15:43:07 UTC (rev 17879)
+++ torctl/trunk/python/TorCtl/TorUtil.py	2009-01-04 17:56:40 UTC (rev 17880)
@@ -22,10 +22,10 @@
 
 # TODO: Make functions to read these from a config file. This isn't
 # the right place for them either.. But at least it's unified.
-tor_port = 9050
+tor_port = 9060
 tor_host = '127.0.0.1'
 
-control_port = 9051
+control_port = 9061
 control_host = '127.0.0.1'
 control_pass = ""
 



More information about the tor-commits mailing list