[or-cvs] r10901: Revert part of r10874, since it was breaking our load balanc (tor/trunk/src/or)

arma at seul.org arma at seul.org
Sun Jul 22 04:36:34 UTC 2007


Author: arma
Date: 2007-07-22 00:36:33 -0400 (Sun, 22 Jul 2007)
New Revision: 10901

Modified:
   tor/trunk/src/or/routerlist.c
Log:
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. :)


Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-07-22 03:51:13 UTC (rev 10900)
+++ tor/trunk/src/or/routerlist.c	2007-07-22 04:36:33 UTC (rev 10901)
@@ -1283,7 +1283,7 @@
 
   /* 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 @@
       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.");



More information about the tor-commits mailing list