]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix some issues in rate-limiting noticed by Sebastian
authorNick Mathewson <nickm@torproject.org>
Tue, 31 Aug 2010 16:52:11 +0000 (12:52 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 31 Aug 2010 16:52:11 +0000 (12:52 -0400)
src/common/util.c
src/common/util.h
src/or/command.c

index 3c735e9c7c8463a67dbc897c4534ebf74c9f2d1c..2781fa35d6bfc25bedd94857b594c75554f1efec 100644 (file)
@@ -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;
index 1e22bd5b1bd40c2be3a7eb787b45ced451948c34..3a3a87378a40b1f333b0aa777ac8f047601906f4 100644 (file)
@@ -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 */
index ad8abfe5c9d3864e3e7848386acfd936728f73bb..ea0bbea1e527dd77d5a6b5cd1e2dc1186dae4d10 100644 (file)
@@ -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);