mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-30 21:25:06 +00:00
Allow the initial time to be externally provided.
Allow the initial start time to be externally provided. Saves a call to getttimeofday and allows running from an external clock (i.e. trace files).
This commit is contained in:
parent
f5ce6752be
commit
c066be3905
@ -31,12 +31,18 @@ token_bucket::~token_bucket()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void token_bucket::init(double rate, double max_tokens)
|
void token_bucket::init(double rate, double max_tokens, uint64_t now)
|
||||||
{
|
{
|
||||||
m_rate = rate;
|
m_rate = rate;
|
||||||
m_max_tokens = max_tokens;
|
m_max_tokens = max_tokens;
|
||||||
m_tokens = max_tokens;
|
m_tokens = max_tokens;
|
||||||
m_last_seen = sinsp_utils::get_current_time_ns();
|
|
||||||
|
if(now == 0)
|
||||||
|
{
|
||||||
|
now = sinsp_utils::get_current_time_ns();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_last_seen = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool token_bucket::claim(uint64_t now)
|
bool token_bucket::claim(uint64_t now)
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
//
|
//
|
||||||
// Initialize the token bucket and start accumulating tokens
|
// Initialize the token bucket and start accumulating tokens
|
||||||
//
|
//
|
||||||
void init(double rate, double max_tokens);
|
void init(double rate, double max_tokens, uint64_t now = 0);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns true if a token can be claimed. Also updates
|
// Returns true if a token can be claimed. Also updates
|
||||||
|
Loading…
Reference in New Issue
Block a user