summaryrefslogtreecommitdiff
path: root/src/or/geoip.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-02-03 13:06:58 -0500
committerNick Mathewson <nickm@torproject.org>2015-02-03 13:06:58 -0500
commitcdc49629c7d26e9806b8aa3c5a7dc80fbec9d060 (patch)
tree4a03c7d9830abee489d0f08d0d2ce618699e41da /src/or/geoip.c
parentd03e1da232ada2e0d3a3de3dbf6885caec74e4e0 (diff)
parent7f52dc4d03cc8b738b0c2a3896128ab38b030c52 (diff)
downloadtor-cdc49629c7d26e9806b8aa3c5a7dc80fbec9d060.tar.gz
tor-cdc49629c7d26e9806b8aa3c5a7dc80fbec9d060.zip
Merge branch 'bug6852'
Conflicts: src/or/status.c
Diffstat (limited to 'src/or/geoip.c')
-rw-r--r--src/or/geoip.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 5564b72a04..120ce479cc 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -1436,6 +1436,39 @@ 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)
+{
+ const int n_hours = 6;
+ char *out = NULL;
+ int n_clients = 0;
+ clientmap_entry_t **ent;
+ unsigned cutoff = (unsigned)( (now-n_hours*3600)/60 );
+
+ 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;
+ if ((*ent)->last_seen_in_minutes < cutoff)
+ continue;
+ n_clients++;
+ }
+
+ tor_asprintf(&out, "Heartbeat: "
+ "In the last %d hours, I have seen %d unique clients.",
+ n_hours,
+ n_clients);
+
+ return out;
+}
+
/** Write bridge statistics to $DATADIR/stats/bridge-stats and return
* when we should next try to write statistics. */
time_t