jabberd2  2.3.2
Functions
rate.c File Reference
#include "util.h"

Go to the source code of this file.

Functions

rate_t rate_new (int total, int seconds, int wait)
 
void rate_free (rate_t rt)
 
void rate_reset (rate_t rt)
 
void rate_add (rate_t rt, int count)
 Add a number of events to the counter. More...
 
int rate_left (rate_t rt)
 
int rate_check (rate_t rt)
 

Function Documentation

rate_t rate_new ( int  total,
int  seconds,
int  wait 
)
void rate_free ( rate_t  rt)
void rate_reset ( rate_t  rt)

Definition at line 41 of file rate.c.

References rate_st::bad, rate_st::count, and rate_st::time.

Referenced by rate_add(), and rate_check().

void rate_add ( rate_t  rt,
int  count 
)

Add a number of events to the counter.

This takes care of moving the sliding window, if we've moved outside the previous window.

Definition at line 48 of file rate.c.

References rate_st::bad, rate_st::count, rate_reset(), rate_st::seconds, rate_st::time, and rate_st::total.

Referenced by _c2s_client_accept_check(), _c2s_client_sx_callback(), _router_accept_check(), _router_sx_callback(), and sm_storage_rate_limit().

int rate_left ( rate_t  rt)
Returns
The amount of events we have left before we hit the rate limit. This could be number of bytes, or number of connection attempts, etc.

Definition at line 69 of file rate.c.

References rate_st::bad, rate_st::count, and rate_st::total.

Referenced by _c2s_client_sx_callback(), and _router_sx_callback().

int rate_check ( rate_t  rt)
Returns
1 if we're under the rate limit and everything is fine or 0 if the rate limit has been exceeded and we should throttle something.

Definition at line 78 of file rate.c.

References rate_st::bad, rate_st::count, rate_reset(), rate_st::time, rate_st::total, and rate_st::wait.

Referenced by _c2s_client_accept_check(), _c2s_client_sx_callback(), _c2s_time_checks(), _router_accept_check(), _router_sx_callback(), and sm_storage_rate_limit().