[tor-commits] [stegotorus/master] Fix some bugs in the exponential backoff.

zwol at torproject.org zwol at torproject.org
Fri Jul 20 23:17:06 UTC 2012


commit e5e8c69490e6012fc12ed4d4591e073c7d762906
Author: Zack Weinberg <zackw at cmu.edu>
Date:   Fri Jan 13 17:43:07 2012 +0000

    Fix some bugs in the exponential backoff.
    
    git-svn-id: svn+ssh://spartan.csl.sri.com/svn/private/DEFIANCE@216 a58ff0ac-194c-e011-a152-003048836090
---
 src/protocol/chop.cc |   20 ++++++++++----------
 src/rng.cc           |    2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index 6b0d6a4..b7e95fb 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -104,16 +104,16 @@ namespace {
     CIRCUIT_DECLARE_METHODS(chop);
 
     uint32_t axe_interval() {
-      return rng_range_geom(30 * 60 * 1000,
-                            std::min((1 << dead_cycles) * 1000,
-                                     20 * 60 * 1000))
-        + 5 * 1000;
+      // 20*60*1000 lies between 2^20 and 2^21.
+      uint32_t shift = std::max(1u, std::min(20u, dead_cycles));
+      uint32_t xv = std::max(1u, std::min(20u * 60 * 1000, 1u << shift));
+      return rng_range_geom(30 * 60 * 1000, xv) + 5 * 1000;
     }
     uint32_t flush_interval() {
-      return rng_range_geom(20 * 60 * 1000,
-                            std::min((1 << dead_cycles) * 500,
-                                     10 * 60 * 1000))
-        + 1000;
+      // 10*60*1000 lies between 2^19 and 2^20.
+      uint32_t shift = std::max(1u, std::min(19u, dead_cycles));
+      uint32_t xv = std::max(1u, std::min(10u * 60 * 1000, 1u << shift));
+      return rng_range_geom(20 * 60 * 1000, xv) + 1000;
     }
   };
 
@@ -1031,9 +1031,9 @@ chop_circuit_t::drop_downstream(conn_t *conn)
       else
         circuit_close(this);
     } else if (this->cfg->mode == LSN_SIMPLE_SERVER) {
-      circuit_arm_axe_timer(this, 5000);
+      circuit_arm_axe_timer(this, this->axe_interval());
     } else {
-      circuit_arm_flush_timer(this, 1);
+      circuit_arm_flush_timer(this, this->flush_interval());
     }
   }
 }
diff --git a/src/rng.cc b/src/rng.cc
index a42c487..f5c0ca4 100644
--- a/src/rng.cc
+++ b/src/rng.cc
@@ -216,7 +216,7 @@ rng_range_geom(unsigned int hi, unsigned int xv)
      ( e^{-hi/xe}, 1 ]. Doing this with arithmetic introduces
      a slight nonuniformity, but we really want to avoid rejection
      sampling here. */
-  double ulo = exp(-hi/xe);
+  double ulo = exp(-double(hi)/xe);
   U = ulo + U * (1-ulo);
 
   /* Inverse transform sampling gives us a value for the exponential





More information about the tor-commits mailing list