tor
master
|
#include <util.h>
Data Fields | |
int | rate |
time_t | last_allowed |
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!"); }