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

[or-cvs] r12402: Backport r12400 and r12401: Do not allow buckets to overflow (in tor/branches/tor-0_1_2-patches: . src/or)



Author: nickm
Date: 2007-11-06 14:58:06 -0500 (Tue, 06 Nov 2007)
New Revision: 12402

Modified:
   tor/branches/tor-0_1_2-patches/
   tor/branches/tor-0_1_2-patches/ChangeLog
   tor/branches/tor-0_1_2-patches/src/or/connection.c
Log:
 r16467@catbus:  nickm | 2007-11-06 14:57:00 -0500
 Backport r12400 and r12401: Do not allow buckets to overflow.



Property changes on: tor/branches/tor-0_1_2-patches
___________________________________________________________________
 svk:merge ticket from /tor/012 [r16467] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/branches/tor-0_1_2-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_2-patches/ChangeLog	2007-11-06 19:54:32 UTC (rev 12401)
+++ tor/branches/tor-0_1_2-patches/ChangeLog	2007-11-06 19:58:06 UTC (rev 12402)
@@ -30,6 +30,8 @@
       that it shouldn't be considered to exist at all anymore. Now we
       clear all the flags for routers that fall out of the networkstatus
       consensus. Fixes bug 529.
+    - When the clock jumps forward a lot, do not allow the bandwidth
+      buckets to become negative.  Fixes Bug 544.
 
   o Minor bugfixes:
     - Don't try to access (or alter) the state file when running

Modified: tor/branches/tor-0_1_2-patches/src/or/connection.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/connection.c	2007-11-06 19:54:32 UTC (rev 12401)
+++ tor/branches/tor-0_1_2-patches/src/or/connection.c	2007-11-06 19:58:06 UTC (rev 12402)
@@ -1328,15 +1328,19 @@
 
   /* refill the global buckets */
   if (global_read_bucket < (int)options->BandwidthBurst) {
+    int initial_read_bucket = global_read_bucket;
     global_read_bucket += (int)options->BandwidthRate*seconds_elapsed;
-    if (global_read_bucket > (int)options->BandwidthBurst)
+    if (global_read_bucket > (int)options->BandwidthBurst ||
+        global_read_bucket < initial_read_bucket)
       global_read_bucket = (int)options->BandwidthBurst;
     log(LOG_DEBUG, LD_NET,"global_read_bucket now %d.", global_read_bucket);
   }
   if (global_write_bucket < (int)options->BandwidthBurst) {
+    int initial_write_bucket = global_write_bucket;
     global_write_bucket_empty_last_second = global_write_bucket == 0;
     global_write_bucket += (int)options->BandwidthRate*seconds_elapsed;
-    if (global_write_bucket > (int)options->BandwidthBurst)
+    if (global_write_bucket > (int)options->BandwidthBurst ||
+        global_write_bucket < initial_write_bucket)
       global_write_bucket = (int)options->BandwidthBurst;
     log(LOG_DEBUG, LD_NET,"global_write_bucket now %d.", global_write_bucket);
   }
@@ -1349,8 +1353,10 @@
     if (connection_speaks_cells(conn)) {
       or_connection_t *or_conn = TO_OR_CONN(conn);
       if (connection_read_bucket_should_increase(or_conn)) {
+        int initial_read_bucket = or_conn->read_bucket;
         or_conn->read_bucket += or_conn->bandwidthrate*seconds_elapsed;
-        if (or_conn->read_bucket > or_conn->bandwidthburst)
+        if (or_conn->read_bucket > or_conn->bandwidthburst ||
+            or_conn->read_bucket < initial_read_bucket)
           or_conn->read_bucket = or_conn->bandwidthburst;
         //log_fn(LOG_DEBUG,"Receiver bucket %d now %d.", i,
         //       conn->read_bucket);