mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +01:00
Add transport information to the GeoIP database.
This commit is contained in:
parent
210210f219
commit
0ec4e5a698
@ -2379,7 +2379,8 @@ channel_do_open_actions(channel_t *chan)
|
|||||||
/* only report it to the geoip module if it's not a known router */
|
/* only report it to the geoip module if it's not a known router */
|
||||||
if (!router_get_by_id_digest(chan->identity_digest)) {
|
if (!router_get_by_id_digest(chan->identity_digest)) {
|
||||||
if (channel_get_addr_if_possible(chan, &remote_addr)) {
|
if (channel_get_addr_if_possible(chan, &remote_addr)) {
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &remote_addr,
|
/* XXXX 5040/4773 : Is this 'NULL' right? */
|
||||||
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &remote_addr, NULL,
|
||||||
now);
|
now);
|
||||||
}
|
}
|
||||||
/* Otherwise the underlying transport can't tell us this, so skip it */
|
/* Otherwise the underlying transport can't tell us this, so skip it */
|
||||||
|
@ -2966,7 +2966,9 @@ directory_handle_command_get(dir_connection_t *conn, const char *headers,
|
|||||||
tor_addr_t addr;
|
tor_addr_t addr;
|
||||||
if (tor_inet_aton((TO_CONN(conn))->address, &in)) {
|
if (tor_inet_aton((TO_CONN(conn))->address, &in)) {
|
||||||
tor_addr_from_ipv4h(&addr, ntohl(in.s_addr));
|
tor_addr_from_ipv4h(&addr, ntohl(in.s_addr));
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, time(NULL));
|
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS,
|
||||||
|
&addr, NULL,
|
||||||
|
time(NULL));
|
||||||
geoip_note_ns_response(GEOIP_SUCCESS);
|
geoip_note_ns_response(GEOIP_SUCCESS);
|
||||||
/* Note that a request for a network status has started, so that we
|
/* Note that a request for a network status has started, so that we
|
||||||
* can measure the download time later on. */
|
* can measure the download time later on. */
|
||||||
|
@ -461,6 +461,10 @@ geoip_db_digest(sa_family_t family)
|
|||||||
typedef struct clientmap_entry_t {
|
typedef struct clientmap_entry_t {
|
||||||
HT_ENTRY(clientmap_entry_t) node;
|
HT_ENTRY(clientmap_entry_t) node;
|
||||||
tor_addr_t addr;
|
tor_addr_t addr;
|
||||||
|
/* Name of pluggable transport used by this client. NULL if no
|
||||||
|
pluggable transport was used. */
|
||||||
|
char *transport_name;
|
||||||
|
|
||||||
/** Time when we last saw this IP address, in MINUTES since the epoch.
|
/** Time when we last saw this IP address, in MINUTES since the epoch.
|
||||||
*
|
*
|
||||||
* (This will run out of space around 4011 CE. If Tor is still in use around
|
* (This will run out of space around 4011 CE. If Tor is still in use around
|
||||||
@ -519,7 +523,9 @@ client_history_clear(void)
|
|||||||
* configured accordingly. */
|
* configured accordingly. */
|
||||||
void
|
void
|
||||||
geoip_note_client_seen(geoip_client_action_t action,
|
geoip_note_client_seen(geoip_client_action_t action,
|
||||||
const tor_addr_t *addr, time_t now)
|
const tor_addr_t *addr,
|
||||||
|
const char *transport_name,
|
||||||
|
time_t now)
|
||||||
{
|
{
|
||||||
const or_options_t *options = get_options();
|
const or_options_t *options = get_options();
|
||||||
clientmap_entry_t lookup, *ent;
|
clientmap_entry_t lookup, *ent;
|
||||||
@ -534,12 +540,18 @@ geoip_note_client_seen(geoip_client_action_t action,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_debug(LD_GENERAL, "Seen client from '%s' with transport '%s'.",
|
||||||
|
safe_str_client(fmt_addr((addr))),
|
||||||
|
transport_name ? transport_name : "<no transport>");
|
||||||
|
|
||||||
tor_addr_copy(&lookup.addr, addr);
|
tor_addr_copy(&lookup.addr, addr);
|
||||||
lookup.action = (int)action;
|
lookup.action = (int)action;
|
||||||
ent = HT_FIND(clientmap, &client_history, &lookup);
|
ent = HT_FIND(clientmap, &client_history, &lookup);
|
||||||
if (! ent) {
|
if (! ent) {
|
||||||
ent = tor_malloc_zero(sizeof(clientmap_entry_t));
|
ent = tor_malloc_zero(sizeof(clientmap_entry_t));
|
||||||
tor_addr_copy(&ent->addr, addr);
|
tor_addr_copy(&ent->addr, addr);
|
||||||
|
if (transport_name)
|
||||||
|
ent->transport_name = tor_strdup(transport_name);
|
||||||
ent->action = (int)action;
|
ent->action = (int)action;
|
||||||
HT_INSERT(clientmap, &client_history, ent);
|
HT_INSERT(clientmap, &client_history, ent);
|
||||||
}
|
}
|
||||||
@ -566,6 +578,7 @@ remove_old_client_helper_(struct clientmap_entry_t *ent, void *_cutoff)
|
|||||||
{
|
{
|
||||||
time_t cutoff = *(time_t*)_cutoff / 60;
|
time_t cutoff = *(time_t*)_cutoff / 60;
|
||||||
if (ent->last_seen_in_minutes < cutoff) {
|
if (ent->last_seen_in_minutes < cutoff) {
|
||||||
|
tor_free(ent->transport_name);
|
||||||
tor_free(ent);
|
tor_free(ent);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@ -1515,6 +1528,7 @@ geoip_free_all(void)
|
|||||||
for (ent = HT_START(clientmap, &client_history); ent != NULL; ent = next) {
|
for (ent = HT_START(clientmap, &client_history); ent != NULL; ent = next) {
|
||||||
this = *ent;
|
this = *ent;
|
||||||
next = HT_NEXT_RMV(clientmap, &client_history, ent);
|
next = HT_NEXT_RMV(clientmap, &client_history, ent);
|
||||||
|
tor_free(this->transport_name);
|
||||||
tor_free(this);
|
tor_free(this);
|
||||||
}
|
}
|
||||||
HT_CLEAR(clientmap, &client_history);
|
HT_CLEAR(clientmap, &client_history);
|
||||||
|
@ -29,7 +29,8 @@ const char *geoip_db_digest(sa_family_t family);
|
|||||||
country_t geoip_get_country(const char *countrycode);
|
country_t geoip_get_country(const char *countrycode);
|
||||||
|
|
||||||
void geoip_note_client_seen(geoip_client_action_t action,
|
void geoip_note_client_seen(geoip_client_action_t action,
|
||||||
const tor_addr_t *addr, time_t now);
|
const tor_addr_t *addr, const char *transport_name,
|
||||||
|
time_t now);
|
||||||
void geoip_remove_old_clients(time_t cutoff);
|
void geoip_remove_old_clients(time_t cutoff);
|
||||||
|
|
||||||
void geoip_note_ns_response(geoip_ns_response_t response);
|
void geoip_note_ns_response(geoip_ns_response_t response);
|
||||||
|
@ -1741,20 +1741,20 @@ test_geoip(void)
|
|||||||
/* Put 9 observations in AB... */
|
/* Put 9 observations in AB... */
|
||||||
for (i=32; i < 40; ++i) {
|
for (i=32; i < 40; ++i) {
|
||||||
SET_TEST_ADDRESS(i);
|
SET_TEST_ADDRESS(i);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now-7200);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now-7200);
|
||||||
}
|
}
|
||||||
SET_TEST_ADDRESS(225);
|
SET_TEST_ADDRESS(225);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now-7200);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now-7200);
|
||||||
/* and 3 observations in XY, several times. */
|
/* and 3 observations in XY, several times. */
|
||||||
for (j=0; j < 10; ++j)
|
for (j=0; j < 10; ++j)
|
||||||
for (i=52; i < 55; ++i) {
|
for (i=52; i < 55; ++i) {
|
||||||
SET_TEST_ADDRESS(i);
|
SET_TEST_ADDRESS(i);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now-3600);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now-3600);
|
||||||
}
|
}
|
||||||
/* and 17 observations in ZZ... */
|
/* and 17 observations in ZZ... */
|
||||||
for (i=110; i < 127; ++i) {
|
for (i=110; i < 127; ++i) {
|
||||||
SET_TEST_ADDRESS(i);
|
SET_TEST_ADDRESS(i);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now);
|
||||||
}
|
}
|
||||||
geoip_get_client_history(GEOIP_CLIENT_CONNECT, &s, &v);
|
geoip_get_client_history(GEOIP_CLIENT_CONNECT, &s, &v);
|
||||||
test_assert(s);
|
test_assert(s);
|
||||||
@ -1803,7 +1803,7 @@ test_geoip(void)
|
|||||||
/* Start testing dirreq statistics by making sure that we don't collect
|
/* Start testing dirreq statistics by making sure that we don't collect
|
||||||
* dirreq stats without initializing them. */
|
* dirreq stats without initializing them. */
|
||||||
SET_TEST_ADDRESS(100);
|
SET_TEST_ADDRESS(100);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now);
|
||||||
s = geoip_format_dirreq_stats(now + 86400);
|
s = geoip_format_dirreq_stats(now + 86400);
|
||||||
test_assert(!s);
|
test_assert(!s);
|
||||||
|
|
||||||
@ -1811,7 +1811,7 @@ test_geoip(void)
|
|||||||
* dirreq-stats history string. */
|
* dirreq-stats history string. */
|
||||||
geoip_dirreq_stats_init(now);
|
geoip_dirreq_stats_init(now);
|
||||||
SET_TEST_ADDRESS(100);
|
SET_TEST_ADDRESS(100);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now);
|
||||||
s = geoip_format_dirreq_stats(now + 86400);
|
s = geoip_format_dirreq_stats(now + 86400);
|
||||||
test_streq(dirreq_stats_1, s);
|
test_streq(dirreq_stats_1, s);
|
||||||
tor_free(s);
|
tor_free(s);
|
||||||
@ -1820,7 +1820,7 @@ test_geoip(void)
|
|||||||
* don't generate a history string. */
|
* don't generate a history string. */
|
||||||
geoip_dirreq_stats_term();
|
geoip_dirreq_stats_term();
|
||||||
SET_TEST_ADDRESS(101);
|
SET_TEST_ADDRESS(101);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now);
|
||||||
s = geoip_format_dirreq_stats(now + 86400);
|
s = geoip_format_dirreq_stats(now + 86400);
|
||||||
test_assert(!s);
|
test_assert(!s);
|
||||||
|
|
||||||
@ -1828,7 +1828,7 @@ test_geoip(void)
|
|||||||
* that we get an all empty history string. */
|
* that we get an all empty history string. */
|
||||||
geoip_dirreq_stats_init(now);
|
geoip_dirreq_stats_init(now);
|
||||||
SET_TEST_ADDRESS(100);
|
SET_TEST_ADDRESS(100);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now);
|
||||||
geoip_reset_dirreq_stats(now);
|
geoip_reset_dirreq_stats(now);
|
||||||
s = geoip_format_dirreq_stats(now + 86400);
|
s = geoip_format_dirreq_stats(now + 86400);
|
||||||
test_streq(dirreq_stats_2, s);
|
test_streq(dirreq_stats_2, s);
|
||||||
@ -1855,7 +1855,7 @@ test_geoip(void)
|
|||||||
/* Start testing entry statistics by making sure that we don't collect
|
/* Start testing entry statistics by making sure that we don't collect
|
||||||
* anything without initializing entry stats. */
|
* anything without initializing entry stats. */
|
||||||
SET_TEST_ADDRESS(100);
|
SET_TEST_ADDRESS(100);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now);
|
||||||
s = geoip_format_entry_stats(now + 86400);
|
s = geoip_format_entry_stats(now + 86400);
|
||||||
test_assert(!s);
|
test_assert(!s);
|
||||||
|
|
||||||
@ -1863,7 +1863,7 @@ test_geoip(void)
|
|||||||
* entry-stats history string. */
|
* entry-stats history string. */
|
||||||
geoip_entry_stats_init(now);
|
geoip_entry_stats_init(now);
|
||||||
SET_TEST_ADDRESS(100);
|
SET_TEST_ADDRESS(100);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now);
|
||||||
s = geoip_format_entry_stats(now + 86400);
|
s = geoip_format_entry_stats(now + 86400);
|
||||||
test_streq(entry_stats_1, s);
|
test_streq(entry_stats_1, s);
|
||||||
tor_free(s);
|
tor_free(s);
|
||||||
@ -1872,7 +1872,7 @@ test_geoip(void)
|
|||||||
* don't generate a history string. */
|
* don't generate a history string. */
|
||||||
geoip_entry_stats_term();
|
geoip_entry_stats_term();
|
||||||
SET_TEST_ADDRESS(101);
|
SET_TEST_ADDRESS(101);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now);
|
||||||
s = geoip_format_entry_stats(now + 86400);
|
s = geoip_format_entry_stats(now + 86400);
|
||||||
test_assert(!s);
|
test_assert(!s);
|
||||||
|
|
||||||
@ -1880,7 +1880,7 @@ test_geoip(void)
|
|||||||
* that we get an all empty history string. */
|
* that we get an all empty history string. */
|
||||||
geoip_entry_stats_init(now);
|
geoip_entry_stats_init(now);
|
||||||
SET_TEST_ADDRESS(100);
|
SET_TEST_ADDRESS(100);
|
||||||
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, now);
|
geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now);
|
||||||
geoip_reset_entry_stats(now);
|
geoip_reset_entry_stats(now);
|
||||||
s = geoip_format_entry_stats(now + 86400);
|
s = geoip_format_entry_stats(now + 86400);
|
||||||
test_streq(entry_stats_2, s);
|
test_streq(entry_stats_2, s);
|
||||||
|
Loading…
Reference in New Issue
Block a user