aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dirauth
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/dirauth
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/dirauth')
-rw-r--r--src/feature/dirauth/dirvote.c44
-rw-r--r--src/feature/dirauth/dirvote.h3
2 files changed, 42 insertions, 5 deletions
diff --git a/src/feature/dirauth/dirvote.c b/src/feature/dirauth/dirvote.c
index 2a48a32834..6477f34baf 100644
--- a/src/feature/dirauth/dirvote.c
+++ b/src/feature/dirauth/dirvote.c
@@ -255,6 +255,7 @@ format_networkstatus_vote(crypto_pk_t *private_signing_key,
/* XXXX Abstraction violation: should be pulling a field out of v3_ns.*/
char *flag_thresholds = dirserv_get_flag_thresholds_line();
char *params;
+ char *bw_headers_line = NULL;
authority_cert_t *cert = v3_ns->cert;
char *methods =
make_consensus_method_list(MIN_SUPPORTED_CONSENSUS_METHOD,
@@ -268,8 +269,32 @@ format_networkstatus_vote(crypto_pk_t *private_signing_key,
params = smartlist_join_strings(v3_ns->net_params, " ", 0, NULL);
else
params = tor_strdup("");
-
tor_assert(cert);
+
+ /* v3_ns->bw_file_headers is only set when V3BandwidthsFile is
+ * configured */
+ if (v3_ns->bw_file_headers) {
+ char *bw_file_headers = NULL;
+ /* If there are too many headers, leave the header string NULL */
+ if (! BUG(smartlist_len(v3_ns->bw_file_headers)
+ > MAX_BW_FILE_HEADER_COUNT_IN_VOTE)) {
+ bw_file_headers = smartlist_join_strings(v3_ns->bw_file_headers, " ",
+ 0, NULL);
+ if (BUG(strlen(bw_file_headers) > MAX_BW_FILE_HEADERS_LINE_LEN)) {
+ /* Free and set to NULL, because the line was too long */
+ tor_free(bw_file_headers);
+ }
+ }
+ if (!bw_file_headers) {
+ /* If parsing failed, add a bandwidth header line with no entries */
+ bw_file_headers = tor_strdup("");
+ }
+ /* At this point, the line will always be present */
+ bw_headers_line = format_line_if_present("bandwidth-file-headers",
+ bw_file_headers);
+ tor_free(bw_file_headers);
+ }
+
smartlist_add_asprintf(chunks,
"network-status-version 3\n"
"vote-status %s\n"
@@ -287,7 +312,9 @@ format_networkstatus_vote(crypto_pk_t *private_signing_key,
"params %s\n"
"dir-source %s %s %s %s %d %d\n"
"contact %s\n"
- "%s", /* shared randomness information */
+ "%s" /* shared randomness information */
+ "%s" /* bandwidth file headers */
+ ,
v3_ns->type == NS_TYPE_VOTE ? "vote" : "opinion",
methods,
published, va, fu, vu,
@@ -303,13 +330,16 @@ format_networkstatus_vote(crypto_pk_t *private_signing_key,
fmt_addr32(addr), voter->dir_port, voter->or_port,
voter->contact,
shared_random_vote_str ?
- shared_random_vote_str : "");
+ shared_random_vote_str : "",
+ bw_headers_line ?
+ bw_headers_line : "");
tor_free(params);
tor_free(flags);
tor_free(flag_thresholds);
tor_free(methods);
tor_free(shared_random_vote_str);
+ tor_free(bw_headers_line);
if (!tor_digest_is_zero(voter->legacy_id_digest)) {
char fpbuf[HEX_DIGEST_LEN+1];
@@ -4343,6 +4373,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
digestmap_t *omit_as_sybil = NULL;
const int vote_on_reachability = running_long_enough_to_decide_unreachable();
smartlist_t *microdescriptors = NULL;
+ smartlist_t *bw_file_headers = NULL;
tor_assert(private_key);
tor_assert(cert);
@@ -4380,7 +4411,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
* set_routerstatus_from_routerinfo() see up-to-date bandwidth info.
*/
if (options->V3BandwidthsFile) {
- dirserv_read_measured_bandwidths(options->V3BandwidthsFile, NULL);
+ dirserv_read_measured_bandwidths(options->V3BandwidthsFile, NULL, NULL);
} else {
/*
* No bandwidths file; clear the measured bandwidth cache in case we had
@@ -4482,8 +4513,10 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
/* This pass through applies the measured bw lines to the routerstatuses */
if (options->V3BandwidthsFile) {
+ /* Only set bw_file_headers when V3BandwidthsFile is configured */
+ bw_file_headers = smartlist_new();
dirserv_read_measured_bandwidths(options->V3BandwidthsFile,
- routerstatuses);
+ routerstatuses, bw_file_headers);
} else {
/*
* No bandwidths file; clear the measured bandwidth cache in case we had
@@ -4579,6 +4612,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
options->ConsensusParams, NULL, 0, 0);
smartlist_sort_strings(v3_out->net_params);
}
+ v3_out->bw_file_headers = bw_file_headers;
voter = tor_malloc_zero(sizeof(networkstatus_voter_info_t));
voter->nickname = tor_strdup(options->Nickname);
diff --git a/src/feature/dirauth/dirvote.h b/src/feature/dirauth/dirvote.h
index 7ce8e4a699..979a2be8a6 100644
--- a/src/feature/dirauth/dirvote.h
+++ b/src/feature/dirauth/dirvote.h
@@ -89,6 +89,9 @@
#define DGV_INCLUDE_PENDING 2
#define DGV_INCLUDE_PREVIOUS 4
+/** Maximum size of a line in a vote. */
+#define MAX_BW_FILE_HEADERS_LINE_LEN 1024
+
/*
* Public API. Used outside of the dirauth subsystem.
*