Skip to main content

IterativeLookup

Struct IterativeLookup 

Source
pub struct IterativeLookup<N>
where N: LookupNode,
{ /* private fields */ }
Expand description

Pull-based, transport-independent Kademlia lookup state machine.

Implementations§

Source§

impl<N> IterativeLookup<N>
where N: LookupNode,

Source

pub fn new( target: [u8; 32], config: LookupConfig, ) -> Result<IterativeLookup<N>, LookupError>

Construct an empty lookup for target.

Source

pub const fn target(&self) -> [u8; 32]

Target key for this lookup.

Source

pub const fn config(&self) -> LookupConfig

Active lookup configuration.

Source

pub const fn iterations(&self) -> usize

Number of rounds begun so far.

Source

pub const fn termination(&self) -> Option<LookupTermination>

Current terminal state, if the lookup has stopped.

Source

pub const fn round_active(&self) -> bool

Whether a transport round is currently active.

Source

pub fn peer_state(&self, peer: &[u8; 32]) -> Option<LookupPeerState>

State currently assigned to a peer.

Source

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

Whether the peer has never been contacted by this lookup.

Source

pub fn queried_peers(&self) -> &[[u8; 32]]

Peers selected for a transport query, in query order.

Source

pub fn add_known_result(&mut self, node: N)

Add a successful result that must never be queried, such as the local node competing in a native lookup’s final XOR ordering.

Source

pub fn add_candidate(&mut self, node: N) -> CandidateInsertion

Add or update an unqueried candidate.

Source

pub fn begin_round(&mut self) -> Result<LookupProgress, LookupError>

Begin the next α-query round.

Source

pub fn take_next_candidate(&mut self) -> Result<Option<N>, LookupError>

Remove and return the closest candidate for the active round.

The driver must either call Self::mark_waiting for the returned node or discard it as temporarily ineligible before asking for another.

Source

pub fn mark_waiting(&mut self, node: N) -> Result<(), LookupError>

Mark a selected node as an in-flight query in the active round.

Source

pub fn record_success(&mut self, peer: &[u8; 32]) -> Result<(), LookupError>

Record a successful response and retain the queried peer as a result.

Source

pub fn record_failure(&mut self, peer: &[u8; 32]) -> Result<(), LookupError>

Record an explicit query or transport failure.

Source

pub fn record_unresponsive( &mut self, peer: &[u8; 32], ) -> Result<(), LookupError>

Record a query abandoned after the transport’s round grace period.

Source

pub fn waiting_peers(&self) -> Vec<[u8; 32]>

Peers still waiting in the active round, in XOR order.

Source

pub fn complete_round(&mut self) -> Result<LookupProgress, LookupError>

Complete the current round and evaluate native Saorsa convergence.

Source

pub fn results(&self) -> Vec<N>

Successful responders sorted closest-first and truncated to K.

Trait Implementations§

Source§

impl<N> Debug for IterativeLookup<N>
where N: Debug + LookupNode,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<N> Freeze for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: Freeze, HashMap<[u8; 32], N>: Freeze,

§

impl<N> RefUnwindSafe for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: RefUnwindSafe, HashMap<[u8; 32], N>: RefUnwindSafe,

§

impl<N> Send for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: Send, HashMap<[u8; 32], N>: Send,

§

impl<N> Sync for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: Sync, HashMap<[u8; 32], N>: Sync,

§

impl<N> Unpin for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: Unpin, HashMap<[u8; 32], N>: Unpin,

§

impl<N> UnsafeUnpin for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: UnsafeUnpin, HashMap<[u8; 32], N>: UnsafeUnpin,

§

impl<N> UnwindSafe for IterativeLookup<N>
where BTreeMap<([u8; 32], [u8; 32]), N>: UnwindSafe, HashMap<[u8; 32], N>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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