ratelimiter

package
v0.31.13 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: AGPL-3.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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