[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r12400: Fix bug 544: do not allow buckets to overflow. Backportable. (in tor/trunk: . src/or)



Author: nickm
Date: 2007-11-06 14:42:37 -0500 (Tue, 06 Nov 2007)
New Revision: 12400

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/connection.c
Log:
 r16462@catbus:  nickm | 2007-11-06 14:40:58 -0500
 Fix bug 544: do not allow buckets to overflow.  Backportable.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r16462] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-11-06 18:27:14 UTC (rev 12399)
+++ tor/trunk/ChangeLog	2007-11-06 19:42:37 UTC (rev 12400)
@@ -17,6 +17,8 @@
     - Stop servers from crashing if they set a Family option (or
       maybe in other situations too). Bugfix on 0.2.0.9-alpha; reported
       by Fabian Keil.
+    - When the clock jumps forward a lot, do not allow the bandwidth
+      buckets to become negative.  Bugfix on 0.1.2.x; fixes Bug 544.
 
   o Major bugfixes (v3 dir, bugfixes on 0.2.0.9-alpha):
     - Consider replacing the current consensus when certificates arrive

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2007-11-06 18:27:14 UTC (rev 12399)
+++ tor/trunk/src/or/connection.c	2007-11-06 19:42:37 UTC (rev 12400)
@@ -1638,14 +1638,20 @@
   }
 }
 
+/** DOCDOC */
 static void
 connection_bucket_refill_helper(int *bucket, int rate, int burst,
                                 int seconds_elapsed, const char *name)
 {
-  if (*bucket < burst) {
-    *bucket += rate*seconds_elapsed;
-    if (*bucket > burst)
+  int starting_bucket = *bucket;
+  if (starting_bucket < burst) {
+    int incr = rate*seconds_elapsed;
+    *bucket += incr;
+    if (*bucket > burst || *bucket < starting_bucket) {
+      /* If we overflow the burst, or underflow our starting bucket,
+       * cap the bucket value to burst. */
       *bucket = burst;
+    }
     log(LOG_DEBUG, LD_NET,"%s now %d.", name, *bucket);
   }
 }