Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

ratelimit state

Back to all declarations

rate

float64

// one token every 2 blocks

Value

0.5

burst

float64

Limiter configuration, shared by every caller bucket. rate = tokens replenished per block. burst = bucket capacity (max tokens, also the largest single burst).

Value

5

bucket

type

bucket is the per-caller state persisted in the avl tree.

Value

ratelimit.bucket

buckets

*v0.Tree

buckets maps address string -> \*bucket, ordered by key (deterministic).

Open
OID
03950c…4fe8:6
buckets details

Inspect pointer

fmin

func(a float64, b float64) float64

fmin returns the smaller of two float64 values.

Open
OID
03950c…4fe8:8
fmin details

Inspect func

refill

func(tokens float64, last int64, now int64, r float64, cap float64) float64

refill returns the token count at height \`now\` given \`tokens\` observed at height \`last\`, replenishing at \`r\` tokens/block up to capacity \`cap\`. It never decreases below the stored value and never exceeds \`cap\`.

Open
OID
03950c…4fe8:10
refill details

Inspect func

tokensToInt

func(t float64) int

tokensToInt floors a token count to a whole, non-negative token.

Open
OID
03950c…4fe8:11
tokensToInt details

Inspect func

load

func(key string, now int64) *ratelimit.bucket

load returns the live bucket for addr, refilled to \`now\`, creating a full bucket the first time an address is seen.

Open
OID
03950c…4fe8:12
load details

Inspect func

Allow

func() bool

Allow consumes one token for the calling realm/user and reports whether the request is permitted. Returns false (and consumes nothing) when the bucket is empty.

Open
OID
03950c…4fe8:13
Allow details

Inspect func

SetConfig

func(newRate float64, newBurst float64)

SetConfig updates the shared rate (tokens per block) and burst (capacity). Values are clamped to be non-negative; burst is forced to at least 1.

Open
OID
03950c…4fe8:14
SetConfig details

Inspect func

Tokens

func(addr .uverse.address) int

Tokens is a read-only view of how many whole tokens \`addr\` has available at the current block height, without mutating any state.

Open
OID
03950c…4fe8:15
Tokens details

Inspect func

Render

func(path string) string

Render shows the limiter config and a table of known callers with their current tokens and last-seen height. Path "/addr/\<address>" focuses one caller.

Open
OID
03950c…4fe8:17
Render details

Inspect func
rate : float64 =0.5
burst : float64 =5
bucket : type =ratelimit.bucket
buckets : *v0.Tree Inspect
fmin : func(a float64, b float64) float64 Inspect
refill : func(tokens float64, last int64, now int64, r float64, cap float64) float64 Inspect
tokensToInt : func(t float64) int Inspect
load : func(key string, now int64) *ratelimit.bucket Inspect
Allow : func() bool Inspect
SetConfig : func(newRate float64, newBurst float64) Inspect
Tokens : func(addr .uverse.address) int Inspect
ftoa : func(f float64) string Inspect
Render : func(path string) string Inspect