aboutsummaryrefslogtreecommitdiff
path: root/src/or/dirvote.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/dirvote.c')
-rw-r--r--src/or/dirvote.c232
1 files changed, 104 insertions, 128 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index ab08fd0200..cddb658244 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -53,7 +53,7 @@ static int dirvote_publish_consensus(void);
static char *make_consensus_method_list(int low, int high, const char *sep);
/** The highest consensus method that we currently support. */
-#define MAX_SUPPORTED_CONSENSUS_METHOD 11
+#define MAX_SUPPORTED_CONSENSUS_METHOD 12
/** Lowest consensus method that contains a 'directory-footer' marker */
#define MIN_METHOD_FOR_FOOTER 9
@@ -67,6 +67,10 @@ static char *make_consensus_method_list(int low, int high, const char *sep);
/** Lowest consensus method that generates microdescriptors */
#define MIN_METHOD_FOR_MICRODESC 8
+/** Lowest consensus method that ensures a majority of authorities voted
+ * for a param. */
+#define MIN_METHOD_FOR_MAJORITY_PARAMS 12
+
/* =====
* Voting
* =====*/
@@ -78,7 +82,7 @@ static char *make_consensus_method_list(int low, int high, const char *sep);
* <b>v3_ns</b>, signed with our v3 signing key <b>private_signing_key</b>.
* For v3 authorities. */
char *
-format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
+format_networkstatus_vote(crypto_pk_t *private_signing_key,
networkstatus_t *v3_ns)
{
size_t len;
@@ -86,9 +90,7 @@ format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
const char *client_versions = NULL, *server_versions = NULL;
char *outp, *endp;
char fingerprint[FINGERPRINT_LEN+1];
- char ipaddr[INET_NTOA_BUF_LEN];
char digest[DIGEST_LEN];
- struct in_addr in;
uint32_t addr;
routerlist_t *rl = router_get_routerlist();
char *version_lines = NULL;
@@ -101,8 +103,6 @@ format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
voter = smartlist_get(v3_ns->voters, 0);
addr = voter->addr;
- in.s_addr = htonl(addr);
- tor_inet_ntoa(&in, ipaddr, sizeof(ipaddr));
base16_encode(fingerprint, sizeof(fingerprint),
v3_ns->cert->cache_info.identity_digest, DIGEST_LEN);
@@ -189,7 +189,8 @@ format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
flags,
params,
voter->nickname, fingerprint, voter->address,
- ipaddr, voter->dir_port, voter->or_port, voter->contact);
+ fmt_addr32(addr), voter->dir_port, voter->or_port,
+ voter->contact);
if (r < 0) {
log_err(LD_BUG, "Insufficient memory for network status line");
@@ -471,7 +472,7 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
if (consensus_method >= MIN_METHOD_FOR_MICRODESC &&
microdesc_digest256_out) {
- smartlist_t *digests = smartlist_create();
+ smartlist_t *digests = smartlist_new();
const char *best_microdesc_digest;
SMARTLIST_FOREACH_BEGIN(votes, vote_routerstatus_t *, rs) {
char d[DIGEST256_LEN];
@@ -499,15 +500,15 @@ static void
hash_list_members(char *digest_out, size_t len_out,
smartlist_t *lst, digest_algorithm_t alg)
{
- crypto_digest_env_t *d;
+ crypto_digest_t *d;
if (alg == DIGEST_SHA1)
- d = crypto_new_digest_env();
+ d = crypto_digest_new();
else
- d = crypto_new_digest256_env(alg);
+ d = crypto_digest256_new(alg);
SMARTLIST_FOREACH(lst, const char *, cp,
crypto_digest_add_bytes(d, cp, strlen(cp)));
crypto_digest_get_digest(d, digest_out, len_out);
- crypto_free_digest_env(d);
+ crypto_digest_free(d);
}
/** Sorting helper: compare two strings based on their values as base-ten
@@ -535,9 +536,9 @@ _cmp_int_strings(const void **_a, const void **_b)
static int
compute_consensus_method(smartlist_t *votes)
{
- smartlist_t *all_methods = smartlist_create();
- smartlist_t *acceptable_methods = smartlist_create();
- smartlist_t *tmp = smartlist_create();
+ smartlist_t *all_methods = smartlist_new();
+ smartlist_t *acceptable_methods = smartlist_new();
+ smartlist_t *tmp = smartlist_new();
int min = (smartlist_len(votes) * 2) / 3;
int n_ok;
int result;
@@ -580,15 +581,13 @@ make_consensus_method_list(int low, int high, const char *separator)
{
char *list;
- char b[32];
int i;
smartlist_t *lst;
- lst = smartlist_create();
+ lst = smartlist_new();
for (i = low; i <= high; ++i) {
if (!consensus_method_is_supported(i))
continue;
- tor_snprintf(b, sizeof(b), "%d", i);
- smartlist_add(lst, tor_strdup(b));
+ smartlist_add_asprintf(lst, "%d", i);
}
list = smartlist_join_strings(lst, separator, 0, NULL);
tor_assert(list);
@@ -605,7 +604,7 @@ static char *
compute_consensus_versions_list(smartlist_t *lst, int n_versioning)
{
int min = n_versioning / 2;
- smartlist_t *good = smartlist_create();
+ smartlist_t *good = smartlist_new();
char *result;
sort_version_list(lst, 0);
get_frequent_members(good, lst, min);
@@ -614,11 +613,16 @@ compute_consensus_versions_list(smartlist_t *lst, int n_versioning)
return result;
}
+/** Minimum number of directory authorities voting for a parameter to
+ * include it in the consensus, if consensus method 12 or later is to be
+ * used. See proposal 178 for details. */
+#define MIN_VOTES_FOR_PARAM 3
+
/** Helper: given a list of valid networkstatus_t, return a new string
* containing the contents of the consensus network parameter set.
*/
/* private */ char *
-dirvote_compute_params(smartlist_t *votes)
+dirvote_compute_params(smartlist_t *votes, int method, int total_authorities)
{
int i;
int32_t *vals;
@@ -630,7 +634,7 @@ dirvote_compute_params(smartlist_t *votes)
const int n_votes = smartlist_len(votes);
smartlist_t *output;
- smartlist_t *param_list = smartlist_create();
+ smartlist_t *param_list = smartlist_new();
/* We require that the parameter lists in the votes are well-formed: that
is, that their keywords are unique and sorted, and that their values are
@@ -658,7 +662,7 @@ dirvote_compute_params(smartlist_t *votes)
tor_assert(eq);
cur_param_len = (int)(eq+1 - cur_param);
- output = smartlist_create();
+ output = smartlist_new();
SMARTLIST_FOREACH_BEGIN(param_list, const char *, param) {
const char *next_param;
@@ -675,11 +679,17 @@ dirvote_compute_params(smartlist_t *votes)
next_param = smartlist_get(param_list, param_sl_idx+1);
if (!next_param || strncmp(next_param, param, cur_param_len)) {
/* We've reached the end of a series. */
- int32_t median = median_int32(vals, i);
- char *out_string = tor_malloc(64+cur_param_len);
- memcpy(out_string, param, cur_param_len);
- tor_snprintf(out_string+cur_param_len,64, "%ld", (long)median);
- smartlist_add(output, out_string);
+ /* Make sure enough authorities voted on this param, unless the
+ * the consensus method we use is too old for that. */
+ if (method < MIN_METHOD_FOR_MAJORITY_PARAMS ||
+ i > total_authorities/2 ||
+ i >= MIN_VOTES_FOR_PARAM) {
+ int32_t median = median_int32(vals, i);
+ char *out_string = tor_malloc(64+cur_param_len);
+ memcpy(out_string, param, cur_param_len);
+ tor_snprintf(out_string+cur_param_len,64, "%ld", (long)median);
+ smartlist_add(output, out_string);
+ }
i = 0;
if (next_param) {
@@ -798,8 +808,6 @@ networkstatus_compute_bw_weights_v10(smartlist_t *chunks, int64_t G,
int64_t Wmg = -1, Wme = -1, Wmd = -1;
int64_t Wed = -1, Wee = -1;
const char *casename;
- char buf[512];
- int r;
if (G <= 0 || M <= 0 || E <= 0 || D <= 0) {
log_warn(LD_DIR, "Consensus with empty bandwidth: "
@@ -1007,7 +1015,7 @@ networkstatus_compute_bw_weights_v10(smartlist_t *chunks, int64_t G,
*
* NOTE: This list is sorted.
*/
- r = tor_snprintf(buf, sizeof(buf),
+ smartlist_add_asprintf(chunks,
"bandwidth-weights Wbd=%d Wbe=%d Wbg=%d Wbm=%d "
"Wdb=%d "
"Web=%d Wed=%d Wee=%d Weg=%d Wem=%d "
@@ -1018,13 +1026,6 @@ networkstatus_compute_bw_weights_v10(smartlist_t *chunks, int64_t G,
(int)weight_scale, (int)Wed, (int)Wee, (int)Wed, (int)Wee,
(int)weight_scale, (int)Wgd, (int)Wgg, (int)Wgg,
(int)weight_scale, (int)Wmd, (int)Wme, (int)Wmg, (int)weight_scale);
- if (r<0) {
- log_warn(LD_BUG,
- "Not enough space in buffer for bandwidth-weights line.");
- *buf = '\0';
- return 0;
- }
- smartlist_add(chunks, tor_strdup(buf));
log_notice(LD_CIRC, "Computed bandwidth weights for %s with v10: "
"G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT
@@ -1048,8 +1049,6 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M,
int64_t Wmg = -1, Wme = -1, Wmd = -1;
int64_t Wed = -1, Wee = -1;
const char *casename;
- char buf[512];
- int r;
if (G <= 0 || M <= 0 || E <= 0 || D <= 0) {
log_warn(LD_DIR, "Consensus with empty bandwidth: "
@@ -1311,7 +1310,7 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M,
*
* NOTE: This list is sorted.
*/
- r = tor_snprintf(buf, sizeof(buf),
+ smartlist_add_asprintf(chunks,
"Wbd=%d Wbe=%d Wbg=%d Wbm=%d "
"Wdb=%d "
"Web=%d Wed=%d Wee=%d Weg=%d Wem=%d "
@@ -1322,12 +1321,7 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M,
(int)weight_scale, (int)Wed, (int)Wee, (int)Wed, (int)Wee,
(int)weight_scale, (int)Wgd, (int)Wgg, (int)Wgg,
(int)weight_scale, (int)Wmd, (int)Wme, (int)Wmg, (int)weight_scale);
- if (r<0) {
- log_warn(LD_BUG,
- "Not enough space in buffer for bandwidth-weights line.");
- *buf = '\0';
- }
- smartlist_add(chunks, tor_strdup(buf));
+
log_notice(LD_CIRC, "Computed bandwidth weights for %s with v9: "
"G="I64_FORMAT" M="I64_FORMAT" E="I64_FORMAT" D="I64_FORMAT
" T="I64_FORMAT,
@@ -1347,10 +1341,10 @@ networkstatus_compute_bw_weights_v9(smartlist_t *chunks, int64_t G, int64_t M,
char *
networkstatus_compute_consensus(smartlist_t *votes,
int total_authorities,
- crypto_pk_env_t *identity_key,
- crypto_pk_env_t *signing_key,
+ crypto_pk_t *identity_key,
+ crypto_pk_t *signing_key,
const char *legacy_id_key_digest,
- crypto_pk_env_t *legacy_signing_key,
+ crypto_pk_t *legacy_signing_key,
consensus_flavor_t flavor)
{
smartlist_t *chunks;
@@ -1375,7 +1369,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
log_warn(LD_DIR, "Can't compute a consensus from no votes.");
return NULL;
}
- flags = smartlist_create();
+ flags = smartlist_new();
consensus_method = compute_consensus_method(votes);
if (consensus_method_is_supported(consensus_method)) {
@@ -1398,8 +1392,8 @@ networkstatus_compute_consensus(smartlist_t *votes,
int *votesec_list = tor_malloc(n_votes * sizeof(int));
int *distsec_list = tor_malloc(n_votes * sizeof(int));
int n_versioning_clients = 0, n_versioning_servers = 0;
- smartlist_t *combined_client_versions = smartlist_create();
- smartlist_t *combined_server_versions = smartlist_create();
+ smartlist_t *combined_client_versions = smartlist_new();
+ smartlist_t *combined_server_versions = smartlist_new();
SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
tor_assert(v->type == NS_TYPE_VOTE);
@@ -1409,7 +1403,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
votesec_list[v_sl_idx] = v->vote_seconds;
distsec_list[v_sl_idx] = v->dist_seconds;
if (v->client_versions) {
- smartlist_t *cv = smartlist_create();
+ smartlist_t *cv = smartlist_new();
++n_versioning_clients;
smartlist_split_string(cv, v->client_versions, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@@ -1418,7 +1412,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_free(cv); /* elements get freed later. */
}
if (v->server_versions) {
- smartlist_t *sv = smartlist_create();
+ smartlist_t *sv = smartlist_new();
++n_versioning_servers;
smartlist_split_string(sv, v->server_versions, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
@@ -1460,10 +1454,9 @@ networkstatus_compute_consensus(smartlist_t *votes,
tor_free(distsec_list);
}
- chunks = smartlist_create();
+ chunks = smartlist_new();
{
- char *buf=NULL;
char va_buf[ISO_TIME_LEN+1], fu_buf[ISO_TIME_LEN+1],
vu_buf[ISO_TIME_LEN+1];
char *flaglist;
@@ -1472,20 +1465,17 @@ networkstatus_compute_consensus(smartlist_t *votes,
format_iso_time(vu_buf, valid_until);
flaglist = smartlist_join_strings(flags, " ", 0, NULL);
- tor_asprintf(&buf, "network-status-version 3%s%s\n"
+ smartlist_add_asprintf(chunks, "network-status-version 3%s%s\n"
"vote-status consensus\n",
flavor == FLAV_NS ? "" : " ",
flavor == FLAV_NS ? "" : flavor_name);
- smartlist_add(chunks, buf);
-
if (consensus_method >= 2) {
- tor_asprintf(&buf, "consensus-method %d\n",
+ smartlist_add_asprintf(chunks, "consensus-method %d\n",
consensus_method);
- smartlist_add(chunks, buf);
}
- tor_asprintf(&buf,
+ smartlist_add_asprintf(chunks,
"valid-after %s\n"
"fresh-until %s\n"
"valid-until %s\n"
@@ -1496,13 +1486,13 @@ networkstatus_compute_consensus(smartlist_t *votes,
va_buf, fu_buf, vu_buf,
vote_seconds, dist_seconds,
client_versions, server_versions, flaglist);
- smartlist_add(chunks, buf);
tor_free(flaglist);
}
if (consensus_method >= MIN_METHOD_FOR_PARAMS) {
- params = dirvote_compute_params(votes);
+ params = dirvote_compute_params(votes, consensus_method,
+ total_authorities);
if (params) {
smartlist_add(chunks, tor_strdup("params "));
smartlist_add(chunks, params);
@@ -1514,7 +1504,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_sort(votes, _compare_votes_by_authority_id);
/* Add the authority sections. */
{
- smartlist_t *dir_sources = smartlist_create();
+ smartlist_t *dir_sources = smartlist_new();
SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
dir_src_ent_t *e = tor_malloc_zero(sizeof(dir_src_ent_t));
e->v = v;
@@ -1533,37 +1523,30 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_sort(dir_sources, _compare_dir_src_ents_by_authority_id);
SMARTLIST_FOREACH_BEGIN(dir_sources, const dir_src_ent_t *, e) {
- struct in_addr in;
- char ip[INET_NTOA_BUF_LEN];
char fingerprint[HEX_DIGEST_LEN+1];
char votedigest[HEX_DIGEST_LEN+1];
networkstatus_t *v = e->v;
networkstatus_voter_info_t *voter = get_voter(v);
- char *buf = NULL;
if (e->is_legacy)
tor_assert(consensus_method >= 2);
- in.s_addr = htonl(voter->addr);
- tor_inet_ntoa(&in, ip, sizeof(ip));
base16_encode(fingerprint, sizeof(fingerprint), e->digest, DIGEST_LEN);
base16_encode(votedigest, sizeof(votedigest), voter->vote_digest,
DIGEST_LEN);
- tor_asprintf(&buf,
+ smartlist_add_asprintf(chunks,
"dir-source %s%s %s %s %s %d %d\n",
voter->nickname, e->is_legacy ? "-legacy" : "",
- fingerprint, voter->address, ip,
+ fingerprint, voter->address, fmt_addr32(voter->addr),
voter->dir_port,
voter->or_port);
- smartlist_add(chunks, buf);
if (! e->is_legacy) {
- tor_asprintf(&buf,
+ smartlist_add_asprintf(chunks,
"contact %s\n"
"vote-digest %s\n",
voter->contact,
votedigest);
- smartlist_add(chunks, buf);
}
} SMARTLIST_FOREACH_END(e);
SMARTLIST_FOREACH(dir_sources, dir_src_ent_t *, e, tor_free(e));
@@ -1577,10 +1560,10 @@ networkstatus_compute_consensus(smartlist_t *votes,
int *flag_counts; /* The number of voters that list flag[j] for the
* currently considered router. */
int i;
- smartlist_t *matching_descs = smartlist_create();
- smartlist_t *chosen_flags = smartlist_create();
- smartlist_t *versions = smartlist_create();
- smartlist_t *exitsummaries = smartlist_create();
+ smartlist_t *matching_descs = smartlist_new();
+ smartlist_t *chosen_flags = smartlist_new();
+ smartlist_t *versions = smartlist_new();
+ smartlist_t *exitsummaries = smartlist_new();
uint32_t *bandwidths = tor_malloc(sizeof(uint32_t) * smartlist_len(votes));
uint32_t *measured_bws = tor_malloc(sizeof(uint32_t) *
smartlist_len(votes));
@@ -1700,7 +1683,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
int naming_conflict = 0;
int n_listing = 0;
int i;
- char *buf=NULL;
char microdesc_digest[DIGEST256_LEN];
/* Of the next-to-be-considered digest in each voter, which is first? */
@@ -1968,10 +1950,9 @@ networkstatus_compute_consensus(smartlist_t *votes,
/* Now an m line, if applicable. */
if (flavor == FLAV_MICRODESC &&
!tor_digest256_is_zero(microdesc_digest)) {
- char m[BASE64_DIGEST256_LEN+1], *cp;
+ char m[BASE64_DIGEST256_LEN+1];
digest256_to_base64(m, microdesc_digest);
- tor_asprintf(&cp, "m %s\n", m);
- smartlist_add(chunks, cp);
+ smartlist_add_asprintf(chunks, "m %s\n", m);
}
/* Next line is all flags. The "\n" is missing. */
smartlist_add(chunks,
@@ -1984,15 +1965,12 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_add(chunks, tor_strdup("\n"));
/* Now the weight line. */
if (rs_out.has_bandwidth) {
- char *cp=NULL;
- tor_asprintf(&cp, "w Bandwidth=%d\n", rs_out.bandwidth);
- smartlist_add(chunks, cp);
+ smartlist_add_asprintf(chunks, "w Bandwidth=%d\n", rs_out.bandwidth);
}
/* Now the exitpolicy summary line. */
if (rs_out.has_exitsummary && flavor == FLAV_NS) {
- tor_asprintf(&buf, "p %s\n", rs_out.exitsummary);
- smartlist_add(chunks, buf);
+ smartlist_add_asprintf(chunks, "p %s\n", rs_out.exitsummary);
}
/* And the loop is over and we move on to the next router */
@@ -2074,7 +2052,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
size_t digest_len =
flavor == FLAV_NS ? DIGEST_LEN : DIGEST256_LEN;
const char *algname = crypto_digest_algorithm_get_name(digest_alg);
- char *buf = NULL;
char sigbuf[4096];
smartlist_add(chunks, tor_strdup("directory-signature "));
@@ -2088,14 +2065,13 @@ networkstatus_compute_consensus(smartlist_t *votes,
/* add the junk that will go at the end of the line. */
if (flavor == FLAV_NS) {
- tor_asprintf(&buf, "%s %s\n", fingerprint,
+ smartlist_add_asprintf(chunks, "%s %s\n", fingerprint,
signing_key_fingerprint);
} else {
- tor_asprintf(&buf, "%s %s %s\n",
+ smartlist_add_asprintf(chunks, "%s %s %s\n",
algname, fingerprint,
signing_key_fingerprint);
}
- smartlist_add(chunks, buf);
/* And the signature. */
sigbuf[0] = '\0';
if (router_append_dirobj_signature(sigbuf, sizeof(sigbuf),
@@ -2113,14 +2089,13 @@ networkstatus_compute_consensus(smartlist_t *votes,
crypto_pk_get_fingerprint(legacy_signing_key,
signing_key_fingerprint, 0);
if (flavor == FLAV_NS) {
- tor_asprintf(&buf, "%s %s\n", fingerprint,
+ smartlist_add_asprintf(chunks, "%s %s\n", fingerprint,
signing_key_fingerprint);
} else {
- tor_asprintf(&buf, "%s %s %s\n",
+ smartlist_add_asprintf(chunks, "%s %s %s\n",
algname, fingerprint,
signing_key_fingerprint);
}
- smartlist_add(chunks, buf);
sigbuf[0] = '\0';
if (router_append_dirobj_signature(sigbuf, sizeof(sigbuf),
digest, digest_len,
@@ -2313,7 +2288,7 @@ networkstatus_format_signatures(networkstatus_t *consensus,
else
keyword = "directory-signature";
- elements = smartlist_create();
+ elements = smartlist_new();
SMARTLIST_FOREACH_BEGIN(consensus->voters, networkstatus_voter_info_t *, v) {
SMARTLIST_FOREACH_BEGIN(v->sigs, document_signature_t *, sig) {
@@ -2325,20 +2300,19 @@ networkstatus_format_signatures(networkstatus_t *consensus,
base16_encode(sk, sizeof(sk), sig->signing_key_digest, DIGEST_LEN);
base16_encode(id, sizeof(id), sig->identity_digest, DIGEST_LEN);
if (flavor == FLAV_NS) {
- tor_snprintf(buf, sizeof(buf),
+ smartlist_add_asprintf(elements,
"%s %s %s\n-----BEGIN SIGNATURE-----\n",
keyword, id, sk);
} else {
const char *digest_name =
crypto_digest_algorithm_get_name(sig->alg);
- tor_snprintf(buf, sizeof(buf),
+ smartlist_add_asprintf(elements,
"%s%s%s %s %s %s\n-----BEGIN SIGNATURE-----\n",
keyword,
for_detached_signatures ? " " : "",
for_detached_signatures ? flavor_name : "",
digest_name, id, sk);
}
- smartlist_add(elements, tor_strdup(buf));
base64_encode(buf, sizeof(buf), sig->signature, sig->signature_len);
strlcat(buf, "-----END SIGNATURE-----\n", sizeof(buf));
smartlist_add(elements, tor_strdup(buf));
@@ -2361,7 +2335,6 @@ char *
networkstatus_get_detached_signatures(smartlist_t *consensuses)
{
smartlist_t *elements;
- char buf[4096];
char *result = NULL, *sigs = NULL;
networkstatus_t *consensus_ns = NULL;
tor_assert(consensuses);
@@ -2377,7 +2350,7 @@ networkstatus_get_detached_signatures(smartlist_t *consensuses)
return NULL;
}
- elements = smartlist_create();
+ elements = smartlist_new();
{
char va_buf[ISO_TIME_LEN+1], fu_buf[ISO_TIME_LEN+1],
@@ -2390,12 +2363,11 @@ networkstatus_get_detached_signatures(smartlist_t *consensuses)
format_iso_time(fu_buf, consensus_ns->fresh_until);
format_iso_time(vu_buf, consensus_ns->valid_until);
- tor_snprintf(buf, sizeof(buf),
+ smartlist_add_asprintf(elements,
"consensus-digest %s\n"
"valid-after %s\n"
"fresh-until %s\n"
"valid-until %s\n", d, va_buf, fu_buf, vu_buf);
- smartlist_add(elements, tor_strdup(buf));
}
/* Get all the digests for the non-FLAV_NS consensuses */
@@ -2414,9 +2386,8 @@ networkstatus_get_detached_signatures(smartlist_t *consensuses)
if (tor_mem_is_zero(ns->digests.d[alg], DIGEST256_LEN))
continue;
base16_encode(d, sizeof(d), ns->digests.d[alg], DIGEST256_LEN);
- tor_snprintf(buf, sizeof(buf), "additional-digest %s %s %s\n",
+ smartlist_add_asprintf(elements, "additional-digest %s %s %s\n",
flavor_name, alg_name, d);
- smartlist_add(elements, tor_strdup(buf));
}
} SMARTLIST_FOREACH_END(ns);
@@ -2455,7 +2426,7 @@ get_detached_signatures_from_pending_consensuses(pending_consensus_t *pending,
{
int flav;
char *signatures;
- smartlist_t *c = smartlist_create();
+ smartlist_t *c = smartlist_new();
for (flav = 0; flav < n_flavors; ++flav) {
if (pending[flav].consensus)
smartlist_add(c, pending[flav].consensus);
@@ -2518,7 +2489,7 @@ authority_cert_dup(authority_cert_t *cert)
void
dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out)
{
- or_options_t *options = get_options();
+ const or_options_t *options = get_options();
tor_assert(timing_out);
@@ -2592,7 +2563,7 @@ static struct {
/** Set voting_schedule to hold the timing for the next vote we should be
* doing. */
void
-dirvote_recalculate_timing(or_options_t *options, time_t now)
+dirvote_recalculate_timing(const or_options_t *options, time_t now)
{
int interval, vote_delay, dist_delay;
time_t start;
@@ -2643,7 +2614,7 @@ dirvote_recalculate_timing(or_options_t *options, time_t now)
/** Entry point: Take whatever voting actions are pending as of <b>now</b>. */
void
-dirvote_act(or_options_t *options, time_t now)
+dirvote_act(const or_options_t *options, time_t now)
{
if (!authdir_mode_v3(options))
return;
@@ -2723,7 +2694,7 @@ static smartlist_t *pending_consensus_signature_list = NULL;
static int
dirvote_perform_vote(void)
{
- crypto_pk_env_t *key = get_my_v3_authority_signing_key();
+ crypto_pk_t *key = get_my_v3_authority_signing_key();
authority_cert_t *cert = get_my_v3_authority_cert();
networkstatus_t *ns;
char *contents;
@@ -2758,7 +2729,7 @@ dirvote_perform_vote(void)
directory_post_to_dirservers(DIR_PURPOSE_UPLOAD_VOTE,
ROUTER_PURPOSE_GENERAL,
- V3_AUTHORITY,
+ V3_DIRINFO,
pending_vote->vote_body->dir,
pending_vote->vote_body->dir_len, 0);
log_notice(LD_DIR, "Vote posted.");
@@ -2771,13 +2742,13 @@ dirvote_perform_vote(void)
static void
dirvote_fetch_missing_votes(void)
{
- smartlist_t *missing_fps = smartlist_create();
+ smartlist_t *missing_fps = smartlist_new();
char *resource;
SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
trusted_dir_server_t *, ds,
{
- if (!(ds->type & V3_AUTHORITY))
+ if (!(ds->type & V3_DIRINFO))
continue;
if (!dirvote_get_vote(ds->v3_identity_digest,
DGV_BY_ID|DGV_INCLUDE_PENDING)) {
@@ -2792,8 +2763,13 @@ dirvote_fetch_missing_votes(void)
smartlist_free(missing_fps);
return;
}
- log_notice(LOG_NOTICE, "We're missing votes from %d authorities. Asking "
- "every other authority for a copy.", smartlist_len(missing_fps));
+ {
+ char *tmp = smartlist_join_strings(missing_fps, " ", 0, NULL);
+ log_notice(LOG_NOTICE, "We're missing votes from %d authorities (%s). "
+ "Asking every other authority for a copy.",
+ smartlist_len(missing_fps), tmp);
+ tor_free(tmp);
+ }
resource = smartlist_join_strings(missing_fps, "+", 0, NULL);
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_STATUS_VOTE,
0, resource);
@@ -2845,9 +2821,9 @@ static void
dirvote_clear_votes(int all_votes)
{
if (!previous_vote_list)
- previous_vote_list = smartlist_create();
+ previous_vote_list = smartlist_new();
if (!pending_vote_list)
- pending_vote_list = smartlist_create();
+ pending_vote_list = smartlist_new();
/* All "previous" votes are now junk. */
SMARTLIST_FOREACH(previous_vote_list, pending_vote_t *, v, {
@@ -2886,11 +2862,11 @@ dirvote_clear_votes(int all_votes)
static char *
list_v3_auth_ids(void)
{
- smartlist_t *known_v3_keys = smartlist_create();
+ smartlist_t *known_v3_keys = smartlist_new();
char *keys;
SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
trusted_dir_server_t *, ds,
- if ((ds->type & V3_AUTHORITY) &&
+ if ((ds->type & V3_DIRINFO) &&
!tor_digest_is_zero(ds->v3_identity_digest))
smartlist_add(known_v3_keys,
tor_strdup(hex_str(ds->v3_identity_digest, DIGEST_LEN))));
@@ -2919,7 +2895,7 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
tor_assert(status_out);
if (!pending_vote_list)
- pending_vote_list = smartlist_create();
+ pending_vote_list = smartlist_new();
*status_out = 0;
*msg_out = NULL;
@@ -3083,9 +3059,9 @@ dirvote_compute_consensuses(void)
memset(pending, 0, sizeof(pending));
if (!pending_vote_list)
- pending_vote_list = smartlist_create();
+ pending_vote_list = smartlist_new();
- n_voters = get_n_authorities(V3_AUTHORITY);
+ n_voters = get_n_authorities(V3_DIRINFO);
n_votes = smartlist_len(pending_vote_list);
if (n_votes <= n_voters/2) {
log_warn(LD_DIR, "We don't have enough votes to generate a consensus: "
@@ -3111,8 +3087,8 @@ dirvote_compute_consensuses(void)
goto err;
}
- votes = smartlist_create();
- votestrings = smartlist_create();
+ votes = smartlist_new();
+ votestrings = smartlist_new();
SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v,
{
sized_chunk_t *c = tor_malloc(sizeof(sized_chunk_t));
@@ -3131,7 +3107,7 @@ dirvote_compute_consensuses(void)
{
char legacy_dbuf[DIGEST_LEN];
- crypto_pk_env_t *legacy_sign=NULL;
+ crypto_pk_t *legacy_sign=NULL;
char *legacy_id_digest = NULL;
int n_generated = 0;
if (get_options()->V3AuthUseLegacyKey) {
@@ -3225,7 +3201,7 @@ dirvote_compute_consensuses(void)
directory_post_to_dirservers(DIR_PURPOSE_UPLOAD_SIGNATURES,
ROUTER_PURPOSE_GENERAL,
- V3_AUTHORITY,
+ V3_DIRINFO,
pending_consensus_signatures,
strlen(pending_consensus_signatures), 0);
log_notice(LD_DIR, "Signature(s) posted.");
@@ -3392,7 +3368,7 @@ dirvote_add_signatures(const char *detached_signatures_body,
log_notice(LD_DIR, "Got a signature from %s. "
"Queuing it for the next consensus.", source);
if (!pending_consensus_signature_list)
- pending_consensus_signature_list = smartlist_create();
+ pending_consensus_signature_list = smartlist_new();
smartlist_add(pending_consensus_signature_list,
tor_strdup(detached_signatures_body));
*msg = "Signature queued";