From dc2f415fc29659acf30eb1df4e501e79f95ccb01 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 14:37:36 +0100 Subject: [PATCH] ax(node): rename ttl to timeToLive in MessageDeduplicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AX Principle 1 — predictable names over short names. The field `ttl` requires context to decode; `timeToLive` is self-describing without a comment. Co-Authored-By: Charon --- pkg/node/transport.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/node/transport.go b/pkg/node/transport.go index 24d32b7..1faf948 100644 --- a/pkg/node/transport.go +++ b/pkg/node/transport.go @@ -61,18 +61,18 @@ type MessageHandler func(conn *PeerConnection, msg *Message) // if dedup.IsDuplicate(msg.ID) { continue } // dedup.Mark(msg.ID) type MessageDeduplicator struct { - seen map[string]time.Time - mutex sync.RWMutex - ttl time.Duration + seen map[string]time.Time + mutex sync.RWMutex + timeToLive time.Duration } // dedup := node.NewMessageDeduplicator(5 * time.Minute) // dedup.Mark(msg.ID) // if dedup.IsDuplicate(msg.ID) { continue } -func NewMessageDeduplicator(ttl time.Duration) *MessageDeduplicator { +func NewMessageDeduplicator(timeToLive time.Duration) *MessageDeduplicator { deduplicator := &MessageDeduplicator{ - seen: make(map[string]time.Time), - ttl: ttl, + seen: make(map[string]time.Time), + timeToLive: timeToLive, } return deduplicator } @@ -92,13 +92,13 @@ func (deduplicator *MessageDeduplicator) Mark(msgID string) { deduplicator.mutex.Unlock() } -// go dedup.Cleanup() // call periodically; entries older than ttl are dropped +// go dedup.Cleanup() // call periodically; entries older than timeToLive are dropped func (deduplicator *MessageDeduplicator) Cleanup() { deduplicator.mutex.Lock() defer deduplicator.mutex.Unlock() now := time.Now() for id, seen := range deduplicator.seen { - if now.Sub(seen) > deduplicator.ttl { + if now.Sub(seen) > deduplicator.timeToLive { delete(deduplicator.seen, id) } }