PSyncNode

Struct PSyncNode 

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

Partial Sync (PSync) node.

Maintains a local set of content name hashes and an IBF over that set. To reconcile with a peer: compute local_ibf.subtract(peer_ibf) and call decode() to find which hashes each side is missing.

Implementations§

Source§

impl PSyncNode

Source

pub fn new(ibf_size: usize) -> Self

Create a node with an IBF of ibf_size cells and k=3 hash functions.

ibf_size should be significantly larger than the expected set difference; 80 cells handles differences up to ~40 elements with k=3.

Source

pub fn insert(&mut self, hash: u64)

Insert a content hash into the local set.

Source

pub fn remove(&mut self, hash: u64) -> bool

Remove a content hash from the local set. Returns true if present.

Source

pub fn contains(&self, hash: u64) -> bool

Returns true if the local set contains hash.

Source

pub fn len(&self) -> usize

Number of hashes in the local set.

Source

pub fn is_empty(&self) -> bool

Returns true if the local set is empty.

Source

pub fn build_ibf(&self) -> Ibf

Build an IBF over the current local set.

Source

pub fn reconcile(&self, peer_ibf: &Ibf) -> Option<(HashSet<u64>, HashSet<u64>)>

Reconcile with a peer IBF.

Returns Some((hashes_we_have_that_peer_lacks, hashes_peer_has_that_we_lack)) or None if the difference is too large to decode.

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.