summaryrefslogtreecommitdiff
path: root/src/feature/dircache
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-07-30 08:33:59 -0400
committerNick Mathewson <nickm@torproject.org>2018-07-30 08:33:59 -0400
commitac9d08f66a3e5fd3fb3d456c4146b57c5ce1f1d6 (patch)
tree942abab1c2dcb5af24db7d10a7b8607c692ecf48 /src/feature/dircache
parent811ed8cf9f58d8480244483f4ad012ea9dca42ef (diff)
parent6d59ab16a0aebf74b793c174f8e724b2fbcbbb64 (diff)
downloadtor-ac9d08f66a3e5fd3fb3d456c4146b57c5ce1f1d6.tar.gz
tor-ac9d08f66a3e5fd3fb3d456c4146b57c5ce1f1d6.zip
Merge remote-tracking branch 'juga/ticket3723_03_squashed_rebased'
Diffstat (limited to 'src/feature/dircache')
-rw-r--r--src/feature/dircache/dirserv.c34
-rw-r--r--src/feature/dircache/dirserv.h10
2 files changed, 39 insertions, 5 deletions
diff --git a/src/feature/dircache/dirserv.c b/src/feature/dircache/dirserv.c
index 1500467ec0..b85db8324f 100644
--- a/src/feature/dircache/dirserv.c
+++ b/src/feature/dircache/dirserv.c
@@ -51,6 +51,7 @@
#include "lib/crypt_ops/crypto_format.h"
#include "lib/encoding/confline.h"
+#include "lib/encoding/keyval.h"
/**
* \file dirserv.c
* \brief Directory server core implementation. Manages directory
@@ -2599,12 +2600,14 @@ measured_bw_line_apply(measured_bw_line_t *parsed_line,
}
/**
- * Read the measured bandwidth file and apply it to the list of
- * vote_routerstatus_t. Returns -1 on error, 0 otherwise.
+ * Read the measured bandwidth list file, apply it to the list of
+ * 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 *routerstatuses,
+ smartlist_t *bw_file_headers)
{
FILE *fp = tor_fopen_cloexec(from_file, "r");
int applied_lines = 0;
@@ -2654,6 +2657,12 @@ dirserv_read_measured_bandwidths(const char *from_file,
goto err;
}
+ /* 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);
@@ -2669,7 +2678,24 @@ 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++;
- }
+ /* 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_HEADERS_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) &&
+ !strchr(line, ' ') &&
+ (smartlist_len(bw_file_headers)
+ < MAX_BW_FILE_HEADER_COUNT_IN_VOTE)) {
+ line[strlen(line)-1] = '\0';
+ smartlist_add_strdup(bw_file_headers, line);
+ };
}
}
diff --git a/src/feature/dircache/dirserv.h b/src/feature/dircache/dirserv.h
index b1b8cee5fc..9be4bf9db2 100644
--- a/src/feature/dircache/dirserv.h
+++ b/src/feature/dircache/dirserv.h
@@ -49,6 +49,13 @@ typedef enum {
/** Maximum allowable length of a version line in a networkstatus. */
#define MAX_V_LINE_LEN 128
+/** Maximum allowable length of bandwidth headers in a bandwidth file */
+#define MAX_BW_FILE_HEADER_COUNT_IN_VOTE 50
+
+/** Terminatore that separates bandwidth file headers from bandwidth file
+ * relay lines */
+#define BW_FILE_HEADERS_TERMINATOR "=====\n"
+
/** Ways to convert a spoolable_resource_t to a bunch of bytes. */
typedef enum dir_spool_source_t {
DIR_SPOOL_SERVER_BY_DIGEST=1, DIR_SPOOL_SERVER_BY_FP,
@@ -217,7 +224,8 @@ dirserv_read_guardfraction_file_from_str(const char *guardfraction_file_str,
#endif /* defined(DIRSERV_PRIVATE) */
int dirserv_read_measured_bandwidths(const char *from_file,
- smartlist_t *routerstatuses);
+ smartlist_t *routerstatuses,
+ smartlist_t *bw_file_headers);
int dirserv_read_guardfraction_file(const char *fname,
smartlist_t *vote_routerstatuses);