2 * UCW Library -- Rate Limiting based on the Token Bucket Filter
4 * (c) 2009 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 #ifdef CONFIG_UCW_CLEAN_ABI
14 #define tbf_init ucw_tbf_init
15 #define tbf_limit ucw_tbf_limit
18 /** A data structure describing a single TBF. **/
19 struct token_bucket_filter {
20 double rate; // Number of tokens received per second
21 uns burst; // Capacity of the bucket
22 timestamp_t last_hit; // Internal state...
27 /** Initialize the bucket. **/
28 void tbf_init(struct token_bucket_filter *f);
31 * Ask the filter to process a single event. Returns a negative number
32 * if the event exceeds the rate (and should be dropped) and a non-negative
33 * number if the event passes the filter.
34 * The absolute value of the result is the number of dropped events
35 * since the last passed event.
37 int tbf_limit(struct token_bucket_filter *f, timestamp_t now);