]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Remove an erroneous 0.5 in compute_weighted_bandwidths()
authorNick Mathewson <nickm@torproject.org>
Fri, 22 Sep 2017 19:29:15 +0000 (15:29 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 22 Sep 2017 19:29:15 +0000 (15:29 -0400)
Back in 0.2.4.3-alpha (e106812a778f537), when we switched from using
double to using uint64 for selecting by bandwidth, I got the math
wrong: I should have used llround(x), or (uint64_t)(x+0.5), but
instead I wrote llround(x+0.5).  That means we would always round
up, rather than rounding to the closest integer

Fixes bug 23318; bugfix on 0.2.4.3-alpha.

changes/bug23318 [new file with mode: 0644]
src/or/routerlist.c

diff --git a/changes/bug23318 b/changes/bug23318
new file mode 100644 (file)
index 0000000..32c85eb
--- /dev/null
@@ -0,0 +1,7 @@
+  o Minor bugfixes (path selection):
+    - When selecting relays by bandwidth, avoid a rounding error that
+      could sometimes cause load to be imbalanced incorrectly. Previously,
+      we would always round upwards; now, we round towards the nearest
+      integer.  This had the biggest effect when a relay's weight adjustments
+      should have given it weight 0, but it got weight 1 instead.
+      Fixes bug 23318; bugfix on 0.2.4.3-alpha.
index 2365f28fd2b726c0cea9d68f43b3be57a4b8ae0f..faf2eeda5d0c57c64cf00afad2adc4af4533b26f 100644 (file)
@@ -2713,7 +2713,7 @@ compute_weighted_bandwidths(const smartlist_t *sl,
       final_weight = weight*this_bw;
     }
 
-    bandwidths[node_sl_idx] = final_weight + 0.5;
+    bandwidths[node_sl_idx] = final_weight;
   } SMARTLIST_FOREACH_END(node);
 
   log_debug(LD_CIRC, "Generated weighted bandwidths for rule %s based "