9 #ifndef TOR_TOKEN_BUCKET_H
10 #define TOR_TOKEN_BUCKET_H
16 #define TOKEN_BUCKET_MAX_BURST INT32_MAX
46 const uint32_t elapsed_steps);
53 return bucket->bucket >= 0 ? bucket->bucket : 0;
63 uint32_t last_refilled_at_timestamp;
72 uint32_t rate, uint32_t burst);
89 ssize_t n_read, ssize_t n_written);
98 static inline size_t token_bucket_rw_get_write(
113 uint32_t last_refilled_at_timestamp;
117 uint32_t burst, uint32_t now_ts);
135 #ifdef TOKEN_BUCKET_PRIVATE
140 #define TICKS_PER_STEP 16
Macros to implement mocking and selective exposure for the test code.
STATIC uint32_t rate_per_sec_to_rate_per_step(uint32_t rate)
int token_bucket_rw_dec(token_bucket_rw_t *bucket, ssize_t n_read, ssize_t n_written)
int token_bucket_rw_dec_read(token_bucket_rw_t *bucket, ssize_t n)
int token_bucket_raw_refill_steps(token_bucket_raw_t *bucket, const token_bucket_cfg_t *cfg, const uint32_t elapsed_steps)
void token_bucket_ctr_init(token_bucket_ctr_t *bucket, uint32_t rate, uint32_t burst, uint32_t now_ts)
int token_bucket_raw_dec(token_bucket_raw_t *bucket, ssize_t n)
void token_bucket_rw_init(token_bucket_rw_t *bucket, uint32_t rate, uint32_t burst, uint32_t now_ts)
void token_bucket_raw_adjust(token_bucket_raw_t *bucket, const token_bucket_cfg_t *cfg)
void token_bucket_rw_adjust(token_bucket_rw_t *bucket, uint32_t rate, uint32_t burst)
void token_bucket_cfg_init(token_bucket_cfg_t *cfg, uint32_t rate, uint32_t burst)
void token_bucket_ctr_reset(token_bucket_ctr_t *bucket, uint32_t now_ts)
void token_bucket_ctr_refill(token_bucket_ctr_t *bucket, uint32_t now_ts)
void token_bucket_ctr_adjust(token_bucket_ctr_t *bucket, uint32_t rate, uint32_t burst)
int token_bucket_rw_dec_write(token_bucket_rw_t *bucket, ssize_t n)
static size_t token_bucket_raw_get(const token_bucket_raw_t *bucket)
int token_bucket_rw_refill(token_bucket_rw_t *bucket, uint32_t now_ts)
void token_bucket_raw_reset(token_bucket_raw_t *bucket, const token_bucket_cfg_t *cfg)
void token_bucket_rw_reset(token_bucket_rw_t *bucket, uint32_t now_ts)
Integer definitions used throughout Tor.