Documentation
¶
Overview ¶
Package ratelimit provides the byte token buckets shared by node engines: one per credential (the device limit) and one per user on the node (the person limit, see Registry).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitUp ¶ added in v0.1.39
WaitUp waits until n upload bytes may pass both the device limiter and the person limiter; either may be nil (no such limit). The device bucket goes first: a device held back by its own limit must not sit on tokens of the person bucket that the person's other devices could use. No lock is held while waiting. False: ctx ended.
Types ¶
type Holder ¶ added in v0.1.39
Holder is one credential asking for its user's bucket. BPS 0 (or no user) means the credential has no person limit.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter keeps independent upload and download buckets. BPS is the configured limit in bits per second; SetBPS changes it in place, so everything holding the limiter follows.
type Registry ¶ added in v0.1.39
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the person limit: one Limiter per user id, shared by every credential of that user on this node, in every inbound and every engine. The buckets are per node on purpose: a person on two nodes at once can reach twice the limit, there is no coordination between nodes.
A credential is a holder of its user's bucket. Holders come and go inbound by inbound (Sync); the bucket lives while it has at least one holder, changes its rate in place when the value changes (everything that got it from Sync follows), and is dropped with its last holder. The credentials of one user carry the same value; if they disagree (an inbound applied before its neighbour) the bucket takes the smallest, so the outcome does not depend on the order of arrival.
func NewRegistry ¶ added in v0.1.39
func NewRegistry() *Registry
func (*Registry) Limiter ¶ added in v0.1.39
Limiter returns the bucket of a user, nil when no credential of theirs is limited on this node.
func (*Registry) Sync ¶ added in v0.1.39
Sync makes hs the complete set of holders of scope (an inbound id; nil/empty releases the scope) and returns the bucket of each limited credential, keyed by credential id. The credentials the scope no longer lists let go of their buckets; a bucket nobody holds any more is dropped. Safe for concurrent use; the returned limiters are used without any registry lock.