diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2009-07-10 13:37:25 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2009-07-14 01:46:17 +0200 |
commit | 59dd9de8581c0cf0a0bd572f8d67b1be2b2a4274 (patch) | |
tree | 15f13cbb58042225fbf9a539cc9918cb3c92fcd2 /src/or/geoip.c | |
parent | 8f1a973669284e5662bd6f23bc96ecfafa57c554 (diff) | |
download | tor-59dd9de8581c0cf0a0bd572f8d67b1be2b2a4274.tar.gz tor-59dd9de8581c0cf0a0bd572f8d67b1be2b2a4274.zip |
Write number of rejected requests to geoip-stats file.
Diffstat (limited to 'src/or/geoip.c')
-rw-r--r-- | src/or/geoip.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index aac4893117..0a0fc08f84 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -418,6 +418,43 @@ geoip_remove_old_clients(time_t cutoff) client_history_starts = cutoff; } +#ifdef ENABLE_GEOIP_STATS +/** How many responses are we giving to clients requesting v2 network + * statuses? */ +static uint32_t ns_v2_responses[GEOIP_NS_RESPONSE_NUM]; + +/** How many responses are we giving to clients requesting v3 network + * statuses? */ +static uint32_t ns_v3_responses[GEOIP_NS_RESPONSE_NUM]; +#endif + +/** Note that we've rejected a client's request for a v2 or v3 network + * status, encoded in <b>action</b> for reason <b>reason</b> at time + * <b>now</b>. */ +void +geoip_note_ns_response(geoip_client_action_t action, + geoip_ns_response_t response) +{ +#ifdef ENABLE_GEOIP_STATS + static int arrays_initialized = 0; + if (!arrays_initialized) { + memset(ns_v2_responses, 0, sizeof(ns_v2_responses)); + memset(ns_v3_responses, 0, sizeof(ns_v3_responses)); + arrays_initialized = 1; + } + tor_assert(action == GEOIP_CLIENT_NETWORKSTATUS || + action == GEOIP_CLIENT_NETWORKSTATUS_V2); + tor_assert(response < GEOIP_NS_RESPONSE_NUM); + if (action == GEOIP_CLIENT_NETWORKSTATUS) + ns_v3_responses[response]++; + else + ns_v2_responses[response]++; +#else + (void) action; + (void) response; +#endif +} + /** Do not mention any country from which fewer than this number of IPs have * connected. This conceivably avoids reporting information that could * deanonymize users, though analysis is lacking. */ @@ -612,6 +649,7 @@ dump_geoip_stats(void) open_file_t *open_file = NULL; double v2_share = 0.0, v3_share = 0.0; FILE *out; + int i; data_v2 = geoip_get_client_history(now, GEOIP_CLIENT_NETWORKSTATUS_V2); data_v3 = geoip_get_client_history(now, GEOIP_CLIENT_NETWORKSTATUS); @@ -637,6 +675,33 @@ dump_geoip_stats(void) since, data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0) goto done; +#define RESPONSE_GRANULARITY 8 + for (i = 0; i < GEOIP_NS_RESPONSE_NUM; i++) { + ns_v2_responses[i] = round_to_next_multiple_of(ns_v2_responses[i], + RESPONSE_GRANULARITY); + ns_v3_responses[i] = round_to_next_multiple_of(ns_v3_responses[i], + RESPONSE_GRANULARITY); + } +#undef RESPONSE_GRANULARITY + if (fprintf(out, "n-ns-resp ok=%d,not-enough-sigs=%d,unavailable=%d," + "not-found=%d,not-modified=%d,busy=%d\n", + ns_v3_responses[GEOIP_SUCCESS], + ns_v3_responses[GEOIP_REJECT_NOT_ENOUGH_SIGS], + ns_v3_responses[GEOIP_REJECT_UNAVAILABLE], + ns_v3_responses[GEOIP_REJECT_NOT_FOUND], + ns_v3_responses[GEOIP_REJECT_NOT_MODIFIED], + ns_v3_responses[GEOIP_REJECT_BUSY]) < 0) + goto done; + if (fprintf(out, "n-v2-ns-resp ok=%d,unavailable=%d," + "not-found=%d,not-modified=%d,busy=%d\n", + ns_v2_responses[GEOIP_SUCCESS], + ns_v2_responses[GEOIP_REJECT_UNAVAILABLE], + ns_v2_responses[GEOIP_REJECT_NOT_FOUND], + ns_v2_responses[GEOIP_REJECT_NOT_MODIFIED], + ns_v2_responses[GEOIP_REJECT_BUSY]) < 0) + goto done; + memset(ns_v2_responses, 0, sizeof(ns_v2_responses)); + memset(ns_v3_responses, 0, sizeof(ns_v3_responses)); if (!router_get_my_share_of_directory_requests(&v2_share, &v3_share)) { if (fprintf(out, "v2-ns-share %0.2lf%%\n", v2_share*100) < 0) goto done; |