[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r18528: {torctl} Handle NoNodesRemain exception by killing the stream and cle (torctl/trunk/python/TorCtl)



Author: mikeperry
Date: 2009-02-13 06:57:23 -0500 (Fri, 13 Feb 2009)
New Revision: 18528

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


Handle NoNodesRemain exception by killing the stream and
clearing the last_exit, so the metatroller+soat can get a
clue they requested the impossible.



Modified: torctl/trunk/python/TorCtl/PathSupport.py
===================================================================
--- torctl/trunk/python/TorCtl/PathSupport.py	2009-02-13 11:28:01 UTC (rev 18527)
+++ torctl/trunk/python/TorCtl/PathSupport.py	2009-02-13 11:57:23 UTC (rev 18528)
@@ -160,7 +160,7 @@
     "Rewind the generator to the 'beginning'"
     self.routers = copy.copy(self.rstr_routers)
     if not self.routers:
-      plog("ERROR", "No routers left after restrictions applied: "+str(self.rstr_list))
+      plog("WARN", "No routers left after restrictions applied: "+str(self.rstr_list))
       raise NoNodesRemain()
  
   def rebuild(self, sorted_r=None):
@@ -170,7 +170,7 @@
       self.sorted_r = sorted_r
     self.rstr_routers = filter(lambda r: self.rstr_list.r_is_ok(r), self.sorted_r)
     if not self.rstr_routers:
-      plog("ERROR", "No routers left after restrictions applied: "+str(self.rstr_list))
+      plog("WARN", "No routers left after restrictions applied: "+str(self.rstr_list))
       raise NoNodesRemain()
 
   def mark_chosen(self, r):
@@ -1212,7 +1212,14 @@
           break
     else:
       circ = None
-      self.selmgr.set_target(stream.host, stream.port)
+      try:
+        self.selmgr.set_target(stream.host, stream.port)
+      except NoNodesRemain:
+        self.last_exit = None
+        # Kill this stream
+        plog("NOTICE", "Closing stream "+str(stream.strm_id))
+        self.c.close_stream(stream.strm_id)
+        return
       while circ == None:
         try:
           circ = self.c.build_circuit(

Modified: torctl/trunk/python/TorCtl/TorUtil.py
===================================================================
--- torctl/trunk/python/TorCtl/TorUtil.py	2009-02-13 11:28:01 UTC (rev 18527)
+++ torctl/trunk/python/TorCtl/TorUtil.py	2009-02-13 11:57:23 UTC (rev 18528)
@@ -18,7 +18,7 @@
 
 __all__ = ["Enum", "Enum2", "Callable", "sort_list", "quote", "escape_dots", "unescape_dots",
       "BufSock", "secret_to_key", "urandom_rng", "s2k_gen", "s2k_check", "plog", 
-     "ListenSocket", "zprob"]
+     "ListenSocket", "zprob", "logfile", "loglevel"]
 
 # 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.
@@ -209,12 +209,17 @@
 ## XXX: Make this a class?
 loglevel = "DEBUG"
 loglevels = {"DEBUG" : 0, "INFO" : 1, "NOTICE" : 2, "WARN" : 3, "ERROR" : 4}
+logfile=None
 
 def plog(level, msg): # XXX: Timestamps
   if(loglevels[level] >= loglevels[loglevel]):
     t = time.strftime("%a %b %d %H:%M:%S %Y")
-    print level, '[', t, ']:', msg
-    sys.stdout.flush()
+    if logfile:
+      logfile.write(level+'['+t+']:'+msg+"\n")
+      logfile.flush()
+    else:
+      print level, '[', t, ']:', msg
+      sys.stdout.flush()
 
 # Stolen from
 # http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python/stats.py