Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientLimiter ¶
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
Click to show internal directories.
Click to hide internal directories.