[or-cvs] r20513: {torflow} Make soat use new stream filtering code to allow us to paral (in torflow/trunk/NetworkScanners/ExitAuthority: . data)

mikeperry at seul.org mikeperry at seul.org
Wed Sep 9 08:17:51 UTC 2009


Author: mikeperry
Date: 2009-09-09 04:17:51 -0400 (Wed, 09 Sep 2009)
New Revision: 20513

Modified:
   torflow/trunk/NetworkScanners/ExitAuthority/data/torrc
   torflow/trunk/NetworkScanners/ExitAuthority/soat.py
Log:

Make soat use new stream filtering code to allow us
to parallelize multiple soat scanners at once
using the same tor instance.



Modified: torflow/trunk/NetworkScanners/ExitAuthority/data/torrc
===================================================================
--- torflow/trunk/NetworkScanners/ExitAuthority/data/torrc	2009-09-09 08:15:07 UTC (rev 20512)
+++ torflow/trunk/NetworkScanners/ExitAuthority/data/torrc	2009-09-09 08:17:51 UTC (rev 20513)
@@ -2,8 +2,9 @@
 SocksPort 9210 # what port to advertise for application connections
 ControlPort 9211
 SafeLogging 0
-Log notice file ./data/tor.log
+Log info file ./data/tor.log
 DataDirectory ./data/tor-data
 PidFile ./data/tor.pid
 CookieAuthentication 1
 FetchUselessDescriptors 1
+__LeaveStreamsUnattached 1

Modified: torflow/trunk/NetworkScanners/ExitAuthority/soat.py
===================================================================
--- torflow/trunk/NetworkScanners/ExitAuthority/soat.py	2009-09-09 08:15:07 UTC (rev 20512)
+++ torflow/trunk/NetworkScanners/ExitAuthority/soat.py	2009-09-09 08:17:51 UTC (rev 20513)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 #
 # 2008 Aleksei Gorny, mentored by Mike Perry
+# 2009 Mike Perry
 
 '''
 Snakes on a Tor exit node scanner
@@ -47,6 +48,7 @@
 import threading
 import atexit
 
+
 sys.path.append("../../")
 
 from libsoat import *
@@ -59,13 +61,20 @@
 import OpenSSL
 from OpenSSL import *
 
+from soat_config import *
 
+
 sys.path.append("../libs/")
+
+# Make our SocksiPy use our socket
+__origsocket = socket.socket
+socket.socket = PathSupport.SmartSocket
+from SocksiPy import socks
+socket.socket = __origsocket
+
 from BeautifulSoup.BeautifulSoup import SoupStrainer, Tag
-from SocksiPy import socks
 import Pyssh.pyssh
 
-from soat_config import *
 
 # XXX: really need to standardize on $idhex or idhex :(
 # The convention in TorCtl is that nicks have no $, and ids have $.
@@ -112,8 +121,9 @@
     if BindingSocket.bind_to:
       plog("DEBUG", "Binding socket to "+BindingSocket.bind_to)
       self.bind((BindingSocket.bind_to, 0))
-socket.socket = BindingSocket 
+socket.socket = BindingSocket
 
+
 # Nice.. HTTPConnection.connect is doing DNS for us! Fix that:
 # Hrmm.. suppose we could also bind here.. but BindingSocket is 
 # more general and may come in handy for other tests.
@@ -139,8 +149,9 @@
     return self.do_open(NoDNSHTTPConnection, req)
 
 class ExitScanHandler(ScanSupport.ScanHandler):
-  def __init__(self, c, selmgr):
-    ScanSupport.ScanHandler.__init__(self, c, selmgr)
+  def __init__(self, c, selmgr, strm_selector):
+    ScanSupport.ScanHandler.__init__(self, c, selmgr,
+                                     strm_selector=strm_selector)
     self.rlock = threading.Lock()
     self.new_nodes=True
 
@@ -1014,6 +1025,7 @@
     psha1sum = sha.sha(pcontent)
 
     # reset the connection to direct
+    PathSupport.SmartSocket.clear_port_table()
     socket.socket = defaultsocket
 
     exit_node = scanhdlr.get_exit_node()
@@ -1807,6 +1819,7 @@
     (code, cert, exc) = self.ssl_request(address)
 
     # reset the connection method back to direct
+    PathSupport.SmartSocket.clear_port_table()
     socket.socket = defaultsocket
 
     exit_node = scanhdlr.get_exit_node()
@@ -2554,10 +2567,10 @@
   pass
 
 
-def cleanup(c, f):
+def cleanup(c, l, f):
   plog("INFO", "Resetting __LeaveStreamsUnattached=0 and FetchUselessDescriptors="+f)
   try:
-    c.set_option("__LeaveStreamsUnattached", "0")
+    c.set_option("__LeaveStreamsUnattached", l)
     c.set_option("FetchUselessDescriptors", f)
   except TorCtl.TorCtlClosed:
     pass
@@ -2569,8 +2582,8 @@
   c = PathSupport.Connection(s)
   c.debug(file(out_dir+"/control.log", "w", buffering=0))
   c.authenticate_cookie(file(cookie_file, "r"))
-  #f = c.get_option("__LeaveStreamsUnattached")[0]
-  h = ExitScanHandler(c, __selmgr)
+  l = c.get_option("__LeaveStreamsUnattached")[0]
+  h = ExitScanHandler(c, __selmgr, PathSupport.SmartSocket.StreamSelector)
 
   c.set_event_handler(h)
   #c.set_periodic_timer(2.0, "PULSE")
@@ -2585,7 +2598,7 @@
   c.set_option("__LeaveStreamsUnattached", "1")
   f = c.get_option("FetchUselessDescriptors")[0][1]
   c.set_option("FetchUselessDescriptors", "1")
-  atexit.register(cleanup, *(c, f))
+  atexit.register(cleanup, *(c, l, f))
   return (c,h)
 
 



More information about the tor-commits mailing list