Tor 0.4.9.0-alpha-dev
Data Fields
ratelim_t Struct Reference

#include <ratelim.h>

Data Fields

int rate
 
time_t last_allowed
 
time_t started_limiting
 
int n_calls_since_last_time
 

Detailed Description

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!");
}

Definition at line 42 of file ratelim.h.

Field Documentation

◆ last_allowed

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().

◆ n_calls_since_last_time

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().

◆ rate

int rate

How many seconds must elapse between log messages?

Definition at line 44 of file ratelim.h.

Referenced by rate_limit_is_ready().

◆ started_limiting

time_t started_limiting

When did this limiter start suppressing messages?

Definition at line 48 of file ratelim.h.

Referenced by rate_limit_log().


The documentation for this struct was generated from the following file: