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

Re: STREAM_PORT Controller Event



On Saturday 16 June 2007 21:18:13 Nick Mathewson wrote:
> On Sat, Jun 16, 2007 at 06:22:01PM +0100, Robert Hogan wrote:
> > This patch implements a controller event that tells interested contollers
> > the remote address's port for every new stream.
> >
> > This information allows controllers to look up and report the program
> > using that stream. On Linux, this is done by searching /proc/$PID/fd/*
> > for the inode reported in /proc/net/tcp.
>
> Hi, Robert!  I like the idea; just a few suggestions:
>
> 1) why not change this from a new event type to an an extra value
> given for STREAM NEW events when the EXTENDED_EVENTS flag is set?
> That's what it's for: adding new information to existing events[*].
> The syntax could be:
>
>       "650" SP "STREAM" SP StreamID SP StreamStatus SP CircID SP Target
>           [SP "REASON=" Reason [ SP "REMOTE_REASON=" Reason ]]
>           [SP "SOURCE=" Source] [ SP "SOURCE_ADDR=" Addr:Port ] CRLF
>
> 2) I'd suggest having the whole address, not just the port.  Usually
> the address will just be 127.0.0.1, but if people are running Tor as a
> socks proxy for their LAN, they'll want to see which host is using it.
>
> [*]  This could be explained better in control-spec.txt.  The idea is
> that if you specify EXTENDED_EVENTS, you're telling Tor that it is
> allowed to send you any number of unexpected Key=Value pairs after any
> event it sends you.  This is how we try to make events extensible
> without breaking backward compatibility.
>
> yrs,

Hi Nick,

That's a much better idea. Patch attached. The extension format in the 
control-spec hasn't been implemented yet (so far as I can tell) so I've gone 
along with the current method. Am I right on this? If so, would you like 
someone to do it?

At the moment, extended events get displayed regardless of the controller 
directive. There's a one-liner in the patch to fix that.

Regards
Robert


-- 

Browse Anonymously Anywhere	- http://anonymityanywhere.com
TorK	- KDE Anonymity Manager	- http://tork.sf.net
KlamAV	- KDE Anti-Virus 	- http://www.klamav.net

Index: src/or/control.c
===================================================================
--- src/or/control.c	(revision 10632)
+++ src/or/control.c	(working copy)
@@ -425,7 +425,7 @@
  * but it will always end with a CRLF sequence.
  *
  * Currently the length of the message is limited to 1024 (including the
- * ending \n\r\0. */
+ * ending \r\n\0. */
 static void
 connection_printf_to_buf(control_connection_t *conn, const char *format, ...)
 {
@@ -907,8 +907,7 @@
   smartlist_free(events);
 
   conn->event_mask = event_mask;
-  if (extended)
-    conn->use_extended_events = 1;
+  conn->use_extended_events = extended;
 
   control_update_global_event_mask();
   send_control_done(conn);
@@ -2636,6 +2635,7 @@
                             int reason_code)
 {
   char reason_buf[64];
+  char addrport_buf[64];
   const char *status;
   circuit_t *circ;
   origin_circuit_t *origin_circ = NULL;
@@ -2698,15 +2698,20 @@
       break;
     }
   }
+
+  tor_snprintf(addrport_buf,sizeof(addrport_buf), "%sSOURCE_ADDR=%s:%d",
+                   reason_code ? " " : "", TO_CONN(conn)->address, TO_CONN(conn)->port );
+
   circ = circuit_get_by_edge_conn(conn);
   if (circ && CIRCUIT_IS_ORIGIN(circ))
     origin_circ = TO_ORIGIN_CIRCUIT(circ);
   send_control_event_extended(EVENT_STREAM_STATUS, ALL_NAMES,
-                        "650 STREAM %lu %s %lu %s@%s\r\n",
+                        "650 STREAM %lu %s %lu %s@%s%s\r\n",
                         (unsigned long)conn->global_identifier, status,
                         origin_circ?
                            (unsigned long)origin_circ->global_identifier : 0ul,
-                        buf, reason_buf);
+                        buf, reason_buf, addrport_buf);
+
   /* XXX need to specify its intended exit, etc? */
 
   return 0;