Skip to main content

PacketHashlist

Struct PacketHashlist 

Source
pub struct PacketHashlist { /* private fields */ }
Expand description

Bounded FIFO packet-hash deduplication.

Retains at most max_size unique packet hashes. New unique hashes are appended in insertion order; when full, the oldest retained hash is evicted. Re-inserting a retained hash is a no-op and does not refresh its recency.

Implementations§

Source§

impl PacketHashlist

Source

pub fn new(max_size: usize) -> Self

Source

pub fn with_allocation( max_size: usize, allocation: PacketHashlistAllocation, ) -> Self

A table retaining up to max_size hashes. Its storage is allocated once, at full size, and never moved or freed while the table lives, so growth leaves no freed blocks behind for the allocator to keep. Eager touches every slot up front; Lazy leaves the slots to be touched as hashes are written, in order, and uses a prefix of the index that doubles with occupancy, so a table’s resident memory follows the hashes it holds.

Source

pub fn seed_hashing(&mut self, seed: u64)

Key bucket placement with a secret seed, so that senders cannot grind packets whose hashes share a probe sequence. Unseeded tables index buckets by the hashes’ leading bits.

Source

pub fn is_duplicate(&self, hash: &[u8; 32]) -> bool

Check if a hash is currently retained.

Source

pub fn prefetch(&self, hash: &[u8; 32])

Start loading the bucket a lookup of hash probes first, so a later is_duplicate or add for it can overlap that cache miss with other work.

Source

pub fn add(&mut self, hash: [u8; 32])

Retain a hash. If the dedup table is full, evict the oldest unique hash.

Source

pub fn remove(&mut self, hash: &[u8; 32]) -> bool

Stop retaining a hash, preserving the FIFO order of all other entries.

Source

pub fn len(&self) -> usize

Total number of retained packet hashes.

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = [u8; 32]> + '_

Iterate retained hashes from oldest to newest, as stored: the first 16 bytes of each, the rest zero. add takes them back unchanged.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.