pub struct KademliaDiscovery {
table: Arc<RoutingTable>,
lookup_service: Arc<LookupService>,
refresh_service: Arc<RefreshService>,
peer_queue: Arc<AsyncQueue<DiscoveredPeer>>,
task_group: TaskGroup,
config: Arc<Config>,
bloom: BloomRef,
}Fields§
§table: Arc<RoutingTable>Routing table
lookup_service: Arc<LookupService>Lookup Service
refresh_service: Arc<RefreshService>Refresh Service
peer_queue: Arc<AsyncQueue<DiscoveredPeer>>Discovered peers queued for the Node to dial. Producers
(connect_loop, manual peer_endpoints) push; the Node’s
connect_discovered_peers task drains via recv().
task_group: TaskGroupManaging spawned tasks.
config: Arc<Config>Holds the configuration for the P2P network.
bloom: BloomRefShared local bloom. Snapshotted on every connect-loop iteration to filter routing-table entries (and stamped on outgoing PeerMsgs via the lookup service).
Implementations§
Source§impl KademliaDiscovery
impl KademliaDiscovery
Sourcepub fn new(
key_pair: &KeyPair,
peer_id: &PeerID,
config: Arc<Config>,
monitor: Arc<Monitor>,
bloom: BloomRef,
ex: Executor,
) -> Arc<Self>
pub fn new( key_pair: &KeyPair, peer_id: &PeerID, config: Arc<Config>, monitor: Arc<Monitor>, bloom: BloomRef, ex: Executor, ) -> Arc<Self>
Creates a new KademliaDiscovery
Sourceasync fn connect_loop(self: Arc<Self>) -> Result<()>
async fn connect_loop(self: Arc<Self>) -> Result<()>
This method will attempt to find a peer in the routing table and send it as a DiscoveredPeer for the Node to connect to. If the routing table is empty, it will start the seeding process.
Sourceasync fn start_seeding(&self)
async fn start_seeding(&self)
Starts seeding process.
This method randomly selects a peer from the routing table and
attempts to connect to that peer for the initial lookup. If the routing
table doesn’t have an available entry, it will connect to one of the
provided bootstrap endpoints in the Config and initiate the lookup.
Trait Implementations§
Source§impl Discovery for KademliaDiscovery
impl Discovery for KademliaDiscovery
Source§fn start<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
fn start<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
Source§fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DiscoveredPeer> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn recv<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = DiscoveredPeer> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn on_event(&self, event: PeerConnectionEvent)
fn on_event(&self, event: PeerConnectionEvent)
Source§fn find_peers_with(&self, item: &[u8]) -> Vec<DiscoveredPeer>
fn find_peers_with(&self, item: &[u8]) -> Vec<DiscoveredPeer>
item. Used by application layers (e.g. Swarm) to find
candidates for protocol- or swarm-targeted dials. Implementations
without a routing table may return an empty vector.