1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2021, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file ratelim.h
* \brief Summarize similar messages that would otherwise flood the logs.
**/
/* Rate-limiter */
/** A ratelim_t remembers how often an event is occurring, and how often
* it's allowed to occur. Typical usage is something like:
*
<pre>
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);
}
}
</pre>
As a convenience wrapper for logging, you can replace the above with:
<pre>
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!");
}
</pre>
*/
typedef struct ratelim_t ratelim_t;
char *;
/* !defined(TOR_RATELIM_H) */