|
@@ -1592,25 +1592,6 @@ test_dir_measured_bw_kb(void *arg)
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-static void
|
|
|
|
-test_dir_dirserv_read_measured_bandwidths_empty(void *arg)
|
|
|
|
-{
|
|
|
|
- char *fname=NULL;
|
|
|
|
- (void)arg;
|
|
|
|
-
|
|
|
|
- fname = tor_strdup(get_fname("V3BandwidthsFile"));
|
|
|
|
-
|
|
|
|
- write_str_to_file(fname, "", 0);
|
|
|
|
- setup_capture_of_logs(LOG_WARN);
|
|
|
|
- tt_int_op(-1, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
|
|
- expect_log_msg("Empty bandwidth file\n");
|
|
|
|
-
|
|
|
|
- done:
|
|
|
|
- tor_free(fname);
|
|
|
|
- teardown_capture_of_logs();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
|
|
* When the end of the header is detected (a first complete bw line is parsed),
|
|
* When the end of the header is detected (a first complete bw line is parsed),
|
|
* incomplete lines fail and give warnings, but do not give warnings if
|
|
* incomplete lines fail and give warnings, but do not give warnings if
|
|
@@ -1654,7 +1635,7 @@ test_dir_measured_bw_kb_line_is_after_headers(void *arg)
|
|
teardown_capture_of_logs();
|
|
teardown_capture_of_logs();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
static void
|
|
static void
|
|
test_dir_dirserv_read_measured_bandwidths(void *arg)
|
|
test_dir_dirserv_read_measured_bandwidths(void *arg)
|
|
{
|
|
{
|
|
@@ -1662,76 +1643,321 @@ test_dir_dirserv_read_measured_bandwidths(void *arg)
|
|
char *content = NULL;
|
|
char *content = NULL;
|
|
time_t timestamp = time(NULL);
|
|
time_t timestamp = time(NULL);
|
|
char *fname = tor_strdup(get_fname("V3BandwidthsFile"));
|
|
char *fname = tor_strdup(get_fname("V3BandwidthsFile"));
|
|
-
|
|
+ smartlist_t *bw_file_headers = smartlist_new();
|
|
-
|
|
+
|
|
- tor_asprintf(&content, "%ld", (long)timestamp);
|
|
+ char *bw_file_headers_str = NULL;
|
|
- write_str_to_file(fname, content, 0);
|
|
+ char *bw_file_headers_str_v100 = NULL;
|
|
- tor_free(content);
|
|
+ char *bw_file_headers_str_v110 = NULL;
|
|
- tt_int_op(-1, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ char *bw_file_headers_str_bad = NULL;
|
|
-
|
|
+ char *bw_file_headers_str_extra = NULL;
|
|
-
|
|
+ char bw_file_headers_str_long[MAX_BW_FILE_HEADER_COUNT_IN_VOTE * 8 + 1] = "";
|
|
- tor_asprintf(&content, "%ld\n", (long)timestamp);
|
|
+
|
|
- write_str_to_file(fname, content, 0);
|
|
+ char *header_lines_v100 = NULL;
|
|
- tor_free(content);
|
|
+ char *header_lines_v110_no_terminator = NULL;
|
|
- tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ char *header_lines_v110 = NULL;
|
|
-
|
|
+ char header_lines_long[MAX_BW_FILE_HEADER_COUNT_IN_VOTE * 8 + 1] = "";
|
|
-
|
|
+ int i;
|
|
- const char *torflow_relay_lines=
|
|
+ const char *header_lines_v110_no_terminator_no_timestamp =
|
|
|
|
+ "version=1.1.0\n"
|
|
|
|
+ "software=sbws\n"
|
|
|
|
+ "software_version=0.1.0\n"
|
|
|
|
+ "earliest_bandwidth=2018-05-08T16:13:26\n"
|
|
|
|
+ "file_created=2018-04-16T21:49:18\n"
|
|
|
|
+ "generator_started=2018-05-08T16:13:25\n"
|
|
|
|
+ "latest_bandwidth=2018-04-16T20:49:18\n";
|
|
|
|
+ const char *bw_file_headers_str_v110_no_timestamp =
|
|
|
|
+ "version=1.1.0 software=sbws "
|
|
|
|
+ "software_version=0.1.0 "
|
|
|
|
+ "earliest_bandwidth=2018-05-08T16:13:26 "
|
|
|
|
+ "file_created=2018-04-16T21:49:18 "
|
|
|
|
+ "generator_started=2018-05-08T16:13:25 "
|
|
|
|
+ "latest_bandwidth=2018-04-16T20:49:18";
|
|
|
|
+ const char *relay_lines_v100 =
|
|
"node_id=$557365204145532d32353620696e73746561642e bw=1024 "
|
|
"node_id=$557365204145532d32353620696e73746561642e bw=1024 "
|
|
"nick=Test measured_at=1523911725 updated_at=1523911725 "
|
|
"nick=Test measured_at=1523911725 updated_at=1523911725 "
|
|
"pid_error=4.11374090719 pid_error_sum=4.11374090719 "
|
|
"pid_error=4.11374090719 pid_error_sum=4.11374090719 "
|
|
"pid_bw=57136645 pid_delta=2.12168374577 circ_fail=0.2 "
|
|
"pid_bw=57136645 pid_delta=2.12168374577 circ_fail=0.2 "
|
|
"scanner=/filepath\n";
|
|
"scanner=/filepath\n";
|
|
-
|
|
+ const char *relay_lines_v110 =
|
|
- tor_asprintf(&content, "%ld\n%s", (long)timestamp, torflow_relay_lines);
|
|
+ "node_id=$68A483E05A2ABDCA6DA5A3EF8DB5177638A27F80 "
|
|
|
|
+ "master_key_ed25519=YaqV4vbvPYKucElk297eVdNArDz9HtIwUoIeo0+cVIpQ "
|
|
|
|
+ "bw=760 nick=Test rtt=380 time=2018-05-08T16:13:26\n";
|
|
|
|
+ const char *relay_lines_bad =
|
|
|
|
+ "node_id=$68A483E05A2ABDCA6DA5A3EF8DB5177638A\n";
|
|
|
|
+
|
|
|
|
+ tor_asprintf(&header_lines_v100, "%ld\n", (long)timestamp);
|
|
|
|
+ tor_asprintf(&header_lines_v110_no_terminator, "%ld\n%s", (long)timestamp,
|
|
|
|
+ header_lines_v110_no_terminator_no_timestamp);
|
|
|
|
+ tor_asprintf(&header_lines_v110, "%s%s",
|
|
|
|
+ header_lines_v110_no_terminator, BW_FILE_HEADERS_TERMINATOR);
|
|
|
|
+
|
|
|
|
+ tor_asprintf(&bw_file_headers_str_v100, "timestamp=%ld",(long)timestamp);
|
|
|
|
+ tor_asprintf(&bw_file_headers_str_v110, "timestamp=%ld %s",
|
|
|
|
+ (long)timestamp, bw_file_headers_str_v110_no_timestamp);
|
|
|
|
+ tor_asprintf(&bw_file_headers_str_bad, "%s "
|
|
|
|
+ "node_id=$68A483E05A2ABDCA6DA5A3EF8DB5177638A",
|
|
|
|
+ bw_file_headers_str_v110);
|
|
|
|
+
|
|
|
|
+ for (i=0; i<MAX_BW_FILE_HEADER_COUNT_IN_VOTE; i++) {
|
|
|
|
+ strlcat(header_lines_long, "foo=bar\n",
|
|
|
|
+ sizeof(header_lines_long));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (i=0; i<MAX_BW_FILE_HEADER_COUNT_IN_VOTE - 8 - 1; i++) {
|
|
|
|
+ strlcat(bw_file_headers_str_long, "foo=bar ",
|
|
|
|
+ sizeof(bw_file_headers_str_long));
|
|
|
|
+ }
|
|
|
|
+ strlcat(bw_file_headers_str_long, "foo=bar",
|
|
|
|
+ sizeof(bw_file_headers_str_long));
|
|
|
|
+ tor_asprintf(&bw_file_headers_str_extra,
|
|
|
|
+ "%s %s",
|
|
|
|
+ bw_file_headers_str_v110,
|
|
|
|
+ bw_file_headers_str_long);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ write_str_to_file(fname, "", 0);
|
|
|
|
+ setup_capture_of_logs(LOG_WARN);
|
|
|
|
+ tt_int_op(-1, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ expect_log_msg("Empty bandwidth file\n");
|
|
|
|
+ teardown_capture_of_logs();
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op("", OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * bw_file_headers will be empty string */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%ld", (long)timestamp);
|
|
write_str_to_file(fname, content, 0);
|
|
write_str_to_file(fname, content, 0);
|
|
tor_free(content);
|
|
tor_free(content);
|
|
- tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ tt_int_op(-1, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
-
|
|
+ bw_file_headers));
|
|
-
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
- const char *v110_header_lines=
|
|
+ tt_str_op("", OP_EQ, bw_file_headers_str);
|
|
- "version=1.1.0\n"
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
- "software=sbws\n"
|
|
+ smartlist_free(bw_file_headers);
|
|
- "software_version=0.1.0\n"
|
|
+ tor_free(bw_file_headers_str);
|
|
- "generator_started=2018-05-08T16:13:25\n"
|
|
+
|
|
- "earliest_bandwidth=2018-05-08T16:13:26\n"
|
|
+
|
|
- "====\n";
|
|
+ write_str_to_file(fname, header_lines_v100, 0);
|
|
-
|
|
+ bw_file_headers = smartlist_new();
|
|
- tor_asprintf(&content, "%ld\n%s%s", (long)timestamp, v110_header_lines,
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
- torflow_relay_lines);
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v100, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s", header_lines_v100, relay_lines_v100);
|
|
write_str_to_file(fname, content, 0);
|
|
write_str_to_file(fname, content, 0);
|
|
tor_free(content);
|
|
tor_free(content);
|
|
- tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
-
|
|
+ bw_file_headers));
|
|
-
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
- tor_asprintf(&content, "%ld\n%s%s", (long)timestamp, torflow_relay_lines,
|
|
+ tt_str_op(bw_file_headers_str_v100, OP_EQ, bw_file_headers_str);
|
|
- v110_header_lines);
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ tor_asprintf(&content, "%s%s", header_lines_v100, relay_lines_v100);
|
|
write_str_to_file(fname, content, 0);
|
|
write_str_to_file(fname, content, 0);
|
|
tor_free(content);
|
|
tor_free(content);
|
|
- tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL, NULL));
|
|
|
|
|
|
-
|
|
+
|
|
- * bw lines after the headers. */
|
|
+ * v1.0.0 relay lines. bw_file_headers will contain the v1.1.0 headers. */
|
|
- tor_asprintf(&content, "%ld\n%s%s%s", (long)timestamp, torflow_relay_lines,
|
|
+ bw_file_headers = smartlist_new();
|
|
- v110_header_lines, torflow_relay_lines);
|
|
+ tor_asprintf(&content, "%s%s%s", header_lines_v100, header_lines_v110,
|
|
|
|
+ relay_lines_v100);
|
|
write_str_to_file(fname, content, 0);
|
|
write_str_to_file(fname, content, 0);
|
|
tor_free(content);
|
|
tor_free(content);
|
|
- tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
-
|
|
+ bw_file_headers));
|
|
-
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
- const char *sbws_relay_lines=
|
|
+ tt_str_op(bw_file_headers_str_v110, OP_EQ, bw_file_headers_str);
|
|
- "node_id=$68A483E05A2ABDCA6DA5A3EF8DB5177638A27F80 "
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
- "master_key_ed25519=YaqV4vbvPYKucElk297eVdNArDz9HtIwUoIeo0+cVIpQ "
|
|
+ smartlist_free(bw_file_headers);
|
|
- "bw=760 nick=Test rtt=380 time=2018-05-08T16:13:26\n";
|
|
+ tor_free(bw_file_headers_str);
|
|
-
|
|
+
|
|
- tor_asprintf(&content, "%ld\n%s%s", (long)timestamp, v110_header_lines,
|
|
+
|
|
- sbws_relay_lines);
|
|
+ * bw_file_headers will contain only v1.0.0 headers and the additional
|
|
|
|
+ * headers will be interpreted as malformed relay lines. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s%s", header_lines_v100, relay_lines_v100,
|
|
|
|
+ header_lines_v110);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v100, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * lines. bw_file_headers will contain only v1.0.0 headers, the additional
|
|
|
|
+ * headers will be interpreted as malformed relay lines and the last relay
|
|
|
|
+ * lines will be correctly interpreted as relay lines. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s%s%s", header_lines_v100, relay_lines_v100,
|
|
|
|
+ header_lines_v110, relay_lines_v100);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v100, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ write_str_to_file(fname, header_lines_v110_no_terminator, 0);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v110, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ write_str_to_file(fname, header_lines_v110, 0);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v110, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * bw_file_headers will contain the v1.1.0 headers. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s",
|
|
|
|
+ header_lines_v110_no_terminator, relay_lines_v110);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v110, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * bw_file_headers will contain the v1.1.0 headers. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s",
|
|
|
|
+ header_lines_v110, relay_lines_v110);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v110, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * then terminator, then relay_lines_bad.
|
|
|
|
+ * bw_file_headers will contain the v1.1.0 headers. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s%s%s", header_lines_v110, relay_lines_bad,
|
|
|
|
+ BW_FILE_HEADERS_TERMINATOR, relay_lines_bad);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_v110, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * then relay lines. bw_file_headers will contain the v1.1.0 headers and
|
|
|
|
+ * the bad relay lines. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s%s",
|
|
|
|
+ header_lines_v110_no_terminator, relay_lines_bad,
|
|
|
|
+ relay_lines_v110);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_bad, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * then many bad relay lines, then relay lines.
|
|
|
|
+ * bw_file_headers will contain the v1.1.0 headers and the bad relay lines
|
|
|
|
+ * to a maximum of MAX_BW_FILE_HEADER_COUNT_IN_VOTE header lines. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s%s",
|
|
|
|
+ header_lines_v110_no_terminator, header_lines_long,
|
|
|
|
+ relay_lines_v110);
|
|
|
|
+ write_str_to_file(fname, content, 0);
|
|
|
|
+ tor_free(content);
|
|
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ tt_int_op(MAX_BW_FILE_HEADER_COUNT_IN_VOTE, OP_EQ,
|
|
|
|
+ smartlist_len(bw_file_headers));
|
|
|
|
+ bw_file_headers_str = smartlist_join_strings(bw_file_headers, " ", 0, NULL);
|
|
|
|
+ tt_str_op(bw_file_headers_str_extra, OP_EQ, bw_file_headers_str);
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * then many bad relay lines, then relay lines.
|
|
|
|
+ * bw_file_headers will contain the v1.1.0 headers and the bad relay lines.
|
|
|
|
+ * Force bw_file_headers to have more than MAX_BW_FILE_HEADER_COUNT_IN_VOTE
|
|
|
|
+ * This test is needed while there is not dirvote test. */
|
|
|
|
+ bw_file_headers = smartlist_new();
|
|
|
|
+ tor_asprintf(&content, "%s%s%s",
|
|
|
|
+ header_lines_v110_no_terminator, header_lines_long,
|
|
|
|
+ relay_lines_v110);
|
|
write_str_to_file(fname, content, 0);
|
|
write_str_to_file(fname, content, 0);
|
|
tor_free(content);
|
|
tor_free(content);
|
|
- tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL));
|
|
+ tt_int_op(0, OP_EQ, dirserv_read_measured_bandwidths(fname, NULL,
|
|
|
|
+ bw_file_headers));
|
|
|
|
+ tt_int_op(MAX_BW_FILE_HEADER_COUNT_IN_VOTE, OP_EQ,
|
|
|
|
+ smartlist_len(bw_file_headers));
|
|
|
|
+
|
|
|
|
+ * MAX_BW_FILE_HEADER_COUNT_IN_VOTE */
|
|
|
|
+ char line[8] = "foo=bar\0";
|
|
|
|
+ smartlist_add_strdup(bw_file_headers, line);
|
|
|
|
+ tt_int_op(MAX_BW_FILE_HEADER_COUNT_IN_VOTE, OP_LT,
|
|
|
|
+ smartlist_len(bw_file_headers));
|
|
|
|
+ SMARTLIST_FOREACH(bw_file_headers, char *, c, tor_free(c));
|
|
|
|
+ smartlist_free(bw_file_headers);
|
|
|
|
+ tor_free(bw_file_headers_str);
|
|
|
|
|
|
done:
|
|
done:
|
|
tor_free(fname);
|
|
tor_free(fname);
|
|
|
|
+ tor_free(header_lines_v100);
|
|
|
|
+ tor_free(header_lines_v110_no_terminator);
|
|
|
|
+ tor_free(header_lines_v110);
|
|
|
|
+ tor_free(bw_file_headers_str_v100);
|
|
|
|
+ tor_free(bw_file_headers_str_v110);
|
|
|
|
+ tor_free(bw_file_headers_str_bad);
|
|
|
|
+ tor_free(bw_file_headers_str_extra);
|
|
}
|
|
}
|
|
|
|
|
|
#define MBWC_INIT_TIME 1000
|
|
#define MBWC_INIT_TIME 1000
|
|
@@ -6053,7 +6279,6 @@ struct testcase_t dir_tests[] = {
|
|
DIR_LEGACY(versions),
|
|
DIR_LEGACY(versions),
|
|
DIR_LEGACY(fp_pairs),
|
|
DIR_LEGACY(fp_pairs),
|
|
DIR(split_fps, 0),
|
|
DIR(split_fps, 0),
|
|
- DIR_LEGACY(dirserv_read_measured_bandwidths_empty),
|
|
|
|
DIR_LEGACY(measured_bw_kb),
|
|
DIR_LEGACY(measured_bw_kb),
|
|
DIR_LEGACY(measured_bw_kb_line_is_after_headers),
|
|
DIR_LEGACY(measured_bw_kb_line_is_after_headers),
|
|
DIR_LEGACY(measured_bw_kb_cache),
|
|
DIR_LEGACY(measured_bw_kb_cache),
|