limit

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRegistrySize = 20000

Variables

This section is empty.

Functions

This section is empty.

Types

type LimitListener

type LimitListener struct {
	net.Listener
	// contains filtered or unexported fields
}

LimitListener wraps a net.Listener and limits the number of concurrent connections. It implements a semaphore using a buffered channel.

func NewLimitListener

func NewLimitListener(l net.Listener, n int) *LimitListener

NewLimitListener creates a listener that accepts at most n concurrent connections.

func (*LimitListener) Accept

func (l *LimitListener) Accept() (net.Conn, error)

type LimiterRegistry

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

LimiterRegistry manages dynamic rate limiters for arbitrary keys (IPs, Users). It handles cleanup of unused limiters and enforces a hard memory cap (MaxRegistrySize).

func NewRegistry

func NewRegistry() *LimiterRegistry

NewRegistry creates a new LimiterRegistry. It does NOT start the cleanup loop automatically; call Run() for that.

func (*LimiterRegistry) GetOrAdd

func (r *LimiterRegistry) GetOrAdd(key string, config RateConfig) *rate.Limiter

GetOrAdd returns the limiter for the given key. If it doesn't exist, it creates one.

func (*LimiterRegistry) Run

func (r *LimiterRegistry) Run(checkInterval, ttl time.Duration)

Run starts the background cleanup goroutine. It removes entries not seen for 'ttl' duration.

func (*LimiterRegistry) Stop

func (r *LimiterRegistry) Stop()

type RateConfig

type RateConfig struct {
	Rate  rate.Limit // Tokens per second
	Burst int        // Max tokens at once
}

RateConfig defines the token bucket parameters.

type SessionTracker

type SessionTracker struct {
	MaxPerIP   int
	MaxPerUser int
	Total      int32 // Atomic total
	MaxTotal   int32
	// contains filtered or unexported fields
}

SessionTracker enforces limits on concurrent SSH sessions.

func NewSessionTracker

func NewSessionTracker(maxIP, maxUser, maxTotal int) *SessionTracker

func (*SessionTracker) Middleware

func (t *SessionTracker) Middleware(next ssh.Handler) ssh.Handler

Middleware returns an ssh.Handler (middleware) that enforces session limits.

Jump to

Keyboard shortcuts

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