Loading statistics from a file for extra-info descriptors does not correctly determine the last statistics block
There's an issue with the recently added IPv6 connection statistics (apparently) not being included in extra-info descriptors, and I believe the reason is a bug in the
load_stats_file function in
For example, a
stats/conn-stats file might look like this:
conn-bi-direct 2020-12-13 15:48:53 (86400 s) 12,34,56,78 ipv6-conn-bi-direct 2020-12-14 15:48:53 (86400 s) 21,43,65,87 conn-bi-direct 2020-12-13 15:48:53 (86400 s) 23,45,67,89 ipv6-conn-bi-direct 2020-12-14 15:48:53 (86400 s) 32,54,76,98
The extra-info descriptor published by this relay would contain the following line:
conn-bi-direct 2020-12-14 15:48:53 (86400 s) 32,54,76,98
Note how these are the IPv6 numbers from the last line, not IPv4 numbers.
The bug is that
load_stats_file finds the last occurrence of
conn-bi-direct, which is five characters into the last line, and includes the remainder of that line in its extra-info descriptor.
What it should do is find either the last occurence of
\nconn-bi-direct and include the file from there on (without the newline). Or if there's no such string in the file, check if the file begins with
conn-bi-direct, and include the whole file.