diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2009-08-21 23:02:36 +0200 |
---|---|---|
committer | Karsten Loesing <karsten.loesing@gmx.net> | 2009-08-21 23:02:36 +0200 |
commit | 8c29b7920ae18a46ce0527806507275783d1ae42 (patch) | |
tree | 0ff5936969a5b1b831686d1af5fbcff968dd915f /src/or/geoip.c | |
parent | 75c59d1a92e0f4956bd249844c188c432aae1712 (diff) | |
download | tor-8c29b7920ae18a46ce0527806507275783d1ae42.tar.gz tor-8c29b7920ae18a46ce0527806507275783d1ae42.zip |
Add some fixes after discussion with Nick.
- Refactor geoip.c by moving duplicate code into rotate_request_period().
- Don't leak memory when cleaning up cell queues.
- Make sure that exit_(streams|bytes_(read|written)) are initialized in all
places accessing these arrays.
- Read only the last block from *stats files and ensure that its timestamp
is not more than 25 hours in the past and not more than 1 hour in the
future.
- Stop truncating the last character when reading *stats files.
The only thing that's left now is to avoid reading whole *stats files into
memory.
Diffstat (limited to 'src/or/geoip.c')
-rw-r--r-- | src/or/geoip.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index 622b582173..247e16cff3 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -365,6 +365,23 @@ geoip_get_mean_shares(time_t now, double *v2_share_out, return 0; } +/* Rotate period of v2 and v3 network status requests. */ +static void +rotate_request_period(void) +{ + 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; +} + /** Note that we've seen a client connect from the IP <b>addr</b> (host order) * at time <b>now</b>. Ignored by all but bridges and directories if * configured accordingly. */ @@ -404,17 +421,7 @@ geoip_note_client_seen(geoip_client_action_t action, * 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; + rotate_request_period(); } } @@ -1046,17 +1053,7 @@ geoip_dirreq_stats_write(time_t now) open_file = NULL; /* 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; + rotate_request_period(); start_of_dirreq_stats_interval = now; |