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 /** A data structure describing a single TBF. **/
14 struct token_bucket_filter {
15 double rate; // Number of tokens received per second
16 uns burst; // Capacity of the bucket
17 timestamp_t last_hit; // Internal state...
22 /** Initialize the bucket. **/
23 void tbf_init(struct token_bucket_filter *f);
26 * Ask the filter to process a single event. Returns a negative number
27 * if the event exceeds the rate (and should be dropped) and a non-negative
28 * number if the event passes the filter.
29 * The absolute value of the result is the number of dropped events
30 * since the last passed event.
32 int tbf_limit(struct token_bucket_filter *f, timestamp_t now);