[or-cvs] [tor/master 2/2] Fix some issues in rate-limiting noticed by Sebastian

nickm at torproject.org nickm at torproject.org
Tue Aug 31 16:59:26 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Tue, 31 Aug 2010 12:52:11 -0400
Subject: Fix some issues in rate-limiting noticed by Sebastian
Commit: 285addbd943cbc9e96c0a268f4f45510270b4468

---
 src/common/util.c |    4 ++--
 src/common/util.h |    1 -
 src/or/command.c  |    4 +++-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 3c735e9..2781fa3 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1584,10 +1584,10 @@ ftime_definitely_before(time_t now, time_t when)
 /** If the rate-limiter <b>lim</b> is ready at <b>now</b>, return the number
  * of calls to rate_limit_is_ready (including this one!) since the last time
  * rate_limit_is_ready returned nonzero.  Otherwise return 0. */
-int
+static int
 rate_limit_is_ready(ratelim_t *lim, time_t now)
 {
-  if (lim->rate + lim->last_allowed >= now) {
+  if (lim->rate + lim->last_allowed <= now) {
     int res = lim->n_calls_since_last_time + 1;
     lim->last_allowed = now;
     lim->n_calls_since_last_time = 0;
diff --git a/src/common/util.h b/src/common/util.h
index 1e22bd5..3a3a873 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -277,7 +277,6 @@ typedef struct ratelim_t {
 
 #define RATELIM_INIT(r) { (r), 0, 0 }
 
-int rate_limit_is_ready(ratelim_t *lim, time_t now);
 char *rate_limit_log(ratelim_t *lim, time_t now);
 
 /* File helpers */
diff --git a/src/or/command.c b/src/or/command.c
index ad8abfe..ea0bbea 100644
--- a/src/or/command.c
+++ b/src/or/command.c
@@ -288,7 +288,9 @@ command_process_create_cell(cell_t *cell, or_connection_t *conn)
 
     /* hand it off to the cpuworkers, and then return. */
     if (assign_onionskin_to_cpuworker(NULL, circ, onionskin) < 0) {
-      static ratelim_t handoff_warning = RATELIM_INIT(3600);
+#define WARN_HANDOFF_FAILURE_INTERVAL (6*60*60)
+      static ratelim_t handoff_warning =
+        RATELIM_INIT(WARN_HANDOFF_FAILURE_INTERVAL);
       char *m;
       if ((m = rate_limit_log(&handoff_warning, approx_time()))) {
         log_warn(LD_GENERAL,"Failed to hand off onionskin. Closing.%s",m);
-- 
1.7.1



More information about the tor-commits mailing list