Documentation
¶
Index ¶
Constants ¶
const MaxRegistrySize = 20000
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LimitListener ¶
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.
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 ¶
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.