X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/3deadf73ca497f4c50a2dbe387f544ef0070cfb4..e9fcf28eed6a6e44d2e2b963b06bad2ae76309e1:/server/tripe.h?ds=sidebyside diff --git a/server/tripe.h b/server/tripe.h index 6f611822..5550c1fd 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -925,7 +925,7 @@ extern void kx_free(keyexch */*kx*/); extern void kx_newkeys(keyexch */*kx*/); -/* --- @kx_init@ --- * +/* --- @kx_setup@ --- * * * Arguments: @keyexch *kx@ = pointer to key exchange context * @peer *p@ = pointer to peer context @@ -939,8 +939,8 @@ extern void kx_newkeys(keyexch */*kx*/); * exchange. */ -extern int kx_init(keyexch */*kx*/, peer */*p*/, - keyset **/*ks*/, unsigned /*f*/); +extern int kx_setup(keyexch */*kx*/, peer */*p*/, + keyset **/*ks*/, unsigned /*f*/); /*----- Keysets and symmetric cryptography --------------------------------*/ @@ -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