* Returns true if the connection should be allowed.
(ip: string)
| 32 | * Returns true if the connection should be allowed. |
| 33 | */ |
| 34 | allow(ip: string): boolean { |
| 35 | const now = Date.now(); |
| 36 | const timestamps = this.attempts.get(ip) ?? []; |
| 37 | |
| 38 | // Prune old entries |
| 39 | const recent = timestamps.filter((t) => now - t < this.windowMs); |
| 40 | |
| 41 | if (recent.length >= this.maxPerWindow) { |
| 42 | this.attempts.set(ip, recent); |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | recent.push(now); |
| 47 | this.attempts.set(ip, recent); |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Periodically clean up stale entries. |
no test coverage detected