mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-01-03 22:43:09 +00:00
chore: renaming
This commit is contained in:
parent
e42defcfef
commit
9385c1e2f9
@ -17,20 +17,20 @@ const RlnLimiterRefillInterval = 10 * time.Minute
|
||||
// RlnRateLimiter is used to rate limit the outgoing messages,
|
||||
// The capacity and refillAfter comes from RLN contract configuration.
|
||||
type RlnRateLimiter struct {
|
||||
mu sync.Mutex
|
||||
capacity int
|
||||
tokens int
|
||||
refillAfter time.Duration
|
||||
lastRefill time.Time
|
||||
mu sync.Mutex
|
||||
capacity int
|
||||
tokens int
|
||||
refillInterval time.Duration
|
||||
lastRefill time.Time
|
||||
}
|
||||
|
||||
// NewRlnPublishRateLimiter creates a new rate limiter, starts with a full capacity bucket.
|
||||
func NewRlnRateLimiter(capacity int, refillAfter time.Duration) *RlnRateLimiter {
|
||||
func NewRlnRateLimiter(capacity int, refillInterval time.Duration) *RlnRateLimiter {
|
||||
return &RlnRateLimiter{
|
||||
capacity: capacity,
|
||||
tokens: capacity, // Start with a full bucket
|
||||
refillAfter: refillAfter,
|
||||
lastRefill: time.Now(),
|
||||
capacity: capacity,
|
||||
tokens: capacity, // Start with a full bucket
|
||||
refillInterval: refillInterval,
|
||||
lastRefill: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ func (rl *RlnRateLimiter) Allow() bool {
|
||||
|
||||
// Refill tokens if the refill interval has passed
|
||||
now := time.Now()
|
||||
if now.Sub(rl.lastRefill) >= rl.refillAfter {
|
||||
if now.Sub(rl.lastRefill) >= rl.refillInterval {
|
||||
rl.tokens = rl.capacity // Refill the bucket
|
||||
rl.lastRefill = now
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user