Wasm Directoryalpha
Resource

rate-counter

A rate counter that can be used with a edge rate limiter or standalone for counting and rate calculations.

resource rate-counter;

F get-name

get-name: func() -> string;

Returns the name of this rate counter.

F check-rate

check-rate: func(entry: string, delta: u32, window: u32, limit: u32, penalty-box: borrow​<penalty-box>, ttl: u32) -> result​<bool, error>;

Increments an entry in a rate counter and check if the client has exceeded some average number of requests per second (RPS) over the window.

If the client is over the rps limit for the window, add to the penaltybox for ttl. Valid ttl span is 1m to 1h and TTL value is truncated to the nearest minute.

Returns true if the client is penalized (i.e. should be limited), or false if not.

F increment

increment: func(entry: string, delta: u32) -> result​<_, error>;

Increments an entry in the ratecounter by delta.

F lookup-rate

lookup-rate: func(entry: string, window: u32) -> result​<u32, error>;

Looks up the current rate for entry in the ratecounter for a window.

F lookup-count

lookup-count: func(entry: string, duration: u32) -> result​<u32, error>;

Looks up the current count for entry in the ratecounter for duration.

F open

open: func(name: string) -> result​<rate-counter, open-error>;

Opens a rate-counter with the given name.

The name must not exceed 1024 bytes in length. If the name is too long, open-error::name-too-long will be returned.