[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Add unique client counter to the heartbeat message.



commit 05f8fd2878e1b85822c126c0206f8b8929556868
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Tue Feb 26 12:43:53 2013 +0200

    Add unique client counter to the heartbeat message.
---
 changes/bug6852 |    3 +++
 src/or/geoip.c  |   32 ++++++++++++++++++++++++++++++++
 src/or/geoip.h  |    1 +
 src/or/status.c |   10 +++++++++-
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/changes/bug6852 b/changes/bug6852
new file mode 100644
index 0000000..9bafef8
--- /dev/null
+++ b/changes/bug6852
@@ -0,0 +1,3 @@
+  o Minor features:
+    - Add a unique client counter to the heartbeat message. Resolves
+      ticket 6852.
diff --git a/src/or/geoip.c b/src/or/geoip.c
index e2e98e8..810070c 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
diff --git a/src/or/geoip.h b/src/or/geoip.h
index ebefee5..bebce1e 100644
--- a/src/or/geoip.h
+++ b/src/or/geoip.h
@@ -60,6 +60,7 @@ time_t geoip_bridge_stats_write(time_t now);
 void geoip_bridge_stats_term(void);
 const char *geoip_get_bridge_stats_extrainfo(time_t);
 char *geoip_get_bridge_stats_controller(time_t);
+char *format_client_stats_heartbeat(time_t now);
 
 #endif
 
diff --git a/src/or/status.c b/src/or/status.c
index 126167d..02d96aa 100644
--- a/src/or/status.c
+++ b/src/or/status.c
@@ -14,6 +14,7 @@
 #include "router.h"
 #include "circuitlist.h"
 #include "main.h"
+#include "geoip.h"
 
 /** Return the total number of circuits. */
 static int
@@ -87,7 +88,6 @@ log_heartbeat(time_t now)
   const routerinfo_t *me;
 
   const or_options_t *options = get_options();
-  (void)now;
 
   if (public_server_mode(options)) {
     /* Let's check if we are in the current cached consensus. */
@@ -112,6 +112,14 @@ log_heartbeat(time_t now)
         100*(U64_TO_DBL(stats_n_data_bytes_packaged) /
              U64_TO_DBL(stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) );
 
+  if (options->BridgeRelay) {
+    char *msg = NULL;
+    msg = format_client_stats_heartbeat(now);
+    if (msg)
+      log_notice(LD_HEARTBEAT, "%s", msg);
+    tor_free(msg);
+  }
+
   tor_free(uptime);
   tor_free(bw_sent);
   tor_free(bw_rcvd);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits