Commit fad1656a authored by Nick Mathewson's avatar Nick Mathewson 🦀
Browse files

r16467@catbus: nickm | 2007-11-06 14:57:00 -0500

 Backport r12400 and r12401: Do not allow buckets to overflow.


svn:r12402
parent 897f64c9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ Changes in version 0.1.2.18 - 2007-10-28
      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
+9 −3
Original line number Diff line number Diff line
@@ -1328,15 +1328,19 @@ connection_bucket_refill(int seconds_elapsed)

  /* 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 @@ connection_bucket_refill(int seconds_elapsed)
    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);