diff options
author | Peter Palfrader <peter@palfrader.org> | 2008-08-14 23:00:57 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2008-08-14 23:00:57 +0000 |
commit | ceae7ed96020cf4e4936d57367ca004ba1166147 (patch) | |
tree | 10a04c2b140c1ac28db857e78a88fd8eb9ffd308 /src/or | |
parent | 82f8050ac428416a91997003b205ac90019768dd (diff) | |
download | tor-ceae7ed96020cf4e4936d57367ca004ba1166147.tar.gz tor-ceae7ed96020cf4e4936d57367ca004ba1166147.zip |
Add bw to consensus
svn:r16551
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/dirvote.c | 26 | ||||
-rw-r--r-- | src/or/or.h | 3 | ||||
-rw-r--r-- | src/or/routerparse.c | 2 |
3 files changed, 29 insertions, 2 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c index b704a94f08..626854fa69 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -106,7 +106,7 @@ format_networkstatus_vote(crypto_pk_env_t *private_signing_key, tor_snprintf(status, len, "network-status-version 3\n" "vote-status %s\n" - "consensus-methods 1 2 3 4\n" + "consensus-methods 1 2 3 4 5\n" "published %s\n" "valid-after %s\n" "fresh-until %s\n" @@ -452,7 +452,7 @@ compute_consensus_method(smartlist_t *votes) static int consensus_method_is_supported(int method) { - return (method >= 1) && (method <= 4); + return (method >= 1) && (method <= 5); } /** Given a list of vote networkstatus_t in <b>votes</b>, our public @@ -688,6 +688,8 @@ networkstatus_compute_consensus(smartlist_t *votes, smartlist_t *matching_descs = smartlist_create(); smartlist_t *chosen_flags = smartlist_create(); smartlist_t *versions = smartlist_create(); + uint32_t *bandwidths = tor_malloc(sizeof(uint32_t) * smartlist_len(votes)); + int num_bandwidths; int *n_voter_flags; /* n_voter_flags[j] is the number of flags that * votes[j] knows about. */ @@ -819,6 +821,7 @@ networkstatus_compute_consensus(smartlist_t *votes, smartlist_clear(matching_descs); smartlist_clear(chosen_flags); smartlist_clear(versions); + num_bandwidths = 0; /* Okay, go through all the entries for this digest. */ SMARTLIST_FOREACH(votes, networkstatus_t *, v, { @@ -850,6 +853,10 @@ networkstatus_compute_consensus(smartlist_t *votes, } chosen_name = rs->status.nickname; } + + /* count bandwidths */ + if (rs->status.has_bandwidth) + bandwidths[num_bandwidths++] = rs->status.bandwidth; }); /* We don't include this router at all unless more than half of @@ -922,6 +929,12 @@ networkstatus_compute_consensus(smartlist_t *votes, chosen_version = NULL; } + /* Pick a bandwidth */ + if (consensus_method >= 5 && num_bandwidths > 0) { + rs_out.has_bandwidth = 1; + rs_out.bandwidth = median_uint32(bandwidths, num_bandwidths); + } + /* Okay!! Now we can write the descriptor... */ /* First line goes into "buf". */ routerstatus_format_entry(buf, sizeof(buf), &rs_out, NULL, 1, 0); @@ -935,6 +948,15 @@ networkstatus_compute_consensus(smartlist_t *votes, smartlist_add(chunks, tor_strdup(chosen_version)); } smartlist_add(chunks, tor_strdup("\n")); + /* Now the weight line. */ + if (rs_out.has_bandwidth) { + int r = tor_snprintf(buf, sizeof(buf), "w Bandwidth=%d\n", rs_out.bandwidth); + if (r<0) { + log_warn(LD_BUG, "Not enough space in buffer for weight line."); + *buf = '\0'; + } + smartlist_add(chunks, tor_strdup(buf)); + }; /* And the loop is over and we move on to the next router */ } diff --git a/src/or/or.h b/src/or/or.h index 8e8e3387b4..ba19817376 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1415,6 +1415,9 @@ typedef struct routerstatus_t { * we can get v3 downloads from. */ unsigned int version_supports_v3_dir:1; + unsigned int has_bandwidth:1; /**< The vote/consensus had bw info */ + unsigned int has_exitsummary:1; /**< The vote/consensus had exit summaries */ + uint32_t bandwidth; /**< Bandwidth (capacity) of the router as reported in * the vote/consensus, in kilobytes/sec. */ addr_policy_action_t exitsummarytype; /**< is the list of ports a list of diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 8c66127cf3..303d129010 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -1879,6 +1879,7 @@ routerstatus_parse_entry_from_string(memarea_t *area, log_warn(LD_DIR, "Invalid Bandwidth %s", escaped(tok->args[i])); goto err; } + rs->has_bandwidth = 1; } } } @@ -1897,6 +1898,7 @@ routerstatus_parse_entry_from_string(memarea_t *area, } /* XXX weasel: parse this into ports and represent them somehow smart */ rs->exitsummary = tor_strdup(tok->args[1]); + rs->has_exitsummary = 1; } if (!strcasecmp(rs->nickname, UNNAMED_ROUTER_NICKNAME)) |