mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-17 08:11:32 +00:00
Allow rate to be less than 1.
Change all the token-related variables to doubles so the rate can be less than 1.
This commit is contained in:
parent
87a6c74290
commit
e183de3b89
@ -31,7 +31,7 @@ token_bucket::~token_bucket()
|
||||
{
|
||||
}
|
||||
|
||||
void token_bucket::init(uint32_t rate, uint32_t max_tokens)
|
||||
void token_bucket::init(double rate, double max_tokens)
|
||||
{
|
||||
m_rate = rate;
|
||||
m_max_tokens = max_tokens;
|
||||
@ -48,7 +48,7 @@ bool token_bucket::claim(uint64_t now)
|
||||
now = sinsp_utils::get_current_time_ns();
|
||||
}
|
||||
|
||||
uint64_t tokens_gained = (now - m_last_seen) / (m_rate * 1000000000);
|
||||
double tokens_gained = (now - m_last_seen) / (m_rate * 1000000000);
|
||||
m_last_seen = now;
|
||||
|
||||
m_tokens += tokens_gained;
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
//
|
||||
// Initialize the token bucket and start accumulating tokens
|
||||
//
|
||||
void init(uint32_t rate, uint32_t max_tokens);
|
||||
void init(double rate, double max_tokens);
|
||||
|
||||
//
|
||||
// Returns true if a token can be claimed. Also updates
|
||||
@ -43,18 +43,18 @@ private:
|
||||
//
|
||||
// The number of tokens generated per second.
|
||||
//
|
||||
uint64_t m_rate;
|
||||
double m_rate;
|
||||
|
||||
//
|
||||
// The maximum number of tokens that can be banked for future
|
||||
// claim()s.
|
||||
//
|
||||
uint64_t m_max_tokens;
|
||||
double m_max_tokens;
|
||||
|
||||
//
|
||||
// The current number of tokens
|
||||
//
|
||||
uint64_t m_tokens;
|
||||
double m_tokens;
|
||||
|
||||
//
|
||||
// The last time claim() was called (or the object was created).
|
||||
|
Loading…
Reference in New Issue
Block a user