concurrent_limiter

package
v4.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientLimiter added in v4.2.0

type ClientLimiter interface {
	AcquireToken(addr netip.Addr) bool
}

type HPClientLimiter added in v4.2.0

type HPClientLimiter struct {
	// contains filtered or unexported fields
}

HPClientLimiter is a ClientLimiter for heavy workload. It uses sharded locks.

func NewHPClientLimiter added in v4.2.0

func NewHPClientLimiter(opts HPLimiterOpts) (*HPClientLimiter, error)

func (*HPClientLimiter) AcquireToken added in v4.3.0

func (l *HPClientLimiter) AcquireToken(addr netip.Addr) bool

func (*HPClientLimiter) ApplyMask added in v4.3.0

func (l *HPClientLimiter) ApplyMask(addr netip.Addr) netip.Prefix

ApplyMask masks the addr by the mask values in HPLimiterOpts.

func (*HPClientLimiter) Close added in v4.3.0

func (l *HPClientLimiter) Close() error

Close closes HPClientLimiter's cleaner (if it was started). Close always returns a nil error.

func (*HPClientLimiter) GC added in v4.2.0

func (l *HPClientLimiter) GC(now time.Time)

GC removes expired client ip entries from this HPClientLimiter.

type HPLimiterOpts added in v4.3.0

type HPLimiterOpts struct {
	// The rate limit is calculated by Threshold / Interval.
	// Threshold cannot be negative.
	Threshold int
	Interval  time.Duration // Default is 1s.

	// IP masks to aggregate a IP range.
	IPv4Mask int // Default is 32.
	IPv6Mask int // Default is 48.

	// Default is 10s. Negative value disables the cleaner.
	CleanerInterval time.Duration
}

func (*HPLimiterOpts) Init added in v4.3.0

func (opts *HPLimiterOpts) Init() error

Jump to

Keyboard shortcuts

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