Documentation
¶
Overview ¶
Package limits implements the relay's two rate controls: a per-pair byte budget (protects one pair's bandwidth from starving others sharing the host) and a per-IP connection-attempt budget (bounds the cost of unauthenticated upgrade attempts before a pair even exists). See the build plan's Step 2 — these are deliberately simple token buckets, not a distributed rate limiter; the relay is a single process per deploy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is a per-pair byte-rate limiter. Burst is set to one second's worth of the configured rate, which is generous enough not to choke a single large NDJSON chunk while still bounding sustained throughput.
func NewBucket ¶
NewBucket builds a Bucket allowing bytesPerSec sustained, bursting up to bytesPerSec in one go (i.e. a single very large frame at MaxFrameBytes still gets through as long as it's under the burst, rather than being rejected outright).
type IPLimiter ¶
type IPLimiter struct {
// contains filtered or unexported fields
}
IPLimiter bounds new-connection attempts per source IP, independent of whether a pair ends up existing — this is what keeps an unauthenticated flood of upgrade requests cheap to reject.
func NewIPLimiter ¶
NewIPLimiter builds a limiter allowing perMin connection attempts per minute per source IP, with a burst equal to perMin (so a legitimate client reconnecting a few times in quick succession after a network blip isn't punished).
func (*IPLimiter) Allow ¶
Allow reports whether ip may attempt a new connection now, lazily creating that IP's bucket on first sight.