relay: Move "overload-general" from extra-info to server descriptor.

Fixes #40364

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
Alexander Færøy 2021-04-12 18:36:05 +00:00 committed by David Goulet
parent 1b48a28a74
commit 705ea32c6e
5 changed files with 59 additions and 20 deletions

3
changes/ticket40364 Normal file
View File

@ -0,0 +1,3 @@
o Minor bugfixes (relay):
- Move the "overload-general" line from extrainfo to the server descriptor.
Fixes bug 40364; bugfix on 0.4.6.1-alpha.

View File

@ -3059,6 +3059,15 @@ router_dump_router_to_string(routerinfo_t *router,
smartlist_add_strdup(chunks, "tunnelled-dir-server\n");
}
/* Overload general information. */
if (options->OverloadStatistics) {
char *overload_general = rep_hist_get_overload_general_line();
if (overload_general) {
smartlist_add(chunks, overload_general);
}
}
/* Sign the descriptor with Ed25519 */
if (emit_ed_sigs) {
smartlist_add_strdup(chunks, "router-sig-ed25519 ");

View File

@ -221,6 +221,24 @@ overload_happened_recently(time_t overload_time, int n_hours)
/* The current version of the overload stats version */
#define OVERLOAD_STATS_VERSION 1
/** Returns an allocated string for server descriptor for publising information
* on whether we are overloaded or not. */
char *
rep_hist_get_overload_general_line(void)
{
char *result = NULL;
char tbuf[ISO_TIME_LEN+1];
/* Encode the general overload */
if (overload_happened_recently(overload_stats.overload_general_time, 72)) {
format_iso_time(tbuf, overload_stats.overload_general_time);
tor_asprintf(&result, "overload-general %d %s\n",
OVERLOAD_STATS_VERSION, tbuf);
}
return result;
}
/** Returns an allocated string for extra-info documents for publishing
* overload statistics. */
char *
@ -230,14 +248,7 @@ rep_hist_get_overload_stats_lines(void)
smartlist_t *chunks = smartlist_new();
char tbuf[ISO_TIME_LEN+1];
/* First encode the general overload */
if (overload_happened_recently(overload_stats.overload_general_time, 72)) {
format_iso_time(tbuf, overload_stats.overload_general_time);
smartlist_add_asprintf(chunks, "overload-general %d %s\n",
OVERLOAD_STATS_VERSION, tbuf);
}
/* Now do bandwidth-related overloads */
/* Add bandwidth-related overloads */
if (overload_happened_recently(overload_stats.overload_ratelimits_time,24)) {
const or_options_t *options = get_options();
format_iso_time(tbuf, overload_stats.overload_ratelimits_time);

View File

@ -156,6 +156,7 @@ typedef enum {
} overload_type_t;
void rep_hist_note_overload(overload_type_t overload);
char *rep_hist_get_overload_general_line(void);
char *rep_hist_get_overload_stats_lines(void);
#ifdef TOR_UNIT_TESTS

View File

@ -727,7 +727,7 @@ test_overload_stats(void *arg)
update_approx_time(current_time);
/* Now check the string */
stats_str = rep_hist_get_overload_stats_lines();
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-03 23:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
@ -735,7 +735,7 @@ test_overload_stats(void *arg)
current_time += 3600*72;
update_approx_time(current_time);
stats_str = rep_hist_get_overload_stats_lines();
stats_str = rep_hist_get_overload_general_line();
tt_assert(!stats_str);
/* Now the time should be 2002-01-07 00:00:00 */
@ -743,16 +743,19 @@ test_overload_stats(void *arg)
/* Note a DNS overload */
rep_hist_note_overload(OVERLOAD_GENERAL);
stats_str = rep_hist_get_overload_stats_lines();
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
/* Also note an fd exhaustion event */
rep_hist_note_overload(OVERLOAD_FD_EXHAUSTED);
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
stats_str = rep_hist_get_overload_stats_lines();
tt_str_op("overload-general 1 2002-01-07 00:00:00\n"
"overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tt_str_op("overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
/* Move the time forward. Register DNS overload. See that the time changed */
@ -761,9 +764,12 @@ test_overload_stats(void *arg)
rep_hist_note_overload(OVERLOAD_GENERAL);
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
stats_str = rep_hist_get_overload_stats_lines();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n"
"overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tt_str_op("overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
/* Move the time forward. Register a bandwidth ratelimit event. See that the
@ -777,9 +783,12 @@ test_overload_stats(void *arg)
get_options_mutable()->BandwidthRate = 1000;
get_options_mutable()->BandwidthBurst = 2000;
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
stats_str = rep_hist_get_overload_stats_lines();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n"
"overload-ratelimits 1 2002-01-07 04:00:00 1000 2000 1 0\n"
tt_str_op("overload-ratelimits 1 2002-01-07 04:00:00 1000 2000 1 0\n"
"overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
@ -787,16 +796,19 @@ test_overload_stats(void *arg)
current_time += 3600*24;
update_approx_time(current_time);
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
stats_str = rep_hist_get_overload_stats_lines();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n"
"overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tt_str_op("overload-fd-exhausted 1 2002-01-07 00:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
/* Move the time forward 44 hours: no fd exhausted line anymore. */
current_time += 3600*44;
update_approx_time(current_time);
stats_str = rep_hist_get_overload_stats_lines();
stats_str = rep_hist_get_overload_general_line();
tt_str_op("overload-general 1 2002-01-07 02:00:00\n", OP_EQ, stats_str);
tor_free(stats_str);
@ -804,6 +816,9 @@ test_overload_stats(void *arg)
current_time += 3600*2;
update_approx_time(current_time);
stats_str = rep_hist_get_overload_general_line();
tt_assert(!stats_str);
stats_str = rep_hist_get_overload_stats_lines();
tt_assert(!stats_str);