diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-12-18 14:16:41 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-12-18 14:16:41 -0500 |
commit | 7edae5898416dbd291d9e5e9f75e0b24153e73ea (patch) | |
tree | 36a53ab9ee4c2c5ebbaa9ae0301c8b3bf844beeb /src/or/router.c | |
parent | f711bc822156f07de92503e177fbde520f4b6335 (diff) | |
parent | 3a5a728d4a5490ac24819df54aca4a7d0dde0d10 (diff) | |
download | tor-7edae5898416dbd291d9e5e9f75e0b24153e73ea.tar.gz tor-7edae5898416dbd291d9e5e9f75e0b24153e73ea.zip |
Merge commit 'karsten/fix-bridge-stats-master-4'
Diffstat (limited to 'src/or/router.c')
-rw-r--r-- | src/or/router.c | 50 |
1 files changed, 12 insertions, 38 deletions
diff --git a/src/or/router.c b/src/or/router.c index 8b6d1d9bbd..e14f237728 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -1660,7 +1660,7 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, return -1; } - /* PEM-encode the identity key key */ + /* PEM-encode the identity key */ if (crypto_pk_write_public_key_to_string(router->identity_pkey, &identity_pkey,&identity_pkeylen)<0) { log_warn(LD_BUG,"write identity_pkey to string failed!"); @@ -1882,6 +1882,7 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo, int result; size_t len; static int write_stats_to_extrainfo = 1; + time_t now = time(NULL); base16_encode(identity, sizeof(identity), extrainfo->cache_info.identity_digest, DIGEST_LEN); @@ -1896,7 +1897,6 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo, if (options->ExtraInfoStatistics && write_stats_to_extrainfo) { char *contents = NULL; - time_t now = time(NULL); log_info(LD_GENERAL, "Adding stats to extra-info descriptor."); if (options->DirReqStatistics && load_stats_file("stats"PATH_SEPARATOR"dirreq-stats", @@ -1953,18 +1953,16 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo, return -1; if (should_record_bridge_info(options)) { - char *geoip_summary = extrainfo_get_client_geoip_summary(time(NULL)); - if (geoip_summary) { - char geoip_start[ISO_TIME_LEN+1]; - format_iso_time(geoip_start, geoip_get_history_start()); - result = tor_snprintf(s+strlen(s), maxlen-strlen(s), - "geoip-start-time %s\n" - "geoip-client-origins %s\n", - geoip_start, geoip_summary); - control_event_clients_seen(geoip_start, geoip_summary); - tor_free(geoip_summary); - if (result<0) - return -1; + char *bridge_stats = geoip_get_bridge_stats_extrainfo(now); + if (bridge_stats) { + size_t pos = strlen(s); + if (strlcpy(s + pos, bridge_stats, maxlen - strlen(s)) != + strlen(bridge_stats)) { + log_warn(LD_DIR, "Could not write bridge-stats to extra-info " + "descriptor."); + s[pos] = '\0'; + } + tor_free(bridge_stats); } } @@ -2013,30 +2011,6 @@ extrainfo_dump_to_string(char *s, size_t maxlen, extrainfo_t *extrainfo, return (int)strlen(s)+1; } -/** Wrapper function for geoip_get_client_history(). It first discards - * any items in the client history that are too old -- it dumps anything - * more than 48 hours old, but it only considers whether to dump at most - * once per 48 hours, so we aren't too precise to an observer (see also - * r14780). - */ -char * -extrainfo_get_client_geoip_summary(time_t now) -{ - static time_t last_purged_at = 0; - int geoip_purge_interval = - (get_options()->DirReqStatistics || get_options()->EntryStatistics) ? - DIR_ENTRY_RECORD_USAGE_RETAIN_IPS : 48*60*60; - if (now > last_purged_at+geoip_purge_interval) { - /* (Note that this also discards items in the client history with - * action GEOIP_CLIENT_NETWORKSTATUS{_V2}, which doesn't matter - * because bridge and directory stats are independent. Keep in mind - * for future extensions, though.) */ - geoip_remove_old_clients(now-geoip_purge_interval); - last_purged_at = now; - } - return geoip_get_client_history_bridge(now, GEOIP_CLIENT_CONNECT); -} - /** Return true iff <b>s</b> is a legally valid server nickname. */ int is_legal_nickname(const char *s) |