diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-02-05 19:15:13 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-02-05 19:15:13 +0000 |
commit | 47ff0c7fc116a9f49c2a3a87928b38796a1e7c2f (patch) | |
tree | 89a8b2910465055591476d01520b54b3ad8a2fbf | |
parent | f02be02356a6cedcec2b01d5046e5d5cba0797ad (diff) | |
download | tor-47ff0c7fc116a9f49c2a3a87928b38796a1e7c2f.tar tor-47ff0c7fc116a9f49c2a3a87928b38796a1e7c2f.tar.gz |
r11641@catbus: nickm | 2007-02-05 13:59:26 -0500
Add a REMAP state to stream events so that controllers can learn exactly when the target address for a stream has changed. May help Vidalia resolve confusions related to bug 375.
svn:r9484
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | doc/spec/control-spec.txt | 1 | ||||
-rw-r--r-- | src/or/connection_edge.c | 12 | ||||
-rw-r--r-- | src/or/control.c | 1 | ||||
-rw-r--r-- | src/or/or.h | 5 | ||||
-rw-r--r-- | src/or/relay.c | 6 |
6 files changed, 19 insertions, 9 deletions
@@ -97,7 +97,8 @@ Changes in version 0.1.2.7-alpha - 2007-??-?? - Add a SOCKS_BAD_HOSTNAME client status event so controllers can learn when clients are sending malformed hostnames to Tor. - Clean up documentation for controller status events. - + - Add a REMAP status to stream events to note that a stream's address has + changed because of a cached address or a MapAddress directive. Changes in version 0.1.2.6-alpha - 2007-01-09 o Major bugfixes: diff --git a/doc/spec/control-spec.txt b/doc/spec/control-spec.txt index 51cc6db50..9fede97d1 100644 --- a/doc/spec/control-spec.txt +++ b/doc/spec/control-spec.txt @@ -832,6 +832,7 @@ $Id$ StreamStatus = "NEW" / ; New request to connect "NEWRESOLVE" / ; New request to resolve an address + "REMAP" / ; Address re-mapped to another "SENTCONNECT" / ; Sent a connect cell along a circuit "SENTRESOLVE" / ; Sent a resolve cell along a circuit "SUCCEEDED" / ; Received a reply; stream established diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index a994be15b..17feaf44b 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -682,9 +682,10 @@ addressmap_free_all(void) /** Look at address, and rewrite it until it doesn't want any * more rewrites; but don't get into an infinite loop. - * Don't write more than maxlen chars into address. + * Don't write more than maxlen chars into address. Return true if the + * address changed; false otherwise. */ -void +int addressmap_rewrite(char *address, size_t maxlen) { addressmap_entry_t *ent; @@ -695,7 +696,7 @@ addressmap_rewrite(char *address, size_t maxlen) ent = strmap_get(addressmap, address); if (!ent || !ent->new_address) - return; /* done, no rewrite needed */ + return (rewrites > 0); /* done, no rewrite needed */ cp = tor_strdup(escaped_safe_str(ent->new_address)); log_info(LD_APP, "Addressmap: rewriting %s to %s", @@ -707,6 +708,7 @@ addressmap_rewrite(char *address, size_t maxlen) "Loop detected: we've rewritten %s 16 times! Using it as-is.", escaped_safe_str(address)); /* it's fine to rewrite a rewrite, but don't loop forever */ + return 1; } /** If we have a cached reverse DNS entry for the address stored in the @@ -1216,7 +1218,9 @@ connection_ap_handshake_rewrite_and_attach(edge_connection_t *conn, } } else { /* For address map controls, remap the address */ - addressmap_rewrite(socks->address, sizeof(socks->address)); + if (addressmap_rewrite(socks->address, sizeof(socks->address))) { + control_event_stream_status(conn, STREAM_EVENT_REMAP, 0); + } } if (address_is_in_virtual_range(socks->address)) { diff --git a/src/or/control.c b/src/or/control.c index efff7019b..c7ee25b8c 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -3206,6 +3206,7 @@ control_event_stream_status(edge_connection_t *conn, stream_status_event_t tp, case STREAM_EVENT_NEW: status = "NEW"; break; case STREAM_EVENT_NEW_RESOLVE: status = "NEWRESOLVE"; break; case STREAM_EVENT_FAILED_RETRIABLE: status = "DETACHED"; break; + case STREAM_EVENT_REMAP: status = "REMAP"; break; default: log_warn(LD_BUG, "Unrecognized status code %d", (int)tp); return 0; diff --git a/src/or/or.h b/src/or/or.h index abdd62fd2..e9c46468f 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2208,7 +2208,7 @@ void addressmap_clean(time_t now); void addressmap_clear_configured(void); void addressmap_clear_transient(void); void addressmap_free_all(void); -void addressmap_rewrite(char *address, size_t maxlen); +int addressmap_rewrite(char *address, size_t maxlen); int addressmap_have_mapping(const char *address); void addressmap_register(const char *address, char *new_address, time_t expires); @@ -2272,7 +2272,8 @@ typedef enum stream_status_event_t { STREAM_EVENT_CLOSED = 4, STREAM_EVENT_NEW = 5, STREAM_EVENT_NEW_RESOLVE = 6, - STREAM_EVENT_FAILED_RETRIABLE = 7 + STREAM_EVENT_FAILED_RETRIABLE = 7, + STREAM_EVENT_REMAP = 8 } stream_status_event_t; typedef enum or_conn_status_event_t { diff --git a/src/or/relay.c b/src/or/relay.c index 1f0431f23..559d1f643 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -750,8 +750,10 @@ connection_edge_process_end_not_open( router_parse_addr_policy_from_string("reject *:*", -1); } /* rewrite it to an IP if we learned one. */ - addressmap_rewrite(conn->socks_request->address, - sizeof(conn->socks_request->address)); + if (addressmap_rewrite(conn->socks_request->address, + sizeof(conn->socks_request->address))) { + control_event_stream_status(conn, STREAM_EVENT_REMAP, 0); + } if (conn->_base.chosen_exit_optional) { /* stop wanting a specific exit */ conn->_base.chosen_exit_optional = 0; |