rephist: Stop tracking relay connection status

Remove a series of connection counters that were only used when dumping the
rephist statistics with SIGUSR1 signal.

This reduces the or_history_t structure size.

Closes #25163

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet
2018-02-06 12:51:43 -05:00
parent 199bc37290
commit 93ebcc2b8f
5 changed files with 5 additions and 148 deletions
+4
View File
@@ -0,0 +1,4 @@
o Code simplification and refactoring (rephist):
- Remove a series of counters used to track circuit extend attemps and
connection status but that in reality we aren't using for anything other
than stats logged by a SIGUSR1 signal. Closes ticket 25163.
-1
View File
@@ -1884,7 +1884,6 @@ channel_do_open_actions(channel_t *chan)
if (started_here) {
circuit_build_times_network_is_live(get_circuit_build_times_mutable());
rep_hist_note_connect_succeeded(chan->identity_digest, now);
router_set_status(chan->identity_digest, 1);
} else {
/* only report it to the geoip module if it's not a known router */
-4
View File
@@ -705,7 +705,6 @@ connection_or_finished_connecting(or_connection_t *or_conn)
void
connection_or_about_to_close(or_connection_t *or_conn)
{
time_t now = time(NULL);
connection_t *conn = TO_CONN(or_conn);
/* Tell the controlling channel we're closed */
@@ -725,7 +724,6 @@ connection_or_about_to_close(or_connection_t *or_conn)
if (connection_or_nonopen_was_started_here(or_conn)) {
const or_options_t *options = get_options();
connection_or_note_state_when_broken(or_conn);
rep_hist_note_connect_failed(or_conn->identity_digest, now);
/* Tell the new guard API about the channel failure */
entry_guard_chan_failed(TLS_CHAN_TO_BASE(or_conn->chan));
if (conn->state >= OR_CONN_STATE_TLS_HANDSHAKING) {
@@ -741,11 +739,9 @@ connection_or_about_to_close(or_connection_t *or_conn)
} else if (conn->hold_open_until_flushed) {
/* We only set hold_open_until_flushed when we're intentionally
* closing a connection. */
rep_hist_note_disconnect(or_conn->identity_digest, now);
control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED,
tls_error_to_orconn_end_reason(or_conn->tls_error));
} else if (!tor_digest_is_zero(or_conn->identity_digest)) {
rep_hist_note_connection_died(or_conn->identity_digest, now);
control_event_or_conn_status(or_conn, OR_CONN_EVENT_CLOSED,
tls_error_to_orconn_end_reason(or_conn->tls_error));
}
+1 -139
View File
@@ -116,20 +116,6 @@ typedef struct or_history_t {
time_t since;
/** When did we most recently note a change to this OR? */
time_t changed;
/** How many times did we successfully connect? */
unsigned long n_conn_ok;
/** How many times did we try to connect and fail?*/
unsigned long n_conn_fail;
/** How many seconds have we been connected to this OR before
* 'up_since'? */
unsigned long uptime;
/** How many seconds have we been unable to connect to this OR before
* 'down_since'? */
unsigned long downtime;
/** If nonzero, we have been connected since this time. */
time_t up_since;
/** If nonzero, we have been unable to connect since this time. */
time_t down_since;
/** The address at which we most recently connected to this OR
* successfully. */
@@ -233,23 +219,6 @@ free_or_history(void *_hist)
tor_free(hist);
}
/** Update an or_history_t object <b>hist</b> so that its uptime/downtime
* count is up-to-date as of <b>when</b>.
*/
static void
update_or_history(or_history_t *hist, time_t when)
{
tor_assert(hist);
if (hist->up_since) {
tor_assert(!hist->down_since);
hist->uptime += (when - hist->up_since);
hist->up_since = when;
} else if (hist->down_since) {
hist->downtime += (when - hist->down_since);
hist->down_since = when;
}
}
/** Initialize the static data structures for tracking history. */
void
rep_hist_init(void)
@@ -259,99 +228,6 @@ rep_hist_init(void)
predicted_ports_alloc();
}
/** Helper: note that we are no longer connected to the router with history
* <b>hist</b>. If <b>failed</b>, the connection failed; otherwise, it was
* closed correctly. */
static void
mark_or_down(or_history_t *hist, time_t when, int failed)
{
if (hist->up_since) {
hist->uptime += (when - hist->up_since);
hist->up_since = 0;
}
if (failed && !hist->down_since) {
hist->down_since = when;
}
}
/** Helper: note that we are connected to the router with history
* <b>hist</b>. */
static void
mark_or_up(or_history_t *hist, time_t when)
{
if (hist->down_since) {
hist->downtime += (when - hist->down_since);
hist->down_since = 0;
}
if (!hist->up_since) {
hist->up_since = when;
}
}
/** Remember that an attempt to connect to the OR with identity digest
* <b>id</b> failed at <b>when</b>.
*/
void
rep_hist_note_connect_failed(const char* id, time_t when)
{
or_history_t *hist;
hist = get_or_history(id);
if (!hist)
return;
++hist->n_conn_fail;
mark_or_down(hist, when, 1);
hist->changed = when;
}
/** Remember that an attempt to connect to the OR with identity digest
* <b>id</b> succeeded at <b>when</b>.
*/
void
rep_hist_note_connect_succeeded(const char* id, time_t when)
{
or_history_t *hist;
hist = get_or_history(id);
if (!hist)
return;
++hist->n_conn_ok;
mark_or_up(hist, when);
hist->changed = when;
}
/** Remember that we intentionally closed our connection to the OR
* with identity digest <b>id</b> at <b>when</b>.
*/
void
rep_hist_note_disconnect(const char* id, time_t when)
{
or_history_t *hist;
hist = get_or_history(id);
if (!hist)
return;
mark_or_down(hist, when, 0);
hist->changed = when;
}
/** Remember that our connection to the OR with identity digest
* <b>id</b> had an error and stopped working at <b>when</b>.
*/
void
rep_hist_note_connection_died(const char* id, time_t when)
{
or_history_t *hist;
if (!id) {
/* If conn has no identity, it didn't complete its handshake, or something
* went wrong. Ignore it.
*/
return;
}
hist = get_or_history(id);
if (!hist)
return;
mark_or_down(hist, when, 1);
hist->changed = when;
}
/** We have just decided that this router with identity digest <b>id</b> is
* reachable, meaning we will give it a "Running" flag for the next while. */
void
@@ -488,7 +364,6 @@ rep_hist_make_router_pessimal(const char *id, time_t when)
tor_assert(hist);
rep_hist_note_router_unreachable(id, when);
mark_or_down(hist, when, 1);
hist->weighted_run_length = 0;
hist->weighted_uptime = 0;
@@ -676,8 +551,6 @@ rep_hist_dump_stats(time_t now, int severity)
char hexdigest1[HEX_DIGEST_LEN+1];
or_history_t *or_history;
void *or_history_p;
double uptime;
unsigned long upt, downt;
const node_t *node;
rep_history_clean(now - get_options()->RephistTrackTime);
@@ -697,22 +570,11 @@ rep_hist_dump_stats(time_t now, int severity)
else
name1 = "(unknown)";
base16_encode(hexdigest1, sizeof(hexdigest1), digest1, DIGEST_LEN);
update_or_history(or_history, now);
upt = or_history->uptime;
downt = or_history->downtime;
s = get_stability(or_history, now);
stability = (long)s;
if (upt+downt) {
uptime = ((double)upt) / (upt+downt);
} else {
uptime=1.0;
}
tor_log(severity, LD_HIST,
"OR %s [%s]: %ld/%ld good connections; uptime %ld/%ld sec (%.2f%%); "
"wmtbf %lu:%02lu:%02lu",
"OR %s [%s]: wmtbf %lu:%02lu:%02lu",
name1, hexdigest1,
or_history->n_conn_ok, or_history->n_conn_fail+or_history->n_conn_ok,
upt, upt+downt, uptime*100.0,
stability/3600, (stability/60)%60, stability%60);
}
}
-4
View File
@@ -13,10 +13,6 @@
#define TOR_REPHIST_H
void rep_hist_init(void);
void rep_hist_note_connect_failed(const char* nickname, time_t when);
void rep_hist_note_connect_succeeded(const char* nickname, time_t when);
void rep_hist_note_disconnect(const char* nickname, time_t when);
void rep_hist_note_connection_died(const char* nickname, time_t when);
void rep_hist_dump_stats(time_t now, int severity);
void rep_hist_note_bytes_read(size_t num_bytes, time_t when);
void rep_hist_note_bytes_written(size_t num_bytes, time_t when);