From cd58d593789c6facb1d05b7f255bc2c5f2e46010 Mon Sep 17 00:00:00 2001 From: Gab Virebent Date: Mon, 3 Aug 2026 17:13:50 +0200 Subject: Initial import: n2usenet HTTPS/Nym Usenet gateway --- internal/storage/replay.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 internal/storage/replay.go (limited to 'internal/storage/replay.go') diff --git a/internal/storage/replay.go b/internal/storage/replay.go new file mode 100644 index 0000000..a2366a4 --- /dev/null +++ b/internal/storage/replay.go @@ -0,0 +1,32 @@ +package storage + +import ( + "sync" + "time" +) + +type ReplayCache struct { + ttl time.Duration + mu sync.Mutex + data map[string]time.Time +} + +func NewReplayCache(ttl time.Duration) *ReplayCache { + return &ReplayCache{ttl: ttl, data: map[string]time.Time{}} +} + +func (c *ReplayCache) CheckAndMark(hash string) (bool, error) { + c.mu.Lock() + defer c.mu.Unlock() + now := time.Now() + for k, ts := range c.data { + if now.Sub(ts) > c.ttl { + delete(c.data, k) + } + } + if _, exists := c.data[hash]; exists { + return true, nil + } + c.data[hash] = now + return false, nil +} -- cgit v1.2.3