Commit 705ea32c authored by Alexander Færøy's avatar Alexander Færøy 🍍 Committed by David Goulet
Browse files

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



Fixes #40364
Signed-off-by: David Goulet's avatarDavid Goulet <dgoulet@torproject.org>
parent 1b48a28a
Pipeline #4892 passed with stage
in 16 minutes and 28 seconds
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.
......@@ -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 ");
......
......@@ -221,23 +221,34 @@ 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 extra-info documents for publishing
* overload statistics. */
/** Returns an allocated string for server descriptor for publising information
* on whether we are overloaded or not. */
char *
rep_hist_get_overload_stats_lines(void)
rep_hist_get_overload_general_line(void)
{
char *result = NULL;
smartlist_t *chunks = smartlist_new();
char tbuf[ISO_TIME_LEN+1];
/* First encode the general overload */
/* 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",
tor_asprintf(&result, "overload-general %d %s\n",
OVERLOAD_STATS_VERSION, tbuf);
}
/* Now do bandwidth-related overloads */
return result;
}
/** Returns an allocated string for extra-info documents for publishing
* overload statistics. */
char *
rep_hist_get_overload_stats_lines(void)
{
char *result = NULL;
smartlist_t *chunks = smartlist_new();
char tbuf[ISO_TIME_LEN+1];
/* 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);
......
......@@ -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
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment