pub struct P2pNetworkKadRoutingTable<const K: usize = 20> {
pub this_key: P2pNetworkKadKey,
pub buckets: Vec<P2pNetworkKadBucket<K>>,
}Expand description
Kademlia routing table, with K parameter, the maximum number of records
for each bucket. Usually it is set to 20.
Fields§
§this_key: P2pNetworkKadKeySHA256 of the current node’s id.
buckets: Vec<P2pNetworkKadBucket<K>>Kademlia K-buckets. Under index i located elements within distance
2^(256-i) from the current node at most. If there is also i+1 (i.e.
i is not the last index), then distance from the current node to the
elements under i are greater than 2^(256-i-1).
Implementations§
Source§impl<const K: usize> P2pNetworkKadRoutingTable<K>
impl<const K: usize> P2pNetworkKadRoutingTable<K>
pub fn new(this_entry: P2pNetworkKadEntry) -> Self
Sourcepub fn insert(
&mut self,
entry: P2pNetworkKadEntry,
) -> Result<bool, P2pNetworkKadRoutingTableInsertError>
pub fn insert( &mut self, entry: P2pNetworkKadEntry, ) -> Result<bool, P2pNetworkKadRoutingTableInsertError>
Inserts the entry into the routing table.
Returns Ok(true) it is added as a new entry, and Ok(false) if an
existing one has been updated.
If there is no space for adding the new entry (i.e. corresponding
K-bucket is full and cannot be split), then Err(_) value is returned.
TODO: should it be just another variant in Ok(_)?
Filters entry.addrs for supported addresses if non of addresses are supported returns Err(_)
Sourcepub fn look_up(&self, key: &P2pNetworkKadKey) -> Option<&P2pNetworkKadEntry>
pub fn look_up(&self, key: &P2pNetworkKadKey) -> Option<&P2pNetworkKadEntry>
Looks up a Kademlia entry with the specified key.
Sourcepub fn find_node<'a>(
&'a self,
key: &'a P2pNetworkKadKey,
) -> impl Iterator<Item = &'a P2pNetworkKadEntry>
pub fn find_node<'a>( &'a self, key: &'a P2pNetworkKadKey, ) -> impl Iterator<Item = &'a P2pNetworkKadEntry>
FIND_NODE backend. Returns iterator of nodes closest to the specified
key, excluding nodes that correspond to the key itself and
self.this_key.
The number of entries is limited to 20.
Sourcepub fn closest_peers<'a>(
&'a self,
key: &'a P2pNetworkKadKey,
) -> ClosestPeers<'a, K> ⓘ
pub fn closest_peers<'a>( &'a self, key: &'a P2pNetworkKadKey, ) -> ClosestPeers<'a, K> ⓘ
Returns iterator of nodes closest to the current one. TODO: use reverse order over bucket, from the deepest bucket.
Trait Implementations§
Source§impl<const K: usize> Clone for P2pNetworkKadRoutingTable<K>
impl<const K: usize> Clone for P2pNetworkKadRoutingTable<K>
Source§fn clone(&self) -> P2pNetworkKadRoutingTable<K>
fn clone(&self) -> P2pNetworkKadRoutingTable<K>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const K: usize> Debug for P2pNetworkKadRoutingTable<K>
impl<const K: usize> Debug for P2pNetworkKadRoutingTable<K>
Source§impl<const K: usize> Default for P2pNetworkKadRoutingTable<K>
impl<const K: usize> Default for P2pNetworkKadRoutingTable<K>
Source§impl<'de, const K: usize> Deserialize<'de> for P2pNetworkKadRoutingTable<K>
impl<'de, const K: usize> Deserialize<'de> for P2pNetworkKadRoutingTable<K>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Extend<P2pNetworkKadEntry> for P2pNetworkKadRoutingTable
impl Extend<P2pNetworkKadEntry> for P2pNetworkKadRoutingTable
Source§fn extend<T: IntoIterator<Item = P2pNetworkKadEntry>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = P2pNetworkKadEntry>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<const K: usize> MallocSizeOf for P2pNetworkKadRoutingTable<K>
impl<const K: usize> MallocSizeOf for P2pNetworkKadRoutingTable<K>
Auto Trait Implementations§
impl<const K: usize> Freeze for P2pNetworkKadRoutingTable<K>
impl<const K: usize> RefUnwindSafe for P2pNetworkKadRoutingTable<K>
impl<const K: usize> Send for P2pNetworkKadRoutingTable<K>
impl<const K: usize> Sync for P2pNetworkKadRoutingTable<K>
impl<const K: usize> Unpin for P2pNetworkKadRoutingTable<K>
impl<const K: usize> UnwindSafe for P2pNetworkKadRoutingTable<K>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.