pub struct Discovery {
table: Arc<RoutingTable>,
lookup_service: Arc<LookupService>,
refresh_service: Arc<RefreshService>,
connector: Arc<Connector>,
listener: Arc<Listener>,
conn_queue: Arc<ConnQueue>,
task_group: TaskGroup,
config: Arc<Config>,
}
Fields§
§table: Arc<RoutingTable>
Routing table
lookup_service: Arc<LookupService>
Lookup Service
refresh_service: Arc<RefreshService>
Refresh Service
connector: Arc<Connector>
Connector
listener: Arc<Listener>
Listener
conn_queue: Arc<ConnQueue>
Connection queue
task_group: TaskGroup
Managing spawned tasks.
config: Arc<Config>
Holds the configuration for the P2P network.
Implementations§
Source§impl Discovery
impl Discovery
Sourcepub fn new(
key_pair: &KeyPair,
peer_id: &PeerID,
conn_queue: Arc<ConnQueue>,
config: Arc<Config>,
monitor: Arc<Monitor>,
ex: Executor,
) -> Arc<Discovery>
pub fn new( key_pair: &KeyPair, peer_id: &PeerID, conn_queue: Arc<ConnQueue>, config: Arc<Config>, monitor: Arc<Monitor>, ex: Executor, ) -> Arc<Discovery>
Creates a new Discovery
Sourceasync fn start_listener(
self: &Arc<Self>,
endpoint: &Endpoint,
) -> Result<Endpoint>
async fn start_listener( self: &Arc<Self>, endpoint: &Endpoint, ) -> Result<Endpoint>
Start a listener and on success, return the resolved endpoint.
Sourceasync fn connect_loop(self: Arc<Self>) -> Result<()>
async fn connect_loop(self: Arc<Self>) -> Result<()>
This method will attempt to connect to a peer in the routing table. If the routing table is empty, it will start the seeding process for finding new peers.
This will perform a backoff to prevent getting stuck in the loop if the seeding process couldn’t find any peers.
Sourceasync fn connect(self: &Arc<Self>, endpoint: &Endpoint, pid: Option<PeerID>)
async fn connect(self: &Arc<Self>, endpoint: &Endpoint, pid: Option<PeerID>)
Connect to the given endpoint using the connector
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.