Documentation
¶
Index ¶
- type AtomicManager
- func (am *AtomicManager) Allow(addr net.Addr) bool
- func (am *AtomicManager) AllowConnection(addr net.Addr) bool
- func (am *AtomicManager) AllowPublish(clientID string) bool
- func (am *AtomicManager) AllowSubscribe(clientID string) bool
- func (am *AtomicManager) Load() *Manager
- func (am *AtomicManager) OnClientDisconnect(clientID string)
- func (am *AtomicManager) Stop()
- func (am *AtomicManager) Swap(m *Manager) *Manager
- type ClientRateLimiter
- type Config
- type ConnectionConfig
- type IPRateLimiter
- type Manager
- type MessageConfig
- type RateLimitResult
- type SubscribeConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AtomicManager ¶
type AtomicManager struct {
// contains filtered or unexported fields
}
AtomicManager wraps a Manager behind an atomic pointer, allowing the underlying rate limiter to be swapped at runtime without data races. It implements the same interfaces as Manager (IPRateLimiter, RateLimiter, ClientRateLimiter) so it can be used as a drop-in replacement.
func NewAtomicManager ¶
func NewAtomicManager(m *Manager) *AtomicManager
NewAtomicManager creates an AtomicManager with the given initial Manager.
func (*AtomicManager) AllowConnection ¶
func (am *AtomicManager) AllowConnection(addr net.Addr) bool
func (*AtomicManager) AllowPublish ¶
func (am *AtomicManager) AllowPublish(clientID string) bool
func (*AtomicManager) AllowSubscribe ¶
func (am *AtomicManager) AllowSubscribe(clientID string) bool
func (*AtomicManager) Load ¶
func (am *AtomicManager) Load() *Manager
Load returns the current Manager.
func (*AtomicManager) OnClientDisconnect ¶
func (am *AtomicManager) OnClientDisconnect(clientID string)
func (*AtomicManager) Stop ¶
func (am *AtomicManager) Stop()
func (*AtomicManager) Swap ¶
func (am *AtomicManager) Swap(m *Manager) *Manager
Swap replaces the underlying Manager with a new one and stops the old one. Returns the old Manager.
type ClientRateLimiter ¶
type ClientRateLimiter struct {
// contains filtered or unexported fields
}
ClientRateLimiter manages rate limiting for individual MQTT clients. Used to limit message publishing and subscription rates per client.
func NewClientRateLimiter ¶
func NewClientRateLimiter(messageRate float64, messageBurst int, subRate float64, subBurst int) *ClientRateLimiter
NewClientRateLimiter creates a new client-based rate limiter.
func (*ClientRateLimiter) AllowPublish ¶
func (l *ClientRateLimiter) AllowPublish(clientID string) bool
AllowPublish checks if a publish from the given client is allowed. Returns true if allowed, false if rate limited.
func (*ClientRateLimiter) AllowSubscribe ¶
func (l *ClientRateLimiter) AllowSubscribe(clientID string) bool
AllowSubscribe checks if a subscription from the given client is allowed. Returns true if allowed, false if rate limited.
func (*ClientRateLimiter) RemoveClient ¶
func (l *ClientRateLimiter) RemoveClient(clientID string)
RemoveClient removes rate limiters for a disconnected client.
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
Connection ConnectionConfig `yaml:"connection"`
Message MessageConfig `yaml:"message"`
Subscribe SubscribeConfig `yaml:"subscribe"`
}
Config holds rate limiting configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a sensible default configuration.
type ConnectionConfig ¶
type ConnectionConfig struct {
Enabled bool `yaml:"enabled"`
Rate float64 `yaml:"rate"` // connections per second per IP
Burst int `yaml:"burst"` // burst allowance
CleanupInterval time.Duration `yaml:"cleanup_interval"` // cleanup interval for stale entries
}
ConnectionConfig holds per-IP connection rate limiting settings.
type IPRateLimiter ¶
type IPRateLimiter struct {
// contains filtered or unexported fields
}
IPRateLimiter manages rate limiting for IP addresses (connection layer). Used to limit connection attempts per IP to prevent DoS attacks.
func NewIPRateLimiter ¶
func NewIPRateLimiter(r float64, burst int, cleanupInterval time.Duration) *IPRateLimiter
NewIPRateLimiter creates a new IP-based rate limiter. rate is connections per second, burst is the burst allowance.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates all rate limiters.
func (*Manager) Allow ¶
Allow implements the IPRateLimiter interface used by TCP and WebSocket servers.
func (*Manager) AllowConnection ¶
AllowConnection checks if a new connection from the given address is allowed.
func (*Manager) AllowPublish ¶
AllowPublish checks if a publish from the given client is allowed.
func (*Manager) AllowSubscribe ¶
AllowSubscribe checks if a subscription from the given client is allowed.
func (*Manager) OnClientDisconnect ¶
OnClientDisconnect cleans up rate limiters for a disconnected client.
type MessageConfig ¶
type MessageConfig struct {
Enabled bool `yaml:"enabled"`
Rate float64 `yaml:"rate"` // messages per second per client
Burst int `yaml:"burst"` // burst allowance
}
MessageConfig holds per-client message rate limiting settings.
type RateLimitResult ¶
RateLimitResult represents the result of a rate limit check.
type SubscribeConfig ¶
type SubscribeConfig struct {
Enabled bool `yaml:"enabled"`
Rate float64 `yaml:"rate"` // subscriptions per second per client
Burst int `yaml:"burst"` // burst allowance
}
SubscribeConfig holds per-client subscription rate limiting settings.