diff options
author | Roger Dingledine <arma@torproject.org> | 2005-02-24 11:44:08 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2005-02-24 11:44:08 +0000 |
commit | 5b24ca6cde6ce596fc69899f7bed7a77663da484 (patch) | |
tree | 53894a691f61c9fd4a6fc3efdbbda68b9e49b3d1 /src/or | |
parent | 2ecd3ff709e6f3ee70ab82f892d6dd3bfb63c1df (diff) | |
download | tor-5b24ca6cde6ce596fc69899f7bed7a77663da484.tar.gz tor-5b24ca6cde6ce596fc69899f7bed7a77663da484.zip |
cache .exit address better (i think)
svn:r3684
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/connection_edge.c | 32 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/relay.c | 6 |
3 files changed, 29 insertions, 11 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 01d0630c6a..cfee2ac5e5 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -490,20 +490,35 @@ int client_dns_incr_failures(const char *address) /** Record the fact that <b>address</b> resolved to <b>val</b>. * We can now use this in subsequent streams via addressmap_rewrite() * so we can more correctly choose an exit that will allow <b>address</b>. + * + * If <b>exitname</b> is defined, then append the addresses with + * ".exitname.exit" before registering the mapping. */ -void client_dns_set_addressmap(const char *address, uint32_t val) +void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname) { struct in_addr in; - char *addr; + char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_HEX_NICKNAME_LEN+10]; + char valbuf[INET_NTOA_BUF_LEN]; + char extendedval[INET_NTOA_BUF_LEN+MAX_HEX_NICKNAME_LEN+10]; tor_assert(address); tor_assert(val); if (tor_inet_aton(address, &in)) return; /* If address was an IP address already, don't add a mapping. */ in.s_addr = htonl(val); - addr = tor_malloc(INET_NTOA_BUF_LEN); - tor_inet_ntoa(&in,addr,INET_NTOA_BUF_LEN); - addressmap_register(address, addr, + tor_inet_ntoa(&in,valbuf,sizeof(valbuf)); + if (exitname) { + tor_snprintf(extendedaddress, sizeof(extendedaddress), + "%s.%s.exit", address, exitname); + tor_snprintf(extendedval, sizeof(extendedval), + "%s.%s.exit", valbuf, exitname); + } else { + tor_snprintf(extendedaddress, sizeof(extendedaddress), + "%s", address); + tor_snprintf(extendedval, sizeof(extendedval), + "%s", valbuf); + } + addressmap_register(extendedaddress, tor_strdup(extendedval), time(NULL) + MAX_DNS_ENTRY_AGE); } @@ -754,8 +769,8 @@ int connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ) } string_addr = ap_conn->socks_request->address; - payload_len = strlen(string_addr); - tor_assert(strlen(string_addr) <= RELAY_PAYLOAD_SIZE); + payload_len = strlen(string_addr)+1; + tor_assert(payload_len <= RELAY_PAYLOAD_SIZE); log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",ap_conn->stream_id); @@ -840,7 +855,8 @@ void connection_ap_handshake_socks_resolved(connection_t *conn, if (answer_type == RESOLVED_TYPE_IPV4) { uint32_t a = get_uint32(answer); if (a) - client_dns_set_addressmap(conn->socks_request->address, ntohl(a)); + client_dns_set_addressmap(conn->socks_request->address, ntohl(a), + conn->chosen_exit_name); } if (conn->socks_request->socks_version == 4) { diff --git a/src/or/or.h b/src/or/or.h index 953d8ed24b..bcd8345d03 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1289,7 +1289,7 @@ void addressmap_rewrite(char *address, size_t maxlen); int addressmap_already_mapped(const char *address); void addressmap_register(const char *address, char *new_address, time_t expires); int client_dns_incr_failures(const char *address); -void client_dns_set_addressmap(const char *address, uint32_t val); +void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname); void parse_socks_policy(void); void free_socks_policy(void); diff --git a/src/or/relay.c b/src/or/relay.c index 4029823c85..866c3d8757 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -518,7 +518,8 @@ connection_edge_process_relay_cell_not_open( connection_mark_for_close(conn); return 0; } - client_dns_set_addressmap(conn->socks_request->address, addr); + client_dns_set_addressmap(conn->socks_request->address, addr, + conn->chosen_exit_name); /* check if he *ought* to have allowed it */ exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest); @@ -591,7 +592,8 @@ connection_edge_process_relay_cell_not_open( connection_mark_for_close(conn); return 0; } - client_dns_set_addressmap(conn->socks_request->address, addr); + client_dns_set_addressmap(conn->socks_request->address, addr, + conn->chosen_exit_name); } circuit_log_path(LOG_INFO,circ); connection_ap_handshake_socks_reply(conn, NULL, 0, 1); |