pub struct Deduplicator { /* private fields */ }Expand description
Deduplicator for tracking seen messages and preventing duplicates.
Supports two modes:
- HashMap mode: exact tracking with FIFO eviction (original behavior)
- Bloom filter mode: O(1) memory with probabilistic duplicate detection
Implementations§
Source§impl Deduplicator
impl Deduplicator
Sourcepub fn with_config(config: DeduplicatorConfig) -> Self
pub fn with_config(config: DeduplicatorConfig) -> Self
Creates a new deduplicator with custom configuration.
Sourcepub fn is_exact(&self) -> bool
pub fn is_exact(&self) -> bool
Returns true when deduplication is exact (HashMap mode): a positive
Self::is_duplicate answer is then authoritative. In bloom mode
(false) a positive answer may be a false positive (~1% with default
settings), so callers must not treat a hit as proof of a prior send.
Sourcepub fn is_duplicate(&self, message_id: &MessageId) -> bool
pub fn is_duplicate(&self, message_id: &MessageId) -> bool
Checks if a message has been seen before.
§Arguments
message_id- The message ID to check
§Returns
Returns true if the message has been seen, false otherwise.
Note: In bloom filter mode, this may return false positives (claiming a message is a duplicate when it isn’t). The false positive rate is typically below 1% with default settings.
Sourcepub fn is_duplicate_mut(&mut self, message_id: &MessageId) -> bool
pub fn is_duplicate_mut(&mut self, message_id: &MessageId) -> bool
Checks if a message has been seen before (mutable version for bloom rotation and LRU access tracking).
Sourcepub fn unmark_seen(&mut self, message_id: &MessageId) -> bool
pub fn unmark_seen(&mut self, message_id: &MessageId) -> bool
Removes a message from the seen set so a future copy is processed fresh instead of being treated as a duplicate.
Intended for receivers that reject a message after marking it seen (e.g. an encryption-policy or security-gate rejection): forgetting the id makes a replay re-enter the same gate — and be rejected again without a delivery ACK — instead of hitting the duplicate re-ACK path, which would confirm to an injector that the target is online.
§Returns
Returns true if the message was tracked and has been removed.
Bloom filters do not support removal, so in bloom filter mode this is
a no-op returning false: a replayed rejected message is treated as a
duplicate until its filter window rotates out.
Sourcepub fn cleanup_expired(&mut self) -> usize
pub fn cleanup_expired(&mut self) -> usize
Removes expired entries that exceed the retention time.
§Returns
Returns the number of entries removed.
Note: In bloom filter mode, expiration is handled automatically through filter rotation, so this returns 0.
Sourcepub fn tracked_count(&self) -> usize
pub fn tracked_count(&self) -> usize
Gets the number of messages currently being tracked.
Note: In bloom filter mode, this returns an estimate based on insertion count.
Sourcepub fn is_tracked(&self, message_id: &MessageId) -> bool
pub fn is_tracked(&self, message_id: &MessageId) -> bool
Checks if a message ID is being tracked (seen).
Sourcepub fn is_bloom_filter_mode(&self) -> bool
pub fn is_bloom_filter_mode(&self) -> bool
Returns whether bloom filter mode is active.
Sourcepub fn stats(&self) -> DeduplicatorStats
pub fn stats(&self) -> DeduplicatorStats
Gets statistics about the deduplicator.
Sourcepub fn estimated_memory_bytes(&self) -> usize
pub fn estimated_memory_bytes(&self) -> usize
Gets the estimated memory usage in bytes.