Drafter.Accounts.Throttle (drafter v0.4.0)

Copy Markdown View Source

Failed-login bookkeeping per peer address.

A peer is locked once it has limit failures inside window_ms. Failures older than the window are forgotten, and a success clears the peer.

throttle = Drafter.Accounts.Throttle.new(limit: 5, window_ms: 900_000)
throttle = Drafter.Accounts.Throttle.failed(throttle, {10, 0, 0, 7}, now)
Drafter.Accounts.Throttle.locked?(throttle, {10, 0, 0, 7}, now)

Summary

Functions

Record a failure for peer at millisecond time now.

Whether peer has reached the limit inside the window ending at now.

A throttle with no failures recorded.

Forget peer's failures.

Types

peer()

@type peer() :: term()

t()

@type t() :: %Drafter.Accounts.Throttle{
  failures: %{required(peer()) => [integer()]},
  limit: pos_integer(),
  window_ms: pos_integer()
}

Functions

failed(throttle, peer, now)

@spec failed(t(), peer(), integer()) :: t()

Record a failure for peer at millisecond time now.

locked?(throttle, peer, now)

@spec locked?(t(), peer(), integer()) :: boolean()

Whether peer has reached the limit inside the window ending at now.

new(opts \\ [])

@spec new(keyword()) :: t()

A throttle with no failures recorded.

Options

  • :limit - failures inside the window that lock a peer. Default 5.
  • :window_ms - how long a failure counts, in milliseconds. Default 900_000.

succeeded(throttle, peer)

@spec succeeded(t(), peer()) :: t()

Forget peer's failures.