checkAndRecordHash accepts the SHA256 hash ([32]byte) for checking. It now REFRESHES the timestamp whenever a hash is found, effectively creating a sliding deduplication window.
(hash [32]byte)
| 195 | // It now REFRESHES the timestamp whenever a hash is found, |
| 196 | // effectively creating a sliding deduplication window. |
| 197 | func checkAndRecordHash(hash [32]byte) bool { |
| 198 | now := time.Now() |
| 199 | mapMutex.Lock() |
| 200 | defer mapMutex.Unlock() |
| 201 | var zeroHash [32]byte |
| 202 | if hash == zeroHash { |
| 203 | slog.Warn("potentially zero hash received", "hash", fmt.Sprintf("%x", hash)) |
| 204 | } |
| 205 | entry, found := seenIDs[hash] |
| 206 | if found { |
| 207 | isRecentDuplicate := now.Sub(entry.timestamp) < dedupWindow |
| 208 | seenIDs[hash] = seenEntry{timestamp: now} |
| 209 | return !isRecentDuplicate |
| 210 | } |
| 211 | seenIDs[hash] = seenEntry{timestamp: now} |
| 212 | return true |
| 213 | } |
| 214 | |
| 215 | // cleanupExpiredEntries uses the hash ([32]byte) as the key type. |
| 216 | func cleanupExpiredEntries(interval time.Duration) { |