pub struct LookupService {
id: PeerID,
table: Arc<RoutingTable>,
listener: Arc<Listener>,
connector: Arc<Connector>,
outbound_slots: Arc<ConnectionSlots>,
listen_endpoint: RwLock<Option<Endpoint>>,
discovery_endpoint: RwLock<Option<Endpoint>>,
config: Arc<Config>,
monitor: Arc<Monitor>,
}
Fields§
§id: PeerID
Peer’s ID
table: Arc<RoutingTable>
Routing Table
listener: Arc<Listener>
Listener
connector: Arc<Connector>
Connector
outbound_slots: Arc<ConnectionSlots>
Outbound slots.
listen_endpoint: RwLock<Option<Endpoint>>
Resolved listen endpoint
discovery_endpoint: RwLock<Option<Endpoint>>
Resolved discovery endpoint
config: Arc<Config>
Holds the configuration for the P2P network.
monitor: Arc<Monitor>
Responsible for network and system monitoring.
Implementations§
Source§impl LookupService
impl LookupService
Sourcepub fn new(
key_pair: &KeyPair,
table: Arc<RoutingTable>,
config: Arc<Config>,
monitor: Arc<Monitor>,
ex: Executor,
) -> Self
pub fn new( key_pair: &KeyPair, table: Arc<RoutingTable>, config: Arc<Config>, monitor: Arc<Monitor>, ex: Executor, ) -> Self
Creates a new lookup service
Sourcepub fn set_listen_endpoint(&self, resolved_endpoint: &Endpoint) -> Result<()>
pub fn set_listen_endpoint(&self, resolved_endpoint: &Endpoint) -> Result<()>
Set the resolved listen endpoint.
pub fn listen_endpoint(&self) -> Option<Endpoint>
pub fn discovery_endpoint(&self) -> Option<Endpoint>
Sourcepub async fn start_lookup(
&self,
endpoint: &Endpoint,
peer_id: Option<PeerID>,
) -> Result<()>
pub async fn start_lookup( &self, endpoint: &Endpoint, peer_id: Option<PeerID>, ) -> Result<()>
Starts iterative lookup and populate the routing table.
This method begins by generating a random peer ID and connecting to the provided endpoint. It then sends a FindPeer message containing the randomly generated peer ID. Upon receiving peers from the initial lookup, it starts connecting to these received peers and sends them a FindPeer message that contains our own peer ID.
Sourceasync fn random_lookup(
&self,
endpoint: &Endpoint,
peer_id: Option<PeerID>,
random_peers: &mut Vec<PeerMsg>,
) -> Result<()>
async fn random_lookup( &self, endpoint: &Endpoint, peer_id: Option<PeerID>, random_peers: &mut Vec<PeerMsg>, ) -> Result<()>
Starts a random lookup
This will perfom lookup on a random generated PeerID
Sourceasync fn self_lookup(
&self,
random_peers: &[PeerMsg],
peer_buffer: &mut Vec<PeerMsg>,
) -> Result<()>
async fn self_lookup( &self, random_peers: &[PeerMsg], peer_buffer: &mut Vec<PeerMsg>, ) -> Result<()>
Starts a self lookup
Sourceasync fn connect(
&self,
endpoint: Endpoint,
peer_id: Option<PeerID>,
target_peer_id: &PeerID,
) -> Result<Vec<PeerMsg>>
async fn connect( &self, endpoint: Endpoint, peer_id: Option<PeerID>, target_peer_id: &PeerID, ) -> Result<Vec<PeerMsg>>
Connects to the given endpoint and initiates a lookup process for the provided peer ID.
Sourceasync fn handle_outbound(
&self,
conn: Conn<NetMsg, Error>,
target_peer_id: &PeerID,
) -> Result<Vec<PeerMsg>>
async fn handle_outbound( &self, conn: Conn<NetMsg, Error>, target_peer_id: &PeerID, ) -> Result<Vec<PeerMsg>>
Handles outbound connection
Sourceasync fn start_listener(self: &Arc<Self>) -> Result<()>
async fn start_listener(self: &Arc<Self>) -> Result<()>
Start a listener.
Sourceasync fn handle_inbound(
self: &Arc<Self>,
conn: Conn<NetMsg, Error>,
) -> Result<()>
async fn handle_inbound( self: &Arc<Self>, conn: Conn<NetMsg, Error>, ) -> Result<()>
Handles inbound connection
Sourceasync fn send_pong_msg(
&self,
nonce: [u8; 32],
conn: &Conn<NetMsg, Error>,
) -> Result<()>
async fn send_pong_msg( &self, nonce: [u8; 32], conn: &Conn<NetMsg, Error>, ) -> Result<()>
Sends a Pong msg
Sourceasync fn send_findpeer_msg(
&self,
conn: &Conn<NetMsg, Error>,
peer_id: &PeerID,
) -> Result<()>
async fn send_findpeer_msg( &self, conn: &Conn<NetMsg, Error>, peer_id: &PeerID, ) -> Result<()>
Sends a FindPeer msg
Sourceasync fn send_peers_msg(
&self,
peer_id: &PeerID,
conn: &Conn<NetMsg, Error>,
) -> Result<()>
async fn send_peers_msg( &self, peer_id: &PeerID, conn: &Conn<NetMsg, Error>, ) -> Result<()>
Sends a Peers msg.