Documentation ¶
Index ¶
- type RateLimitUser
- type RateLimiter
- func (rl *RateLimiter) AddRequest(userID common.Address, interval RequestInterval) uuid.UUID
- func (rl *RateLimiter) Allow(userID common.Address) (bool, uuid.UUID)
- func (rl *RateLimiter) CountOpenRequests(userID common.Address) int
- func (rl *RateLimiter) GetMaxConcurrentRequest() uint32
- func (rl *RateLimiter) GetUserComputeTime() time.Duration
- func (rl *RateLimiter) IncrementRateLimitedRequests()
- func (rl *RateLimiter) IncrementTotalRequests()
- func (rl *RateLimiter) PruneRequests()
- func (rl *RateLimiter) SetRequestEnd(userID common.Address, id uuid.UUID)
- func (rl *RateLimiter) SumComputeTime(userID common.Address) time.Duration
- type RequestInterval
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimitUser ¶
type RateLimitUser struct {
CurrentRequests map[uuid.UUID]RequestInterval
}
RateLimitUser represents a user with a map of current requests.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func (*RateLimiter) AddRequest ¶
func (rl *RateLimiter) AddRequest(userID common.Address, interval RequestInterval) uuid.UUID
AddRequest adds a new request interval to a user's current requests and returns the UUID.
func (*RateLimiter) Allow ¶
Allow checks if the user is allowed to make a request based on the rate limit threshold before comparing to the threshold also decays the score of the user based on the decay rate
func (*RateLimiter) CountOpenRequests ¶
func (rl *RateLimiter) CountOpenRequests(userID common.Address) int
CountOpenRequests counts the number of requests without an End time set.
func (*RateLimiter) GetMaxConcurrentRequest ¶
func (rl *RateLimiter) GetMaxConcurrentRequest() uint32
GetMaxConcurrentRequest returns the maximum number of concurrent requests allowed.
func (*RateLimiter) GetUserComputeTime ¶
func (rl *RateLimiter) GetUserComputeTime() time.Duration
GetUserComputeTime returns the user compute time
func (*RateLimiter) IncrementRateLimitedRequests ¶
func (rl *RateLimiter) IncrementRateLimitedRequests()
IncrementRateLimitedRequests increments the total requests counter by 1 with thread safety.
func (*RateLimiter) IncrementTotalRequests ¶
func (rl *RateLimiter) IncrementTotalRequests()
IncrementTotalRequests increments the total requests counter by 1 with thread safety.
func (*RateLimiter) PruneRequests ¶
func (rl *RateLimiter) PruneRequests()
PruneRequests deletes all requests that have ended before the rate limiter's window.
func (*RateLimiter) SetRequestEnd ¶
func (rl *RateLimiter) SetRequestEnd(userID common.Address, id uuid.UUID)
SetRequestEnd updates the end time of a request interval given its UUID.
func (*RateLimiter) SumComputeTime ¶
func (rl *RateLimiter) SumComputeTime(userID common.Address) time.Duration
SumComputeTime sums the compute time for requests within the rate limiter's window and returns it as uint32 milliseconds.