# `Drafter.Accounts.Throttle`
[🔗](https://github.com/jaman/drafter/blob/main/lib/drafter/accounts/throttle.ex#L1)

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)

# `peer`

```elixir
@type peer() :: term()
```

# `t`

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

# `failed`

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

Record a failure for `peer` at millisecond time `now`.

# `locked?`

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

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

# `new`

```elixir
@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`

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

Forget `peer`'s failures.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
