diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-08-03 12:04:36 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-08-03 12:04:36 -0400 |
commit | aa584fd3a3888de836bb5c23b7372676c557a735 (patch) | |
tree | 8ed451f1492d9207f435eeeffeefc6ca7c7b88bb /src/or | |
parent | 860c4fc81166568f2909708c455ca6a70d81a2f8 (diff) | |
parent | 93be3a8822ae791cc8adb78ea7d7e76e4c10db41 (diff) | |
download | tor-aa584fd3a3888de836bb5c23b7372676c557a735.tar.gz tor-aa584fd3a3888de836bb5c23b7372676c557a735.zip |
Merge remote-tracking branch 'origin/maint-0.2.3'
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/routerlist.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index e8365d03c0..ee99e2c7ae 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1711,6 +1711,8 @@ smartlist_choose_node_by_bandwidth_weights(smartlist_t *sl, double *bandwidths; double tmp = 0; unsigned int i; + unsigned int i_chosen; + unsigned int i_has_been_chosen; int have_unknown = 0; /* true iff sl contains element not in consensus. */ /* Can't choose exit and guard at same time */ @@ -1873,12 +1875,17 @@ smartlist_choose_node_by_bandwidth_weights(smartlist_t *sl, * from 1 below. See bug 1203 for details. */ /* Last, count through sl until we get to the element we picked */ + i_chosen = (unsigned)smartlist_len(sl); + i_has_been_chosen = 0; tmp = 0.0; for (i=0; i < (unsigned)smartlist_len(sl); i++) { tmp += bandwidths[i]; - if (tmp >= rand_bw) - break; + if (tmp >= rand_bw && !i_has_been_chosen) { + i_chosen = i; + i_has_been_chosen = 1; + } } + i = i_chosen; if (i == (unsigned)smartlist_len(sl)) { /* This was once possible due to round-off error, but shouldn't be able @@ -1911,7 +1918,9 @@ static const node_t * smartlist_choose_node_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule) { - unsigned i; + unsigned int i; + unsigned int i_chosen; + unsigned int i_has_been_chosen; int32_t *bandwidths; int is_exit; int is_guard; @@ -2111,6 +2120,8 @@ smartlist_choose_node_by_bandwidth(smartlist_t *sl, /* Last, count through sl until we get to the element we picked */ tmp = 0; + i_chosen = (unsigned)smartlist_len(sl); + i_has_been_chosen = 0; for (i=0; i < (unsigned)smartlist_len(sl); i++) { is_exit = bitarray_is_set(exit_bits, i); is_guard = bitarray_is_set(guard_bits, i); @@ -2125,9 +2136,12 @@ smartlist_choose_node_by_bandwidth(smartlist_t *sl, else tmp += bandwidths[i]; - if (tmp >= rand_bw) - break; + if (tmp >= rand_bw && !i_has_been_chosen) { + i_chosen = i; + i_has_been_chosen = 1; + } } + i = i_chosen; if (i == (unsigned)smartlist_len(sl)) { /* This was once possible due to round-off error, but shouldn't be able * to occur any longer. */ |