Backport: Several geoip changes/fixes as requested.

svn:r14782
This commit is contained in:
Nick Mathewson 2008-05-28 18:35:39 +00:00
parent b206123140
commit 1ffb56c4bd
4 changed files with 29 additions and 6 deletions

View File

@ -13,6 +13,10 @@ Changes in version 0.2.0.27-rc - 2008-05-??
fails do not leave it unattached and ask the controller to deal. Fixes
the second part of bug 681.
o Minor features:
- Allow comments in geoip file.
- Make bridge authorities never serve extrainfo docs.
o New files:
- A new contrib/tor-exit-notice.html file that exit relay operators
can put on their website to help reduce abuse queries.

View File

@ -2461,7 +2461,7 @@ directory_handle_command_get(dir_connection_t *conn, const char *headers,
}
if (!strcmpstart(url,"/tor/server/") ||
!strcmpstart(url,"/tor/extra/")) {
(!options->BridgeAuthoritativeDir && !strcmpstart(url,"/tor/extra/"))) {
int res;
const char *msg;
const char *request_type = NULL;

View File

@ -76,6 +76,10 @@ geoip_parse_entry(const char *line)
geoip_entries = smartlist_create();
country_idxplus1_by_lc_code = strmap_new();
}
while (TOR_ISSPACE(*line))
++line;
if (*line == '#')
return 0;
if (sscanf(line,"%u,%u,%2s", &low, &high, b) == 3) {
geoip_add_entry(low, high, b);
return 0;
@ -277,12 +281,12 @@ geoip_remove_old_clients(time_t cutoff)
}
/** Do not mention any country from which fewer than this number of IPs have
* connected. This avoids reporting information that could deanonymize
* users. */
#define MIN_IPS_TO_NOTE_COUNTRY 8
* connected. This conceivably avoids reporting information that could
* deanonymize users, though analysis is lacking. */
#define MIN_IPS_TO_NOTE_COUNTRY 0
/** Do not report any geoip data at all if we have fewer than this number of
* IPs to report about. */
#define MIN_IPS_TO_NOTE_ANYTHING 16
#define MIN_IPS_TO_NOTE_ANYTHING 0
/** When reporting geoip data about countries, round down to the nearest
* multiple of this value. */
#define IP_GRANULARITY 8
@ -344,8 +348,10 @@ geoip_get_client_history(time_t now)
++total;
}
/* Don't record anything if we haven't seen enough IPs. */
#if MIN_IPS_TO_NOTE_ANYTHING > 0
if (total < MIN_IPS_TO_NOTE_ANYTHING)
goto done;
#endif
/* Make a list of c_hist_t */
entries = smartlist_create();
for (i = 0; i < n_countries; ++i) {
@ -353,7 +359,11 @@ geoip_get_client_history(time_t now)
const char *countrycode;
c_hist_t *ent;
/* Only report a country if it has a minimum number of IPs. */
#if MIN_IPS_TO_NOTE_COUNTRY > 0
if (c >= MIN_IPS_TO_NOTE_COUNTRY) {
#else
if (1) {
#endif
/* Round up to the next multiple of IP_GRANULARITY */
c += IP_GRANULARITY-1;
c -= c % IP_GRANULARITY;
@ -375,7 +385,9 @@ geoip_get_client_history(time_t now)
smartlist_add(chunks, tor_strdup(buf));
});
result = smartlist_join_strings(chunks, ",", 0, NULL);
#if MIN_IPS_TO_NOTE_ANYTHING > 0
done:
#endif
tor_free(counts);
if (chunks) {
SMARTLIST_FOREACH(chunks, char *, c, tor_free(c));

View File

@ -1822,7 +1822,14 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo,
return -1;
if (options->BridgeRelay && options->BridgeRecordUsageByCountry) {
char *geoip_summary = geoip_get_client_history(time(NULL));
static time_t last_purged_at = 0;
char *geoip_summary;
time_t now = time(NULL);
if (now > last_purged_at+48*60*60) {
geoip_remove_old_clients(now-48*60*60);
last_purged_at = now;
}
geoip_summary = geoip_get_client_history(time(NULL));
if (geoip_summary) {
char geoip_start[ISO_TIME_LEN+1];
format_iso_time(geoip_start, geoip_get_history_start());