karyon_p2p::routing_table

Struct RoutingTable

Source
pub struct RoutingTable {
    key: [u8; 32],
    buckets: RwLock<Vec<Bucket>>,
}
Expand description

This is a modified version of the Kademlia Distributed Hash Table (DHT). https://en.wikipedia.org/wiki/Kademlia

Fields§

§key: [u8; 32]§buckets: RwLock<Vec<Bucket>>

Implementations§

Source§

impl RoutingTable

Source

pub fn new(key: [u8; 32]) -> Self

Creates a new RoutingTable

Source

pub fn add_entry(&self, entry: Entry) -> AddEntryResult

Adds a new entry to the table and returns a result indicating success, failure, or restrictions.

Source

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

Check if the table contains the given key.

Source

pub fn update_entry(&self, key: &[u8; 32], entry_flag: u16)

Updates the status of an entry in the routing table identified by the given key.

If the key is not found, no action is taken.

Source

pub fn bucket_indexes(&self, target_key: &[u8; 32]) -> Vec<usize>

Returns a list of bucket indexes that are closest to the given target key.

Source

pub fn closest_entries( &self, target_key: &[u8; 32], max_entries: usize, ) -> Vec<Entry>

Returns a list of the closest entries to the given target key, limited by max_entries.

Source

pub fn remove_entry(&self, key: &[u8; 32])

Removes an entry with the given key from the routing table, if it exists.

Source

pub fn buckets(&self) -> Vec<Bucket>

Returns an iterator of entries. FIXME: TODO: avoid cloning the data

Source

pub fn random_entry(&self, entry_flag: u16) -> Option<Entry>

Returns a random entry from the routing table.

Source

fn bucket_index(&self, key: &[u8; 32]) -> Option<usize>

Source

fn subnet_restricted(&self, idx: usize, entry: &Entry) -> bool

This function iterate through the routing table and counts how many entries in the same subnet as the given Entry are already present.

If the number of matching entries in the same bucket exceeds a threshold (MAX_MATCHED_SUBNET_IN_BUCKET), or if the total count of matching entries in the entire table exceeds a threshold (MAX_MATCHED_SUBNET_IN_TABLE), the addition of the Entry is considered restricted and returns true.

Trait Implementations§

Source§

impl Debug for RoutingTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> EventValueAny for T
where T: Send + Sync + Debug + Any,

Source§

fn value_as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more