Documentation
¶
Overview ¶
Package ratelimit provides four-tier rate limiting for NACK requests:
- Per-IP token bucket (overall flood protection).
- Per-(srcIP, HashKey) sliding window (per-flow NACK storm cap).
- Per-SeqNum sliding window (per-gap retry cap).
- Per-(srcIP, groupIdx) token bucket (post-lookup retransmit bandwidth cap).
Tiers 1-3 are pre-lookup (call Allow + AllowChain before cache access). Tier 4 is post-lookup (call AllowGroup after cache hit, before Retransmit).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
IPRate float64 // Tokens per second per source IP
IPBurst int // Burst size per source IP
SenderRate float64 // Alias for ChainRate (backward-compat)
SenderWindow time.Duration // Alias for ChainWindow (backward-compat)
ChainRate float64 // Max NACKs per ChainWindow per (srcIP, HashKey)
ChainWindow time.Duration // Sliding window for chain limiter
SequenceMax int // Max requests per SeqNum per SequenceWindow
SequenceWindow time.Duration // Sliding window for sequence limiter
GroupRate float64 // Retransmits per second per (srcIP, groupIdx)
GroupBurst int // Burst size per (srcIP, groupIdx)
}
Config holds rate limiting configuration.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter provides four-tier rate limiting.
func (*Limiter) Allow ¶
Allow checks the IP and sequence tiers (pre-lookup). srcIP is the listener source address; startSeq is the StartSeq field from the NACK datagram (SeqNum of the missing frame). Returns (true, "") if allowed.
func (*Limiter) AllowChain ¶
AllowChain checks the chain tier (pre-lookup, between IP and sequence). hashKey is the HashKey field from the NACK datagram. 0 means the frame was not stamped by the proxy (unstamped); rate-limiting on HashKey=0 would bucket all such unattributed gaps together and prematurely exhaust a shared limit, so the check is skipped.
func (*Limiter) AllowGroup ¶
AllowGroup checks the group tier (post-lookup, before Retransmit). groupIdx is derived from the frame's TxID. Returns true if the retransmit should proceed; false means throttle the retransmit (answered with THROTTLED when the throttle response is enabled, silence otherwise).