Rate limiter with configurable attempt limits and lockout windows.
Keys are caller-supplied (caller and dialed numbers), so the number of tracked keys is capped.
Two things keep that cap from becoming a weakness under a flood of distinct keys:
Constant cost per call. Expired entries are swept at most once every
sweepThreshold inserts, not on every failure, and enforcing the cap drops one entry.
Before, each failure past 1,000 keys walked the whole map, so a flood cost O(n) per attempt.
Lockouts are evicted last. Locked-out keys live in their own map, and the cap drops the
oldest key that is still only counting attempts. A locked-out caller can no longer flood
distinct numbers to push their own lockout out of the map; a lockout is dropped only when
every tracked key is locked out.
Rate limiter with configurable attempt limits and lockout windows.
Keys are caller-supplied (caller and dialed numbers), so the number of tracked keys is capped. Two things keep that cap from becoming a weakness under a flood of distinct keys: