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,
impl<N> IterativeLookup<N>where
N: LookupNode,
Sourcepub fn new(
target: [u8; 32],
config: LookupConfig,
) -> Result<IterativeLookup<N>, LookupError>
pub fn new( target: [u8; 32], config: LookupConfig, ) -> Result<IterativeLookup<N>, LookupError>
Construct an empty lookup for target.
Sourcepub const fn config(&self) -> LookupConfig
pub const fn config(&self) -> LookupConfig
Active lookup configuration.
Sourcepub const fn iterations(&self) -> usize
pub const fn iterations(&self) -> usize
Number of rounds begun so far.
Sourcepub const fn termination(&self) -> Option<LookupTermination>
pub const fn termination(&self) -> Option<LookupTermination>
Current terminal state, if the lookup has stopped.
Sourcepub const fn round_active(&self) -> bool
pub const fn round_active(&self) -> bool
Whether a transport round is currently active.
Sourcepub fn peer_state(&self, peer: &[u8; 32]) -> Option<LookupPeerState>
pub fn peer_state(&self, peer: &[u8; 32]) -> Option<LookupPeerState>
State currently assigned to a peer.
Sourcepub fn is_contactable(&self, peer: &[u8; 32]) -> bool
pub fn is_contactable(&self, peer: &[u8; 32]) -> bool
Whether the peer has never been contacted by this lookup.
Sourcepub fn queried_peers(&self) -> &[[u8; 32]]
pub fn queried_peers(&self) -> &[[u8; 32]]
Peers selected for a transport query, in query order.
Sourcepub fn add_known_result(&mut self, node: N)
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.
Sourcepub fn add_candidate(&mut self, node: N) -> CandidateInsertion
pub fn add_candidate(&mut self, node: N) -> CandidateInsertion
Add or update an unqueried candidate.
Sourcepub fn begin_round(&mut self) -> Result<LookupProgress, LookupError>
pub fn begin_round(&mut self) -> Result<LookupProgress, LookupError>
Begin the next α-query round.
Sourcepub fn take_next_candidate(&mut self) -> Result<Option<N>, LookupError>
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.
Sourcepub fn mark_waiting(&mut self, node: N) -> Result<(), LookupError>
pub fn mark_waiting(&mut self, node: N) -> Result<(), LookupError>
Mark a selected node as an in-flight query in the active round.
Sourcepub fn record_success(&mut self, peer: &[u8; 32]) -> Result<(), LookupError>
pub fn record_success(&mut self, peer: &[u8; 32]) -> Result<(), LookupError>
Record a successful response and retain the queried peer as a result.
Sourcepub fn record_failure(&mut self, peer: &[u8; 32]) -> Result<(), LookupError>
pub fn record_failure(&mut self, peer: &[u8; 32]) -> Result<(), LookupError>
Record an explicit query or transport failure.
Sourcepub fn record_unresponsive(
&mut self,
peer: &[u8; 32],
) -> Result<(), LookupError>
pub fn record_unresponsive( &mut self, peer: &[u8; 32], ) -> Result<(), LookupError>
Record a query abandoned after the transport’s round grace period.
Sourcepub fn waiting_peers(&self) -> Vec<[u8; 32]>
pub fn waiting_peers(&self) -> Vec<[u8; 32]>
Peers still waiting in the active round, in XOR order.
Sourcepub fn complete_round(&mut self) -> Result<LookupProgress, LookupError>
pub fn complete_round(&mut self) -> Result<LookupProgress, LookupError>
Complete the current round and evaluate native Saorsa convergence.
Trait Implementations§
Auto Trait Implementations§
impl<N> Freeze for IterativeLookup<N>
impl<N> RefUnwindSafe for IterativeLookup<N>
impl<N> Send for IterativeLookup<N>
impl<N> Sync for IterativeLookup<N>
impl<N> Unpin for IterativeLookup<N>
impl<N> UnsafeUnpin for IterativeLookup<N>
impl<N> UnwindSafe for IterativeLookup<N>
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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