X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/0510f26241da5ac18afecf97fa46e0448ae705a4..e9fcf28eed6a6e44d2e2b963b06bad2ae76309e1:/server/tripe.h diff --git a/server/tripe.h b/server/tripe.h index 494aa182..5550c1fd 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -1768,6 +1768,39 @@ extern void seq_reset(seqwin */*s*/); extern int seq_check(seqwin */*s*/, uint32 /*q*/, const char */*service*/); +typedef struct ratelim { + unsigned n, max, persec; + struct timeval when; +} ratelim; + +/* --- @ratelim_init@ --- * + * + * Arguments: @ratelim *r@ = rate-limiting state to fill in + * @unsigned persec@ = credit to accumulate per second + * @unsigned max@ = maximum credit to retain + * + * Returns: --- + * + * Use: Initialize a rate-limiting state. + */ + +extern void ratelim_init(ratelim */*r*/, + unsigned /*persec*/, unsigned /*max*/); + +/* --- @ratelim_withdraw@ --- * + * + * Arguments: @ratelim *r@ = rate-limiting state + * @unsigned n@ = credit to withdraw + * + * Returns: Zero if successful; @-1@ if there is unsufficient credit + * + * Use: Updates the state with any accumulated credit. Then, if + * there there are more than @n@ credits available, withdraw @n@ + * and return successfully; otherwise, report failure. + */ + +extern int ratelim_withdraw(ratelim */*r*/, unsigned /*n*/); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus