(token)
| 743 | if (now >= data.resetTime) map.delete(key); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | function getCount(map, key, now, win) { |
| 749 | const d = map.get(key); |
| 750 | return (!d || now >= d.resetTime) ? 0 : d.count; |
| 751 | } |
| 752 | |
| 753 | function incCount(map, key, now, win) { |
| 754 | const e = map.get(key); |
| 755 | if (!e || now >= e.resetTime) map.set(key, { count: 1, resetTime: now + win }); |
| 756 | else e.count++; |
| 757 | } |
| 758 | |
| 759 | function checkCircuitBreaker(clientIP) { |
| 760 | const b = circuitBreakers.get(clientIP); |
| 761 | if (!b) return 'CLOSED'; |
| 762 | |
| 763 | const now = Date.now(); |
| 764 | |
| 765 | if (b.state === 'OPEN') { |
| 766 | if (now - b.lastFailureTime >= CIRCUIT_BREAKER.TIMEOUT) { |
| 767 | b.state = 'HALF_OPEN'; |
| 768 | b.halfOpenAttempts = 0; |
no outgoing calls
no test coverage detected