(ip string)
| 67 | } |
| 68 | |
| 69 | func (t *IPTracker) SetNeedCaptcha(ip string) { |
| 70 | t.mu.Lock() |
| 71 | defer t.mu.Unlock() |
| 72 | |
| 73 | if record, exists := t.records[ip]; exists { |
| 74 | if !t.prepareRecordUnsafe(ip, record) { |
| 75 | t.removeIPUnsafe(ip) |
| 76 | } else { |
| 77 | record.NeedCaptcha = true |
| 78 | record.LastUpdate = time.Now() |
| 79 | return |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if len(t.records) >= MaxIPCount { |
| 84 | t.removeOldestUnsafe() |
| 85 | } |
| 86 | |
| 87 | t.records[ip] = &IPRecord{ |
| 88 | NeedCaptcha: true, |
| 89 | LastUpdate: time.Now(), |
| 90 | } |
| 91 | t.ipOrder = append(t.ipOrder, ip) |
| 92 | } |
| 93 | |
| 94 | func (t *IPTracker) RecordFailure(ip string) { |
| 95 | t.mu.Lock() |
no test coverage detected