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

[or-cvs] r13406: Fix bandwidth bucked calculations again, I think. Bugfix on (in tor/trunk: . src/or)



Author: nickm
Date: 2008-02-06 13:21:16 -0500 (Wed, 06 Feb 2008)
New Revision: 13406

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/connection.c
Log:
 r17949@catbus:  nickm | 2008-02-06 13:21:12 -0500
 Fix bandwidth bucked calculations again, I think. Bugfix on 0.1.2.x. Backport candidate.



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

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-02-06 16:58:05 UTC (rev 13405)
+++ tor/trunk/ChangeLog	2008-02-06 18:21:16 UTC (rev 13406)
@@ -47,6 +47,8 @@
     - If an attempt to launch a DNS resolve request over the control
       port fails because we have overrun the limit on the number of
       connections, tell the controller that the request has failed.
+    - Avoid using too little bandwidth when Tor skips a few seconds.  Bugfix
+      on 0.1.2.x.
 
   o Code simplifications and refactoring:
     - Remove some needless generality from cpuworker code, for improved

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2008-02-06 16:58:05 UTC (rev 13405)
+++ tor/trunk/src/or/connection.c	2008-02-06 18:21:16 UTC (rev 13406)
@@ -1659,13 +1659,19 @@
                                 int seconds_elapsed, const char *name)
 {
   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;
+  if (starting_bucket < burst && seconds_elapsed) {
+    if (((burst - starting_bucket)/seconds_elapsed) < rate) {
+      *bucket = burst;  /* We would overflow the bucket; just set it to
+                         * the maximum. */
+    } else {
+      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. */
+        /* XXXX020 this might be redundant now. */
+        *bucket = burst;
+      }
     }
     log(LOG_DEBUG, LD_NET,"%s now %d.", name, *bucket);
   }