diff options
author | George Kadianakis <desnacked@riseup.net> | 2013-02-26 12:43:53 +0200 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2013-02-26 12:43:53 +0200 |
commit | 05f8fd2878e1b85822c126c0206f8b8929556868 (patch) | |
tree | f654b803437a0e7b8e8bf5bfc04d2625f379000a /src/or/geoip.c | |
parent | 337e32f5b8f5f3b310da20bf0135f17d06efb3ab (diff) | |
download | tor-05f8fd2878e1b85822c126c0206f8b8929556868.tar.gz tor-05f8fd2878e1b85822c126c0206f8b8929556868.zip |
Add unique client counter to the heartbeat message.
Diffstat (limited to 'src/or/geoip.c')
-rw-r--r-- | src/or/geoip.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c index e2e98e8ec4..810070c474 100644 --- a/src/or/geoip.c +++ b/src/or/geoip.c @@ -1292,6 +1292,38 @@ format_bridge_stats_controller(time_t now) return out; } +/** Return a newly allocated string holding our bridge usage stats by + * country in a format suitable for inclusion in our heartbeat + * message. Return NULL on failure. */ +char * +format_client_stats_heartbeat(time_t now) +{ + char *out = NULL; + int n_clients = 0; + clientmap_entry_t **ent; + double elapsed_time = 0; + + if (!start_of_bridge_stats_interval) + return NULL; /* Not initialized. */ + + /* count unique IPs */ + HT_FOREACH(ent, clientmap, &client_history) { + /* only count directly connecting clients */ + if ((*ent)->action != GEOIP_CLIENT_CONNECT) + continue; + n_clients++; + } + + elapsed_time = difftime(now, start_of_bridge_stats_interval); + + tor_asprintf(&out, "Heartbeat: " + "Since the last %ld hours, I have seen %d unique clients.", + tor_lround(elapsed_time / 3600), + n_clients); + + return out; +} + /** Write bridge statistics to $DATADIR/stats/bridge-stats and return * when we should next try to write statistics. */ time_t |