[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r16551: {tor} Add bw to consensus (tor/trunk/src/or)
Author: weasel
Date: 2008-08-14 19:00:57 -0400 (Thu, 14 Aug 2008)
New Revision: 16551
Modified:
tor/trunk/src/or/dirvote.c
tor/trunk/src/or/or.h
tor/trunk/src/or/routerparse.c
Log:
Add bw to consensus
Modified: tor/trunk/src/or/dirvote.c
===================================================================
--- tor/trunk/src/or/dirvote.c 2008-08-14 23:00:44 UTC (rev 16550)
+++ tor/trunk/src/or/dirvote.c 2008-08-14 23:00:57 UTC (rev 16551)
@@ -106,7 +106,7 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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 */
}
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2008-08-14 23:00:44 UTC (rev 16550)
+++ tor/trunk/src/or/or.h 2008-08-14 23:00:57 UTC (rev 16551)
@@ -1415,6 +1415,9 @@
* 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
Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c 2008-08-14 23:00:44 UTC (rev 16550)
+++ tor/trunk/src/or/routerparse.c 2008-08-14 23:00:57 UTC (rev 16551)
@@ -1879,6 +1879,7 @@
log_warn(LD_DIR, "Invalid Bandwidth %s", escaped(tok->args[i]));
goto err;
}
+ rs->has_bandwidth = 1;
}
}
}
@@ -1897,6 +1898,7 @@
}
/* 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))