mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-05-13 00:08:34 -05:00
Fix var leaky bucket initialization for bucket manager
in bucket manager we never call NewVarBucket() so fields are not correct
This commit is contained in:
@@ -108,15 +108,19 @@ type VarLeakyBucket[TKey comparable] struct {
|
||||
}
|
||||
|
||||
func NewVarBucket[TKey comparable](key TKey, capacity TLevel, leakInterval time.Duration, t time.Time) *VarLeakyBucket[TKey] {
|
||||
b := &VarLeakyBucket[TKey]{
|
||||
leakRate: 1.0, // to start like the ConstLeakyBucket, we leak 1 level per leakInterval
|
||||
pendingSum: 0,
|
||||
count: 1, // this is needed to have "previous" empty bucket for averages
|
||||
}
|
||||
b := &VarLeakyBucket[TKey]{}
|
||||
b.Init(key, capacity, leakInterval, t)
|
||||
return b
|
||||
}
|
||||
|
||||
func (lb *VarLeakyBucket[TKey]) Init(key TKey, capacity TLevel, leakInterval time.Duration, tnow time.Time) {
|
||||
lb.ConstLeakyBucket.Init(key, capacity, leakInterval, tnow)
|
||||
|
||||
lb.leakRate = 1.0 // to start like the ConstLeakyBucket, we leak 1 level per leakInterval
|
||||
lb.pendingSum = 0
|
||||
lb.count = 1 // this is needed to have "previous" empty bucket for averages
|
||||
}
|
||||
|
||||
func (lb *VarLeakyBucket[TKey]) LeakInterval() time.Duration {
|
||||
nanoseconds := float64(lb.leakInterval.Nanoseconds()) / lb.leakRate
|
||||
return time.Duration(nanoseconds) * time.Nanosecond
|
||||
|
||||
Reference in New Issue
Block a user