[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] relay: Move "overload-general" from extra-info to server descriptor.
commit 705ea32c6e832ab2f063dc9802a03f53e4371b9a
Author: Alexander Færøy <ahf@xxxxxxxxxxxxxx>
Date: Mon Apr 12 18:36:05 2021 +0000
relay: Move "overload-general" from extra-info to server descriptor.
Fixes #40364
Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
changes/ticket40364 | 3 +++
src/feature/relay/router.c | 9 +++++++++
src/feature/stats/rephist.c | 27 +++++++++++++++++++--------
src/feature/stats/rephist.h | 1 +
src/test/test_stats.c | 39 +++++++++++++++++++++++++++------------
5 files changed, 59 insertions(+), 20 deletions(-)
diff --git a/changes/ticket40364 b/changes/ticket40364
new file mode 100644
index 0000000000..261521a736
--- /dev/null
+++ b/changes/ticket40364
@@ -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.
diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c
index 47dbcaaad6..67d3e3ee75 100644
--- a/src/feature/relay/router.c
+++ b/src/feature/relay/router.c
@@ -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 ");
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c
index 4ad5d46b0c..e25c01331d 100644
--- a/src/feature/stats/rephist.c
+++ b/src/feature/stats/rephist.c
@@ -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",
- OVERLOAD_STATS_VERSION, tbuf);
+ 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);
diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h
index 5aaf5c9255..d4a2f301cf 100644
--- a/src/feature/stats/rephist.h
+++ b/src/feature/stats/rephist.h
@@ -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
diff --git a/src/test/test_stats.c b/src/test/test_stats.c
index 465256a1e1..081ae22cd5 100644
--- a/src/test/test_stats.c
+++ b/src/test/test_stats.c
@@ -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);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits