diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-22 10:30:45 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-22 10:31:51 -0400 |
commit | 97b15a1d7c51764888d2172711e3f3a71fb01916 (patch) | |
tree | 2d7be35820f099e0d7da91f0e4eb49baa99476e4 /src/common/util.c | |
parent | 2cf033f238c111bef62552da16117568435d3a18 (diff) | |
download | tor-97b15a1d7c51764888d2172711e3f3a71fb01916.tar.gz tor-97b15a1d7c51764888d2172711e3f3a71fb01916.zip |
Extract the locking and logging code
The locking code gets its own module, since it's more fundamental
than the higher-level locking code.
Extracting the logging code was the whole point here. :)
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/common/util.c b/src/common/util.c index 5efbb2bbff..2948e264db 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1310,57 +1310,6 @@ format_time_interval(char *out, size_t out_len, long interval) } /* ===== - * Rate limiting - * ===== */ - -/** 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. - * If the call number hits <b>RATELIM_TOOMANY</b> limit, drop a warning - * about this event and stop counting. */ -static int -rate_limit_is_ready(ratelim_t *lim, time_t 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; - return res; - } else { - if (lim->n_calls_since_last_time <= RATELIM_TOOMANY) { - ++lim->n_calls_since_last_time; - } - - return 0; - } -} - -/** If the rate-limiter <b>lim</b> is ready at <b>now</b>, return a newly - * allocated string indicating how many messages were suppressed, suitable to - * append to a log message. Otherwise return NULL. */ -char * -rate_limit_log(ratelim_t *lim, time_t now) -{ - int n; - if ((n = rate_limit_is_ready(lim, now))) { - if (n == 1) { - return tor_strdup(""); - } else { - char *cp=NULL; - const char *opt_over = (n >= RATELIM_TOOMANY) ? "over " : ""; - /* XXXX this is not exactly correct: the messages could have occurred - * any time between the old value of lim->allowed and now. */ - tor_asprintf(&cp, - " [%s%d similar message(s) suppressed in last %d seconds]", - opt_over, n-1, lim->rate); - return cp; - } - } else { - return NULL; - } -} - -/* ===== * File helpers * ===== */ |