summaryrefslogtreecommitdiff
path: root/src/or/dirvote.c
diff options
context:
space:
mode:
authorMike Perry <mikeperry-git@fscked.org>2009-07-31 06:33:53 +0200
committerMike Perry <mikeperry-git@fscked.org>2009-08-06 11:48:03 -0700
commit6fbdf635fa300fb4d9be32cd397dea3bb8cfa4fa (patch)
tree2d1842cac2d7fabe6c0da3226ca2bb40db3f08cd /src/or/dirvote.c
parent9da7b22355b71ed7becad99d5773909e25b400a6 (diff)
downloadtor-6fbdf635fa300fb4d9be32cd397dea3bb8cfa4fa.tar.gz
tor-6fbdf635fa300fb4d9be32cd397dea3bb8cfa4fa.zip
Implement measured bw parsing + unit tests.
Diffstat (limited to 'src/or/dirvote.c')
-rw-r--r--src/or/dirvote.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 409c2fed69..acb658bd23 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -103,6 +103,7 @@ format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
tor_snprintf(status, len,
"network-status-version 3\n"
"vote-status %s\n"
+ /* TODO-160: add 6 when ready */
"consensus-methods 1 2 3 4 5\n"
"published %s\n"
"valid-after %s\n"
@@ -142,7 +143,7 @@ format_networkstatus_vote(crypto_pk_env_t *private_signing_key,
SMARTLIST_FOREACH(v3_ns->routerstatus_list, vote_routerstatus_t *, vrs,
{
if (routerstatus_format_entry(outp, endp-outp, &vrs->status,
- vrs->version, 0, 0) < 0) {
+ vrs->version, NS_V3_VOTE) < 0) {
log_warn(LD_BUG, "Unable to print router status.");
goto err;
}
@@ -701,7 +702,10 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_t *versions = smartlist_create();
smartlist_t *exitsummaries = smartlist_create();
uint32_t *bandwidths = tor_malloc(sizeof(uint32_t) * smartlist_len(votes));
+ uint32_t *measured_bws = tor_malloc(sizeof(uint32_t) *
+ smartlist_len(votes));
int num_bandwidths;
+ int num_mbws;
int *n_voter_flags; /* n_voter_flags[j] is the number of flags that
* votes[j] knows about. */
@@ -835,6 +839,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_clear(chosen_flags);
smartlist_clear(versions);
num_bandwidths = 0;
+ num_mbws = 0;
/* Okay, go through all the entries for this digest. */
SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
@@ -868,6 +873,9 @@ networkstatus_compute_consensus(smartlist_t *votes,
}
/* count bandwidths */
+ if (rs->status.has_measured_bw)
+ measured_bws[num_mbws++] = rs->status.measured_bw;
+
if (rs->status.has_bandwidth)
bandwidths[num_bandwidths++] = rs->status.bandwidth;
} SMARTLIST_FOREACH_END(v);
@@ -945,7 +953,10 @@ networkstatus_compute_consensus(smartlist_t *votes,
}
/* Pick a bandwidth */
- if (consensus_method >= 5 && num_bandwidths > 0) {
+ if (consensus_method >= 6 && num_mbws > 2) {
+ rs_out.has_bandwidth = 1;
+ rs_out.bandwidth = median_uint32(measured_bws, num_mbws);
+ } else if (consensus_method >= 5 && num_bandwidths > 0) {
rs_out.has_bandwidth = 1;
rs_out.bandwidth = median_uint32(bandwidths, num_bandwidths);
}
@@ -1036,7 +1047,8 @@ networkstatus_compute_consensus(smartlist_t *votes,
/* Okay!! Now we can write the descriptor... */
/* First line goes into "buf". */
- routerstatus_format_entry(buf, sizeof(buf), &rs_out, NULL, 1, 0);
+ routerstatus_format_entry(buf, sizeof(buf), &rs_out, NULL,
+ NS_V3_CONSENSUS);
smartlist_add(chunks, tor_strdup(buf));
/* Second line is all flags. The "\n" is missing. */
smartlist_add(chunks,
@@ -1055,8 +1067,10 @@ networkstatus_compute_consensus(smartlist_t *votes,
log_warn(LD_BUG, "Not enough space in buffer for weight line.");
*buf = '\0';
}
+
smartlist_add(chunks, tor_strdup(buf));
};
+
/* Now the exitpolicy summary line. */
if (rs_out.has_exitsummary) {
char buf[MAX_POLICY_LINE_LEN+1];