[or-cvs] r14207: Specifically parsing SOURCE and SOURCE_ADDR from stream even (torflow/trunk/TorCtl)

renner at seul.org renner at seul.org
Wed Mar 26 23:59:34 UTC 2008


Author: renner
Date: 2008-03-26 19:59:34 -0400 (Wed, 26 Mar 2008)
New Revision: 14207

Modified:
   torflow/trunk/TorCtl/PathSupport.py
   torflow/trunk/TorCtl/TorCtl.py
Log:
Specifically parsing SOURCE and SOURCE_ADDR from stream events for identifying Tor internal streams

Modified: torflow/trunk/TorCtl/PathSupport.py
===================================================================
--- torflow/trunk/TorCtl/PathSupport.py	2008-03-26 21:18:07 UTC (rev 14206)
+++ torflow/trunk/TorCtl/PathSupport.py	2008-03-26 23:59:34 UTC (rev 14207)
@@ -1213,7 +1213,7 @@
   def stream_status_event(self, s):
     """ Catch user stream events """
     # Construct debugging output
-    output = [s.event_name, str(s.strm_id), s.status, str(s.circ_id), s.target_host, str(s.target_port)]
+    output = [s.event_name, str(s.strm_id), s.status, str(s.circ_id), s.target_host+':'+str(s.target_port)]
     if s.reason: output.append("REASON=" + s.reason)
     if s.remote_reason: output.append("REMOTE_REASON=" + s.remote_reason)
     plog("DEBUG", " ".join(output))
@@ -1313,8 +1313,6 @@
     plog("DEBUG", " ".join(output))
 
   def unknown_event(self, event):
-    # XXX: Sometimes a strange event (or parsing error) is occuring 
-    # (event_name ='OK'?)
     plog("DEBUG", "UNKNOWN EVENT '" + event.event_name + "':" + 
        event.event_string)
 

Modified: torflow/trunk/TorCtl/TorCtl.py
===================================================================
--- torflow/trunk/TorCtl/TorCtl.py	2008-03-26 21:18:07 UTC (rev 14206)
+++ torflow/trunk/TorCtl/TorCtl.py	2008-03-26 23:59:34 UTC (rev 14207)
@@ -94,7 +94,7 @@
 
 class StreamEvent:
   def __init__(self, event_name, strm_id, status, circ_id, target_host,
-         target_port, reason, remote_reason):
+         target_port, reason, remote_reason, source, source_addr):
     self.event_name = event_name
     self.arrived_at = 0
     self.strm_id = strm_id
@@ -104,6 +104,8 @@
     self.target_port = int(target_port)
     self.reason = reason
     self.remote_reason = remote_reason
+    self.source = source
+    self.source_addr = source_addr
 
 class ORConnEvent:
   def __init__(self, event_name, status, endpoint, age, read_bytes,
@@ -780,18 +782,20 @@
         path = []
       if reason: reason = reason[8:]
       if remote: remote = remote[15:]
-      event = CircuitEvent(evtype, ident, status, path, reason,
-                     remote)
+      event = CircuitEvent(evtype, ident, status, path, reason, remote)
     elif evtype == "STREAM":
-      m = re.match(r"(\S+)\s+(\S+)\s+(\S+)\s+(\S+):(\d+)(\s\S+)?(\s\S+)?", body)
+      #plog("DEBUG", "STREAM: "+body)
+      m = re.match(r"(\S+)\s+(\S+)\s+(\S+)\s+(\S+):(\d+)(\sREASON=\S+)?(\sREMOTE_REASON=\S+)?(\sSOURCE=\S+)?(\sSOURCE_ADDR=\S+)?", body) 
       if not m:
         raise ProtocolError("STREAM event misformatted.")
-      ident,status,circ,target_host,target_port,reason,remote = m.groups()
+      ident,status,circ,target_host,target_port,reason,remote,source,source_addr = m.groups()
       ident,circ = map(int, (ident,circ))
       if reason: reason = reason[8:]
       if remote: remote = remote[15:]
+      if source: source = source[8:]
+      if source_addr: source_addr = source_addr[13:]
       event = StreamEvent(evtype, ident, status, circ, target_host,
-                    int(target_port), reason, remote)
+                    int(target_port), reason, remote, source, source_addr)
     elif evtype == "ORCONN":
       m = re.match(r"(\S+)\s+(\S+)(\sAGE=\S+)?(\sREAD=\S+)?(\sWRITTEN=\S+)?(\sREASON=\S+)?(\sNCIRCS=\S+)?", body)
       if not m:



More information about the tor-commits mailing list