5#ifndef BITCOIN_UTIL_TOKENBUCKET_H
6#define BITCOIN_UTIL_TOKENBUCKET_H
22template <
typename Clock>
43 if (m_value < m_cap && m_last_updated >
MIN_TIME) {
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.
std::conditional< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock >::type Clock