ax(node): rename ttl to timeToLive in MessageDeduplicator
Some checks failed
Test / test (push) Waiting to run
Security Scan / security (push) Has been cancelled

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 <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 14:37:36 +01:00
parent 67ecffed94
commit dc2f415fc2
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -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)
}
}