5#ifndef BITCOIN_UTIL_TOKENBUCKET_H
6#define BITCOIN_UTIL_TOKENBUCKET_H
22template <
typename Clock>
A token bucket rate limiter.
const double m_cap
Maximum token balance.
static constexpr time_point MIN_TIME
TokenBucket(double rate, double value, double cap)
time_point m_last_updated
typename Clock::time_point time_point
typename Clock::duration duration
bool decrement(double n=1.0, double floor=0.0)
Consume n tokens.
const double m_rate
Tokens added per second.
void increment(const time_point &now)
Refill tokens based on elapsed time since last call.
double value() const
Current token balance.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.