diff options
author | George Kadianakis <desnacked@riseup.net> | 2013-06-27 18:27:44 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-08-15 12:03:34 -0400 |
commit | 6ad535e6dca8e9e284a0fa3384679756dca34a87 (patch) | |
tree | 2f2c9683348ca187248118b07b9dec2cf65fa80e /src | |
parent | cb54e44587473782c2865c3ea4aca6e0666943a8 (diff) | |
download | tor-6ad535e6dca8e9e284a0fa3384679756dca34a87.tar tor-6ad535e6dca8e9e284a0fa3384679756dca34a87.tar.gz |
If a single client connects with multiple transports, note all transports.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/geoip.c | 19 | ||||
-rw-r--r-- | src/test/test.c | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index 737512f62..866f6a79e 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -492,6 +492,19 @@ clientmap_entry_hash(const clientmap_entry_t *a) static INLINE int clientmap_entries_eq(const clientmap_entry_t *a, const clientmap_entry_t *b) { + /* If one entry contains a transport and the other doesn't, then + they are not equal. */ + if (a->transport_name && !b->transport_name) + return 0; + if (!a->transport_name && b->transport_name) + return 0; + /* If entries contain different transports, they they are not + equal. */ + if (a->transport_name && + b->transport_name && + strcmp(a->transport_name, b->transport_name)) + return 0; + return !tor_addr_compare(&a->addr, &b->addr, CMP_EXACT) && a->action == b->action; } @@ -529,6 +542,8 @@ geoip_note_client_seen(geoip_client_action_t action, { const or_options_t *options = get_options(); clientmap_entry_t lookup, *ent; + memset(&lookup, 0, sizeof(clientmap_entry_t)); + if (action == GEOIP_CLIENT_CONNECT) { /* Only remember statistics as entry guard or as bridge. */ if (!options->EntryStatistics && @@ -546,7 +561,11 @@ geoip_note_client_seen(geoip_client_action_t action, tor_addr_copy(&lookup.addr, addr); lookup.action = (int)action; + if (transport_name) + lookup.transport_name = tor_strdup(transport_name); ent = HT_FIND(clientmap, &client_history, &lookup); + tor_free(lookup.transport_name); + if (! ent) { ent = tor_malloc_zero(sizeof(clientmap_entry_t)); tor_addr_copy(&ent->addr, addr); diff --git a/src/test/test.c b/src/test/test.c index 822f93a15..e0c6772c2 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1944,10 +1944,15 @@ test_geoip_with_pt(void) geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, "entropy", now-7200); } + /* 2 connections from the same IP with two different transports. */ + SET_TEST_ADDRESS(++i); + geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, "fire", now-7200); + geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, "google", now-7200); + /* Test the transport history string. */ s = geoip_get_transport_history(); tor_assert(s); - test_streq(s, "<OR>=8,alpha=16,beta=8,charlie=16,ddr=136,entropy=8"); + test_streq(s, "<OR>=8,alpha=16,beta=8,charlie=16,ddr=136,entropy=8,fire=8,google=8"); /* Stop collecting entry statistics. */ geoip_entry_stats_term(); |