|
@@ -1674,6 +1674,8 @@ smartlist_choose_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 */
|
|
@@ -1835,12 +1837,17 @@ smartlist_choose_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
|
|
@@ -1877,6 +1884,8 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
|
|
|
int statuses)
|
|
|
{
|
|
|
unsigned int i;
|
|
|
+ unsigned int i_chosen;
|
|
|
+ unsigned int i_has_been_chosen;
|
|
|
routerinfo_t *router;
|
|
|
routerstatus_t *status=NULL;
|
|
|
int32_t *bandwidths;
|
|
@@ -2092,6 +2101,8 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
|
|
|
|
|
|
/* 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);
|
|
@@ -2106,9 +2117,12 @@ smartlist_choose_by_bandwidth(smartlist_t *sl, bandwidth_weight_rule_t rule,
|
|
|
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. */
|