Bug - Heartbeat log message does not consider the value of the "HeartbeatPeriod" value.
The problem is in the file /feature/stats/geoip_stats.c
, at the fonction format_client_stats_heartbeat()
. The variable n_hours
is hardcoded to 6 hours, which is the default value. Here is the changes I made to the fonction. I take the opportunity to do a little bit of refactoring. I did not know how to compile the project and test it, but I'm sure you will understand what I'm trying to do.
To fix this issue, n_hours
, now renamed n_heartbeat_period
, need to take the value of the option->HeartbeatPeriod
, which is in seconds.
[- Line 1207 : const int n_hours = 6; -]
[+ Line 1207 : const int n_heartbeat_period = option->HeartbeatPeriod; +]
[- Line 1211 : unsigned cutoff = (unsigned)( (now-n_hours*3600)/60 ); -]
[+ Line 1211 : unsigned cutoff = (unsigned)( (now-n_heartbeat_period)/60 ); +]
[- Line 1228 : nhours, -]
[+ Line 1228 : n_heartbeat_period +]
The variable out
could also be renamed msg
.
[- Line 1208 : char *out = NULL; -]
[+ Line 1208 : char *msg = NULL; +]
[- Line 1226 : tor_asprintf(&out, "Heartbeat: " -]
[+ Line 1226 : tor_asprintf(&msg, "Heartbeat: " +]
[- Line 1231 : return out; -]
[+ Line 1231 : return msg; +]
A clientmap_entry_t
is a client
, so why not call it that way to make it more clear instead of ent
.
[- Line 1210 : clientmap_entry_t **ent; -]
[+ Line 1210 : clientmap_entry_t **client; +]
[- Line 1217 : HT_FOREACH(ent, clientmap, &client_history) { -]
[+ Line 1217 : HT_FOREACH(client, clientmap, &client_history) { +]
[- Line 1219 : if ((*ent)->action != GEOIP_CLIENT_CONNECT) -]
[+ Line 1219 : if ((*client)->action != GEOIP_CLIENT_CONNECT) +]
[- Line 1221 : if ((*ent)->last_seen_in_minutes < cutoff) -]
[+ Line 1221 : if ((*client)->last_seen_in_minutes < cutoff) +]
Prettier msg
:simple_smile:
[- Line 1226 : tor_asprintf(&out, "Heartbeat: " -]
[- Line 1227 : "In the last %d hours, I have seen %d unique clients.", -]
[- Line 1228 : n_hours, -]
[- Line 1229 : n_clients); -]
[+ Line 1226 : tor_asprintf(&msg, "Heartbeat: In the last %d hour%s, I have seen %u unique client%s.", +]
[+ Line 1227 : n_heartbeat_period*60*60, +]
[+ Line 1228 : n_heartbeat_period >= 60*60*2 ? "s" : "", +]
[+ Line 1229 : n_clients, +]
[+ Line 1230 : n_clients > 1 ? "s" : ""); +]
Message to the moderator about my GitLab Flavored Markdown
skills :
My last issue is horrible and this one will certainly be, because I can't validate the formating before submitting it! I'm so sorry.