rate.cc File Reference

calculate rate limits More...

#include <jabberdlib.h>

Functions

jlimit jlimit_new (int maxt, int maxp)
void jlimit_free (jlimit r)
int jlimit_check (jlimit r, char *key, int points)


Detailed Description

calculate rate limits

Rate limits can be used to limit the number of allowed events in a given interval, e.g. the number of connects from a single IP to the server

The events can be weighted.


Function Documentation

int jlimit_check ( jlimit  r,
char *  key,
int  points 
)

update/check a key in a jlimit instance

Each jlimit instance can track many limits (that have the same setup). The limit is selected by the key, which can be an IP address.

Parameters:
r the jlimit instance
key for which key the limit should be checked
points how many points of the limit should be consumed
Returns:
1 if limit reached, 0 if we are still within the rate limit

References j_strcmp(), jlimit_struct::key, jlimit_struct::maxp, jlimit_struct::maxt, jlimit_struct::points, and jlimit_struct::start.

void jlimit_free ( jlimit  r  ) 

free a jlimit instance

Parameters:
r the jlimit instance that should be freed

References jlimit_struct::key, jlimit_struct::p, and pool_free().

Referenced by mio_rate().

jlimit jlimit_new ( int  maxt,
int  maxp 
)

create a new instance of jlimit that is used to limit events

limit the events to maxp points per maxt seconds

Parameters:
maxt time interval (in seconds) after which the points are cleared
maxp maximum number of points available for the time interval given in maxt
Returns:
new instance of jlimit (has to be freed with jlimit_free if not used anymore)

References jlimit_struct::key, jlimit_struct::maxp, jlimit_struct::maxt, jlimit_struct::p, pmalloc(), jlimit_struct::points, pool_new, and jlimit_struct::start.

Referenced by mio_rate().


Generated on Wed Sep 10 01:59:47 2008 for jabberd14 by  doxygen 1.5.5