ratelimiter

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: Apache-2.0, BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Events

type Events struct {
	Hit *event.Event[*HitEvent]
}

type HitEvent

type HitEvent struct {
	Peer      *peer.Peer
	RateLimit *RateLimit
}

type PeerRateLimiter

type PeerRateLimiter struct {
	Events *Events
	// contains filtered or unexported fields
}

PeerRateLimiter is an object to count activity of peers and notify the subscribers in case the limit of activity is exceeded.

func NewPeerRateLimiter

func NewPeerRateLimiter(interval time.Duration, baseLimit int, log *logger.Logger) (*PeerRateLimiter, error)

NewPeerRateLimiter returns a new instance of the PeerRateLimiter object.

func (*PeerRateLimiter) Close

func (prl *PeerRateLimiter) Close()

Close closes PeerRateLimiter instance, it can't be used after that.

func (*PeerRateLimiter) Count

func (prl *PeerRateLimiter) Count(p *peer.Peer)

Count counts a new activity of the peer towards its rate limit.

func (*PeerRateLimiter) ExtendLimit

func (prl *PeerRateLimiter) ExtendLimit(p *peer.Peer, val int)

ExtendLimit extends the activity limit of the peer.

func (*PeerRateLimiter) SetBaseLimit

func (prl *PeerRateLimiter) SetBaseLimit(limit int)

SetBaseLimit updates the value of the base limit.

type RateLimit

type RateLimit struct {
	Interval time.Duration
	Limit    int
}

RateLimit contains information about rate limit values such as time interval and the limit.

func (RateLimit) String

func (rl RateLimit) String() string

String return a string representation of the RateLimit instance.

Jump to

Keyboard shortcuts

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