aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dircache/dirserv.c
diff options
context:
space:
mode:
authorjuga0 <juga@riseup.net>2018-06-30 06:16:17 +0000
committerjuga0 <juga@riseup.net>2018-07-16 14:43:49 +0000
commit87fc409a70cccf448072a9ce109a4efb3fcf26e9 (patch)
treed64ca34899a9e211725b8aa1ce0a79f78cb4c7cf /src/feature/dircache/dirserv.c
parentf906d9be111bd8eb55cad8478fdab8f20a10a13d (diff)
downloadtor-87fc409a70cccf448072a9ce109a4efb3fcf26e9.tar.gz
tor-87fc409a70cccf448072a9ce109a4efb3fcf26e9.zip
Replace bwlist by bw_file and terminator condition
If bandwidth file terminator is found, set end of headers flag and do not store the line. If it is not, parse a relay line and check whether it is a header line.
Diffstat (limited to 'src/feature/dircache/dirserv.c')
-rw-r--r--src/feature/dircache/dirserv.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/feature/dircache/dirserv.c b/src/feature/dircache/dirserv.c
index e7b5239e0b..c3ccc3c8ff 100644
--- a/src/feature/dircache/dirserv.c
+++ b/src/feature/dircache/dirserv.c
@@ -2600,13 +2600,13 @@ measured_bw_line_apply(measured_bw_line_t *parsed_line,
/**
* Read the measured bandwidth list file, apply it to the list of
- * vote_routerstatus_t and store all the headers in <b>bwlist_headers</b>.
+ * vote_routerstatus_t and store all the headers in <b>bw_file_headers</b>.
* Returns -1 on error, 0 otherwise.
*/
int
dirserv_read_measured_bandwidths(const char *from_file,
smartlist_t *routerstatuses,
- smartlist_t *bwlist_headers)
+ smartlist_t *bw_file_headers)
{
FILE *fp = tor_fopen_cloexec(from_file, "r");
int applied_lines = 0;
@@ -2656,7 +2656,11 @@ dirserv_read_measured_bandwidths(const char *from_file,
goto err;
}
- smartlist_add_asprintf(bwlist_headers, "timestamp=%ld", file_time);
+ /* If timestamp was correct and bw_file_headers is not NULL,
+ * add timestamp to bw_file_headers */
+ if (bw_file_headers)
+ smartlist_add_asprintf(bw_file_headers, "timestamp=%lu",
+ (unsigned long)file_time);
if (routerstatuses)
smartlist_sort(routerstatuses, compare_vote_routerstatus_entries);
@@ -2673,15 +2677,22 @@ dirserv_read_measured_bandwidths(const char *from_file,
dirserv_cache_measured_bw(&parsed_line, file_time);
if (measured_bw_line_apply(&parsed_line, routerstatuses) > 0)
applied_lines++;
- } else {
- /* If line does not contain the header separator and it is key_value,
- * it is probably a KeyValue header.*/
- if (strcmp(line, "====\n") != 0 &&
- string_is_key_value(LOG_DEBUG, line)) {
- line[strlen(line)-1] = '\0';
- smartlist_add_strdup(bwlist_headers, line);
- };
- }
+ /* if the terminator is found, it is the end of header lines, set the
+ * flag but do not store anything */
+ } else if (strcmp(line, BW_FILE_TERMINATOR) == 0)
+ line_is_after_headers = 1;
+ /* if the line was not a correct relay line nor the terminator and
+ * the end of the header lines has not been detected yet
+ * and it is key_value and bw_file_headers did not reach the maximum
+ * number of headers,
+ * then assume this line is a header and add it to bw_file_headers */
+ else if (bw_file_headers &&
+ (line_is_after_headers == 0) &&
+ string_is_key_value(LOG_DEBUG, line) &&
+ (smartlist_len(bw_file_headers) < MAX_BW_FILE_HEADERS_LEN)) {
+ line[strlen(line)-1] = '\0';
+ smartlist_add_strdup(bw_file_headers, line);
+ };
}
}