summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2007-07-22 04:36:33 +0000
committerRoger Dingledine <arma@torproject.org>2007-07-22 04:36:33 +0000
commite96d807db4c798f3794d24aed8a38fa7cc5cf3fa (patch)
treee921fa97efcd1925c25bd10b593ec2ec40d23bee /src
parent83f605f2e32a635d499815ceec97ba0f3d0cb5a4 (diff)
downloadtor-e96d807db4c798f3794d24aed8a38fa7cc5cf3fa.tar.gz
tor-e96d807db4c798f3794d24aed8a38fa7cc5cf3fa.zip
Revert part of r10874, since it was breaking our load balancing
(we always picked one router past the one we wanted!) and could conceivably read past the end of the smartlist too. Nick, I don't know what gcc 4.2 was worried about, but we need to find a better fix than this. :) svn:r10901
Diffstat (limited to 'src')
-rw-r--r--src/or/routerlist.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 9bb456c3af..19b8eed850 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1283,7 +1283,7 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, int for_exit, int statuses)
/* Last, count through sl until we get to the element we picked */
tmp = 0;
- for (i=0; i < smartlist_len(sl) && tmp < rand_bw; i++) {
+ for (i=0; i < smartlist_len(sl); i++) {
if (statuses) {
status = smartlist_get(sl, i);
is_exit = status->is_exit;
@@ -1295,10 +1295,11 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, int for_exit, int statuses)
tmp += ((uint64_t)(bandwidths[i] * exit_weight));
else
tmp += bandwidths[i];
+ if (tmp >= rand_bw)
+ break;
}
- if (tmp < rand_bw) {
+ if (i == smartlist_len(sl)) {
/* This is possible due to round-off error. */
- tor_assert(i == smartlist_len(sl));
--i;
log_warn(LD_BUG, "Round-off error in computing bandwidth had an effect on "
" which router we chose. Please tell the developers.");