(ip string)
| 92 | } |
| 93 | |
| 94 | func (t *IPTracker) RecordFailure(ip string) { |
| 95 | t.mu.Lock() |
| 96 | defer t.mu.Unlock() |
| 97 | |
| 98 | if record, exists := t.records[ip]; exists { |
| 99 | if !t.prepareRecordUnsafe(ip, record) { |
| 100 | t.removeIPUnsafe(ip) |
| 101 | } else { |
| 102 | record.FailedCount++ |
| 103 | record.LastUpdate = time.Now() |
| 104 | if record.FailedCount >= MaxFailedAttempts { |
| 105 | record.LockedUntil = time.Now().Add(LockDuration) |
| 106 | } |
| 107 | return |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if len(t.records) >= MaxIPCount { |
| 112 | t.removeOldestUnsafe() |
| 113 | } |
| 114 | |
| 115 | t.records[ip] = &IPRecord{ |
| 116 | FailedCount: 1, |
| 117 | LastUpdate: time.Now(), |
| 118 | } |
| 119 | t.ipOrder = append(t.ipOrder, ip) |
| 120 | } |
| 121 | |
| 122 | func (t *IPTracker) Clear(ip string) { |
| 123 | t.mu.Lock() |
no test coverage detected