Struct NodeBucketStorage

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

Implements the XOR distance-based bucketing system described in BEP0005 (more or less).

NodeBucketStorage keeps one bucket with capacity k for each bit of the DHT’s info hashes. Since the mainline DHT uses 20 byte (160 bit) info hashes, this object will by default keep a maximum of 160 buckets of size k.

As described in BEP0005, the buckets are organized according to an XOR distance metric so that Nodes with ids closer to our DHT’s Id are given the most storage space. The first bucket stores Nodes that have a zero (or more) bit prefix in common with the DHT Id. The second bucket stores Nodes that have a one (or more) bit prefix in common with the DHT Id. Two or more bits in the third. Three or more bits in the 4th. And so on.

Implementations§

Source§

impl NodeBucketStorage

Source

pub fn new(our_id: Id, k: usize) -> NodeBucketStorage

Create a new NodeBucketStorage.

§Parameters
  • our_id - the current Id of the DHT node that will use this object for storage. Nodes will be assigned to buckets based on the XOR distance between their Id and this one.
  • k - the number of nodes that can be stored in a bucket.

Trait Implementations§

Source§

impl Clone for NodeBucketStorage

Source§

fn clone(&self) -> NodeBucketStorage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl NodeStorage for NodeBucketStorage

Source§

fn add_or_update(&mut self, node: Node, verified: bool)

Add a Node to storage, or update the record of a Node already in storage. Read more
Source§

fn clear(&mut self)

Erase all Nodes from storage, resetting this object to its empty state
Source§

fn count(&self) -> (usize, usize)

Return the number of Nodes that have been verified (last_verified property is not None) and the number that haven’t. Read more
Source§

fn get_all_unverified(&self) -> Vec<NodeWrapper>

Return a copy of the records for all the unverified Nodes
Source§

fn get_all_verified(&self) -> Vec<NodeWrapper>

Return a copy of the records for all verified Nodes
Source§

fn get_nearest_nodes(&self, id: &Id, exclude: Option<&Id>) -> Vec<Node>

Return a copy of the nearest nodes to the provided Id. Read more
Source§

fn prune(&mut self, grace_period: Duration, unverified_grace_period: Duration)

Prune (remove) records of Nodes tht haven’t been seen/verified recently.node_wrapper Read more
Source§

fn set_id(&mut self, new_id: Id)

Set our own DHT node’s Id. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V