concurrent_limiter

package
v0.0.0-...-5f6fcd9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 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

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

type HPClientLimiter

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

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

func NewHPClientLimiter

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

func (*HPClientLimiter) AcquireToken

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

func (*HPClientLimiter) ApplyMask

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

ApplyMask masks the addr by the mask values in HPLimiterOpts.

func (*HPClientLimiter) Close

func (l *HPClientLimiter) Close() error

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

func (*HPClientLimiter) GC

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

GC removes expired client ip entries from this HPClientLimiter.

type HPLimiterOpts

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

func (opts *HPLimiterOpts) Init() error

Jump to

Keyboard shortcuts

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