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

STREAM_PORT Controller Event



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.


Rob
-- 

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 10615)
+++ src/or/control.c	(working copy)
@@ -43,7 +43,8 @@
 #define EVENT_STATUS_GENERAL   0x0012
 #define EVENT_GUARD            0x0013
 #define EVENT_STREAM_BANDWIDTH_USED   0x0014
-#define _EVENT_MAX             0x0014
+#define EVENT_STREAM_PORT_USED   0x0015
+#define _EVENT_MAX             0x0015
 /* If _EVENT_MAX ever hits 0x0020, we need to make the mask wider. */
 
 /** Bitfield: The bit 1&lt;&lt;e is set if <b>any</b> open control
@@ -894,6 +895,8 @@
         event_code = EVENT_GUARD;
       } else if (!strcasecmp(ev, "STREAM_BW"))
         event_code = EVENT_STREAM_BANDWIDTH_USED;
+      else if (!strcasecmp(ev, "STREAM_PORT"))
+        event_code = EVENT_STREAM_PORT_USED;
       else {
         connection_printf_to_buf(conn, "552 Unrecognized event \"%s\"\r\n",
                                  ev);
@@ -2709,6 +2712,11 @@
                         buf, reason_buf);
   /* XXX need to specify its intended exit, etc? */
 
+  if (tp == STREAM_EVENT_NEW){
+    if (EVENT_IS_INTERESTING(EVENT_STREAM_PORT_USED))
+        control_event_stream_port_used(conn);
+  }
+
   return 0;
 }
 
@@ -2879,6 +2887,19 @@
   return 0;
 }
 
+/** A new stream has been opened: tell any interested control
+ * connections the socket of the ap connection associated with the stream. */
+int
+control_event_stream_port_used(edge_connection_t *edge_conn)
+{
+  send_control_event(EVENT_STREAM_PORT_USED, ALL_NAMES,
+                            "650 STREAM_PORT %lu %lu \r\n",
+                            (unsigned long)edge_conn->global_identifier,
+                            (unsigned long)TO_CONN(edge_conn)->port);
+
+  return 0;
+}
+
 /** A second or more has elapsed: tell any interested control
  * connections how much bandwidth we used. */
 int
Index: src/or/or.h
===================================================================
--- src/or/or.h	(revision 10615)
+++ src/or/or.h	(working copy)
@@ -2610,6 +2610,7 @@
                                  or_conn_status_event_t e, int reason);
 int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
 int control_event_stream_bandwidth_used(void);
+int control_event_stream_port_used(edge_connection_t *conn);
 void control_event_logmsg(int severity, unsigned int domain, const char *msg);
 int control_event_descriptors_changed(smartlist_t *routers);
 int control_event_address_mapped(const char *from, const char *to,
Index: src/or/connection.c
===================================================================
--- src/or/connection.c	(revision 10615)
+++ src/or/connection.c	(working copy)
@@ -1655,6 +1655,8 @@
   /* refill the per-connection buckets */
   SMARTLIST_FOREACH(conns, connection_t *, conn,
   {
+
+
     if (connection_speaks_cells(conn)) {
       or_connection_t *or_conn = TO_OR_CONN(conn);
       if (connection_read_bucket_should_increase(or_conn)) {