Karta. SMTP. Limiter
(Karta v1.0.0)
Per-client connection limits for one listener:
- at most
max_per_ipsimultaneous connections per client, and - at most
ratenew connections per client perrate_windowmilliseconds.
A client is an IPv4 address or an IPv6 /64 prefix (one end site usually
holds a whole /64, so per-address limits would be trivial to evade).
Addresses in exempt (CIDR strings) are counted but never refused.
The limiter monitors each connection process, so a crashed or killed
connection frees its slot. It also counts all open connections of the
listener; stressed?/1 is true from stress_threshold connections on, and
the handler then uses its short stress-mode timeout.
The count belongs to the node the sockets are open on, so it is kept per
node: several nodes each protect their own listener. While the limiter's
process is restarting, its table is gone and the reads answer false and
0 rather than crash a connection.
Summary
Functions
Takes a connection slot for ip, owned by the calling process until it exits.
Returns a specification to start this module under a supervisor.
Open connections for a client key; for tests and diagnostics.
The client key: the IPv4 address, or the IPv6 /64 prefix (Karta.CIDR.client_key/1).
True when the listener has stress_threshold or more open connections.
Types
Functions
@spec acquire(GenServer.server(), :inet.ip_address()) :: :ok | {:error, reason()}
Takes a connection slot for ip, owned by the calling process until it exits.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec count(atom(), :inet.ip_address()) :: non_neg_integer()
Open connections for a client key; for tests and diagnostics.
@spec key(:inet.ip_address()) :: :inet.ip_address()
The client key: the IPv4 address, or the IPv6 /64 prefix (Karta.CIDR.client_key/1).
True when the listener has stress_threshold or more open connections.