aboutsummaryrefslogtreecommitdiff
path: root/src/feature/relay/router.h
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-12-15 11:41:42 -0500
committerNick Mathewson <nickm@torproject.org>2020-12-21 13:18:20 -0500
commitc934fced31a2dd6d53b129b6270109bc48c1ebb0 (patch)
tree9b7254eabb1f3e9e7f604003bf2e759b0030d4bd /src/feature/relay/router.h
parentc731a4efec3c7206bbbb8d2ba39c970fcb0c9f36 (diff)
downloadtor-c934fced31a2dd6d53b129b6270109bc48c1ebb0.tar.gz
tor-c934fced31a2dd6d53b129b6270109bc48c1ebb0.zip
relay: Report the entire content of a stats file
It turns out that 9 years ago, we stopped appending data into stats file and rather overwrite everytime we have new stats (see commit a6a127c833eace1100aca7ab8ad118862bb8a8b9) The load_stats_file() function was still thinking that we could have the same line many times in the file which turns out to be false since 9 years ago. However, that did not cause problem until IPv6 connection stats came along which introduced a new line in conn-stats: "ipv6-conn-bi-direct ...". Before, that file contained a single line starting with the tag "conn-bi-direct". That very tag appears also in the IPv6 tag (see above) so the load_stats_file() function would consider that the IPv6 line as the last tag to be appeneded to the file and fail to report the line above (for IPv4). It would actually truncate the IPv6 line and report it (removing the "ipv6-" part). In other words, "conn-bi-direct" was not reported and instead "ipv6-conn-bi-direct" was used without the "ipv6-" part. This commit refactors the entire function so that now it looks for a "timestamp tag" to validate and then if everything is fine, returns the entire content of the file. The refactor simplifies the function, adds logging in case of failures and modernize it in terms of coding standard. Unit tests are also added that makes sure the loaded content matches the entire file if timestamp validation passes. Fixes #40226 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/relay/router.h')
-rw-r--r--src/feature/relay/router.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/feature/relay/router.h b/src/feature/relay/router.h
index f71ada8eb7..2648bb5112 100644
--- a/src/feature/relay/router.h
+++ b/src/feature/relay/router.h
@@ -129,6 +129,8 @@ void router_free_all(void);
STATIC void get_platform_str(char *platform, size_t len);
STATIC int router_write_fingerprint(int hashed, int ed25519_identity);
STATIC smartlist_t *get_my_declared_family(const or_options_t *options);
+STATIC int load_stats_file(const char *filename, const char *ts_tag,
+ time_t now, char **out);
#ifdef TOR_UNIT_TESTS
extern time_t desc_clean_since;