summaryrefslogtreecommitdiff
path: root/src/common/util.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-22 10:30:45 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-22 10:31:51 -0400
commit97b15a1d7c51764888d2172711e3f3a71fb01916 (patch)
tree2d7be35820f099e0d7da91f0e4eb49baa99476e4 /src/common/util.h
parent2cf033f238c111bef62552da16117568435d3a18 (diff)
downloadtor-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.h')
-rw-r--r--src/common/util.h37
1 files changed, 0 insertions, 37 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 8f6ec34dcb..9936c421d2 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -126,43 +126,6 @@ int parse_iso_time_nospace(const char *cp, time_t *t);
int parse_http_time(const char *buf, struct tm *tm);
int format_time_interval(char *out, size_t out_len, long interval);
-/* 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 {
- int rate;
- time_t last_allowed;
- int n_calls_since_last_time;
-} ratelim_t;
-
-#define RATELIM_INIT(r) { (r), 0, 0 }
-#define RATELIM_TOOMANY (16*1000*1000)
-
-char *rate_limit_log(ratelim_t *lim, time_t now);
-
/* File helpers */
ssize_t write_all(tor_socket_t fd, const char *buf, size_t count,int isSocket);
ssize_t read_all(tor_socket_t fd, char *buf, size_t count, int isSocket);