diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/or/geoip.c | 33 | ||||
-rw-r--r-- | src/or/main.c | 1 | ||||
-rw-r--r-- | src/or/router.c | 14 |
3 files changed, 38 insertions, 10 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index 786c40e5b1..622b582173 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -388,6 +388,36 @@ geoip_note_client_seen(geoip_client_action_t action, return; } + /* As a bridge that doesn't rotate request periods every 24 hours, + * possibly rotate now. */ + if (options->BridgeRelay) { + while (current_request_period_starts + REQUEST_HIST_PERIOD < now) { + if (!geoip_countries) + geoip_countries = smartlist_create(); + if (!current_request_period_starts) { + current_request_period_starts = now; + break; + } + /* Also discard all items in the client history that are too old. + * (This only works here because bridge and directory stats are + * independent. Otherwise, we'd only want to discard those items + * with action GEOIP_CLIENT_NETWORKSTATUS{_V2}.) */ + geoip_remove_old_clients(current_request_period_starts); + /* Now rotate request period */ + SMARTLIST_FOREACH(geoip_countries, geoip_country_t *, c, { + memmove(&c->n_v2_ns_requests[0], &c->n_v2_ns_requests[1], + sizeof(uint32_t)*(REQUEST_HIST_LEN-1)); + memmove(&c->n_v3_ns_requests[0], &c->n_v3_ns_requests[1], + sizeof(uint32_t)*(REQUEST_HIST_LEN-1)); + c->n_v2_ns_requests[REQUEST_HIST_LEN-1] = 0; + c->n_v3_ns_requests[REQUEST_HIST_LEN-1] = 0; + }); + current_request_period_starts += REQUEST_HIST_PERIOD; + if (n_old_request_periods < REQUEST_HIST_LEN-1) + ++n_old_request_periods; + } + } + lookup.ipaddr = addr; lookup.action = (int)action; ent = HT_FIND(clientmap, &client_history, &lookup); @@ -949,7 +979,8 @@ geoip_dirreq_stats_write(time_t now) if (!out) goto done; if (fprintf(out, "dirreq-stats-end %s (%d s)\ndirreq-v3-ips %s\n" - "dirreq-v2-ips %s\n", written, REQUEST_HIST_PERIOD, + "dirreq-v2-ips %s\n", written, + (unsigned) (now - start_of_dirreq_stats_interval), data_v3 ? data_v3 : "", data_v2 ? data_v2 : "") < 0) goto done; tor_free(data_v2); diff --git a/src/or/main.c b/src/or/main.c index 16136cb27f..fb6b1ea0e7 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -962,7 +962,6 @@ run_scheduled_events(time_t now) */ if (time_to_write_stats_files >= 0 && time_to_write_stats_files < now) { #define WRITE_STATS_INTERVAL (24*60*60) - or_options_t *options = get_options(); if (options->CellStatistics || options->DirReqStatistics || options->EntryStatistics || options->ExitPortStatistics) { if (!time_to_write_stats_files) { diff --git a/src/or/router.c b/src/or/router.c index bb63dc205e..64267f242c 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -1847,18 +1847,18 @@ load_stats_file(const char *filename, const char *end_line, time_t after, if (start != contents) start++; /* Avoid infinite loops. */ if (!(start = strstr(start, end_line))) - goto err; - if (strlen(start) < strlen(end_line) + sizeof(timestr)) - goto err; + goto notfound; + if (strlen(start) < strlen(end_line) + 1 + sizeof(timestr)) + goto notfound; strlcpy(timestr, start + 1 + strlen(end_line), sizeof(timestr)); if (parse_iso_time(timestr, &written) < 0) - goto err; - } while (written < after); + goto notfound; + } while (written <= after); *out = tor_malloc(strlen(start)); strlcpy(*out, start, strlen(start)); r = 1; } - err: + notfound: tor_free(contents); break; case FN_NOENT: @@ -2011,8 +2011,6 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo, extrainfo_free(ei_tmp); } - log_info(LD_GENERAL, "Done with dumping our extra-info descriptor."); - return (int)strlen(s)+1; } |