(ip string)
| 263 | } |
| 264 | |
| 265 | func (m *Manager) recordFailure(ip string) { |
| 266 | m.failMu.Lock() |
| 267 | defer m.failMu.Unlock() |
| 268 | now := time.Now() |
| 269 | a, ok := m.failures[ip] |
| 270 | if !ok || now.After(a.windowEnd) { |
| 271 | m.failures[ip] = &loginAttempt{count: 1, windowEnd: now.Add(loginWindow)} |
| 272 | return |
| 273 | } |
| 274 | a.count++ |
| 275 | if a.count >= maxLoginFailures { |
| 276 | // 超限后将窗口延长为锁定时长 |
| 277 | a.windowEnd = now.Add(loginLockDuration) |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | func (m *Manager) clearFailures(ip string) { |
| 282 | m.failMu.Lock() |
no test coverage detected