Tor
0.4.7.0-alpha-dev
|
#include <ratelim.h>
Data Fields | |
int | rate |
time_t | last_allowed |
time_t | started_limiting |
int | n_calls_since_last_time |
A ratelim_t remembers how often an event is occurring, and how often it's allowed to occur. Typical usage is something like:
if (possibly_very_frequent_event()) { const int INTERVAL = 300; static ratelim_t warning_limit = RATELIM_INIT(INTERVAL); char *m; if ((m = rate_limit_log(&warning_limit, approx_time()))) { log_warn(LD_GENERAL, "The event occurred!%s", m); tor_free(m); } }
As a convenience wrapper for logging, you can replace the above with:
if (possibly_very_frequent_event()) { static ratelim_t warning_limit = RATELIM_INIT(300); log_fn_ratelim(&warning_limit, LOG_WARN, LD_GENERAL, "The event occurred!"); }
time_t last_allowed |
When did this limiter last allow a message to appear?
Definition at line 46 of file ratelim.h.
Referenced by rate_limit_is_ready().
int n_calls_since_last_time |
How many messages has this limiter suppressed since it last allowed one to appear?
Definition at line 51 of file ratelim.h.
Referenced by rate_limit_is_ready().
int rate |
How many seconds must elapse between log messages?
Definition at line 44 of file ratelim.h.
Referenced by rate_limit_is_ready().
time_t started_limiting |
When did this limiter start suppressing messages?
Definition at line 48 of file ratelim.h.
Referenced by rate_limit_log().