From d828915136af1aac50b94a4567584b3745b13f8a Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 17 Jun 2007 15:10:51 +0000 Subject: r13463@catbus: nickm | 2007-06-17 11:10:17 -0400 Add a SOURCE_ADDR field to STREAM NEW events so that controllers can match requests to applications. (Patch from Robert Hogan.) svn:r10639 --- ChangeLog | 4 ++++ doc/spec/control-spec.txt | 8 +++++++- src/or/control.c | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9e02d28f..782c04f3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,10 @@ Changes in version 0.2.0.3-alpha - 2007-??-?? - Fail quickly and (relatively) harmlessly if we generate a network status document that is somehow malformed. + o Minor features (controller): + - Add a SOURCE_ADDR field to STREAM NEW events so that controllers can + match requests to applications. (Patch from Robert Hogan.) + o Deprecated features: - RedirectExits is now deprecated. diff --git a/doc/spec/control-spec.txt b/doc/spec/control-spec.txt index 4886a4ba8..a0c989c76 100644 --- a/doc/spec/control-spec.txt +++ b/doc/spec/control-spec.txt @@ -835,7 +835,8 @@ $Id$ "650" SP "STREAM" SP StreamID SP StreamStatus SP CircID SP Target [SP "REASON=" Reason [ SP "REMOTE_REASON=" Reason ]] - [SP "SOURCE=" Source] CRLF + [SP "SOURCE=" Source] [ SP "SOURCE_ADDR=" Address ":" Port ] + CRLF StreamStatus = "NEW" / ; New request to connect @@ -879,6 +880,11 @@ $Id$ answer, and "EXIT" is given if the remote node we queried gave us the new address as a response. + The "SOURCE_ADDR" field is included with NEW and NEWRESOLVE events if + extended events are enabled. It indicates the address that requested + the connection, and can be (e.g.) used to look up the requesting + program. + 4.1.3. OR Connection status changed The syntax is: diff --git a/src/or/control.c b/src/or/control.c index 2683be198..0fc859ca1 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -425,7 +425,7 @@ get_escaped_string(const char *start, size_t in_len_max, * 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, ...) { @@ -2636,6 +2636,7 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp, 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 +2699,25 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp, break; } } + + if (tp == STREAM_EVENT_NEW) { + tor_snprintf(addrport_buf,sizeof(addrport_buf), "%sSOURCE_ADDR=%s:%d", + strlen(reason_buf) ? " " : "", + TO_CONN(conn)->address, TO_CONN(conn)->port ); + } else { + addrport_buf[0] = '\0'; + } + 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; -- cgit v1.2.3