Documentation
¶
Overview ¶
Package throttle implements token-bucket bandwidth limiting for proxy connections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MbpsToBytes ¶
MbpsToBytes converts megabits per second to bytes per second.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is a goroutine-safe token-bucket rate limiter.
func NewBucket ¶
NewBucket creates a rate limiter allowing bytesPerSec throughput. Returns nil if bytesPerSec <= 0.
type GroupRegistry ¶
type GroupRegistry struct {
// contains filtered or unexported fields
}
GroupRegistry manages shared bandwidth buckets keyed by a group identifier. All connections with the same group key share a single download/upload budget.
func NewGroupRegistry ¶
func NewGroupRegistry() *GroupRegistry
NewGroupRegistry creates an empty group registry.
func (*GroupRegistry) Acquire ¶
func (g *GroupRegistry) Acquire(key string, dlRate, ulRate int64) (dl, ul *Bucket)
Acquire returns shared download/upload buckets for the given key, creating them on first call. Each Acquire must be paired with Release. If rates differ from the existing entry, the bucket rates are updated.
func (*GroupRegistry) Release ¶
func (g *GroupRegistry) Release(key string)
Release decrements the reference count for the given key. When the count reaches zero, the entry is removed.
func (*GroupRegistry) UpdateRate ¶
func (g *GroupRegistry) UpdateRate(key string, dlRate, ulRate int64)
UpdateRate changes the download/upload rates for an existing group. Non-positive values are ignored. No-op if the group does not exist.
type Limits ¶
Limits holds per-direction bandwidth buckets for a connection.
func FromContext ¶
FromContext extracts Limits from the context, or nil if not set.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader throttles reads through one or more Buckets.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer throttles writes through one or more Buckets.