mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Merge branch 'bug6852'
Conflicts: src/or/status.c
This commit is contained in:
commit
cdc49629c7
3
changes/bug6852
Normal file
3
changes/bug6852
Normal file
@ -0,0 +1,3 @@
|
||||
o Minor features:
|
||||
- Add a unique client counter to the heartbeat message. Resolves
|
||||
ticket 6852.
|
@ -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
|
||||
|
@ -64,6 +64,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
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "statefile.h"
|
||||
|
||||
static void log_accounting(const time_t now, const or_options_t *options);
|
||||
#include "geoip.h"
|
||||
|
||||
/** Return the total number of circuits. */
|
||||
STATIC int
|
||||
@ -92,7 +93,6 @@ log_heartbeat(time_t now)
|
||||
const int hibernating = we_are_hibernating();
|
||||
|
||||
const or_options_t *options = get_options();
|
||||
(void)now;
|
||||
|
||||
if (public_server_mode(options) && !hibernating) {
|
||||
/* Let's check if we are in the current cached consensus. */
|
||||
@ -132,6 +132,14 @@ log_heartbeat(time_t now)
|
||||
|
||||
circuit_log_ancient_one_hop_circuits(1800);
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user