ratelimiter

package
v0.38.0-preview.0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	component.Component
	// contains filtered or unexported fields
}

RateLimiter generic rate limiter

func NewRateLimiter

func NewRateLimiter(limit rate.Limit, burst int, lockoutDuration time.Duration, opts ...p2p.RateLimiterOpt) *RateLimiter

NewRateLimiter returns a new RateLimiter.

func (*RateLimiter) Allow

func (r *RateLimiter) Allow(peerID peer.ID, _ int) bool

Allow checks the cached limiter for the peer and returns limiterMap.Allow(). If a limiter is not cached for a peer one is created. This func can be overridden and the message size parameter can be used with AllowN.

func (*RateLimiter) GetLimiter

func (r *RateLimiter) GetLimiter(peerID peer.ID) *rate.Limiter

GetLimiter returns limiter for the peerID, if a limiter does not exist one is created and stored.

func (*RateLimiter) IsRateLimited

func (r *RateLimiter) IsRateLimited(peerID peer.ID) bool

IsRateLimited returns true is a peer is currently rate limited.

func (*RateLimiter) UpdateLastRateLimit

func (r *RateLimiter) UpdateLastRateLimit(peerID peer.ID, lastRateLimit time.Time)

UpdateLastRateLimit updates the last time a peer was rate limited in the limiter map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL