pub struct LookupService {
id: PeerID,
table: Arc<RoutingTable>,
listener: Arc<Listener<KadNetMsgCodec>>,
connector: Arc<Connector<KadNetMsgCodec>>,
outbound_slots: Arc<ConnectionSlots>,
endpoints: LookupEndpoints,
config: Arc<Config>,
monitor: Arc<Monitor>,
bloom: BloomRef,
}Fields§
§id: PeerIDPeer’s ID
table: Arc<RoutingTable>Routing Table
listener: Arc<Listener<KadNetMsgCodec>>Listener
connector: Arc<Connector<KadNetMsgCodec>>Connector
outbound_slots: Arc<ConnectionSlots>Outbound slots.
endpoints: LookupEndpointsEndpoints this service advertises and binds to.
config: Arc<Config>Holds the configuration for the P2P network.
monitor: Arc<Monitor>Responsible for network and system monitoring.
bloom: BloomRefShared local bloom. Snapshotted on every outgoing PeerMsg.
Implementations§
Source§impl LookupService
impl LookupService
Sourcepub fn new(
key_pair: &KeyPair,
table: Arc<RoutingTable>,
config: Arc<Config>,
monitor: Arc<Monitor>,
bloom: BloomRef,
endpoints: LookupEndpoints,
ex: Executor,
) -> Self
pub fn new( key_pair: &KeyPair, table: Arc<RoutingTable>, config: Arc<Config>, monitor: Arc<Monitor>, bloom: BloomRef, endpoints: LookupEndpoints, ex: Executor, ) -> Self
Creates a new lookup service.
pub fn lookup_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: FramedConn<KadNetMsgCodec>,
target_peer_id: &PeerID,
) -> Result<Vec<PeerMsg>>
async fn handle_outbound( &self, conn: FramedConn<KadNetMsgCodec>, 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: FramedConn<KadNetMsgCodec>,
) -> Result<()>
async fn handle_inbound( self: &Arc<Self>, conn: FramedConn<KadNetMsgCodec>, ) -> Result<()>
Handles inbound connection
Sourceasync fn send_ping_msg(
&self,
conn: &mut FramedConn<KadNetMsgCodec>,
) -> Result<PingMsg>
async fn send_ping_msg( &self, conn: &mut FramedConn<KadNetMsgCodec>, ) -> Result<PingMsg>
Sends a Ping msg.
Sourceasync fn send_pong_msg(
&self,
nonce: [u8; 32],
conn: &mut FramedConn<KadNetMsgCodec>,
) -> Result<()>
async fn send_pong_msg( &self, nonce: [u8; 32], conn: &mut FramedConn<KadNetMsgCodec>, ) -> Result<()>
Sends a Pong msg
Sourceasync fn send_findpeer_msg(
&self,
conn: &mut FramedConn<KadNetMsgCodec>,
peer_id: &PeerID,
) -> Result<()>
async fn send_findpeer_msg( &self, conn: &mut FramedConn<KadNetMsgCodec>, peer_id: &PeerID, ) -> Result<()>
Sends a FindPeer msg
Sourceasync fn send_peers_msg(
&self,
peer_id: &PeerID,
conn: &mut FramedConn<KadNetMsgCodec>,
) -> Result<()>
async fn send_peers_msg( &self, peer_id: &PeerID, conn: &mut FramedConn<KadNetMsgCodec>, ) -> Result<()>
Sends a Peers msg.
Sourceasync fn send_peer_msg(
&self,
conn: &mut FramedConn<KadNetMsgCodec>,
) -> Result<()>
async fn send_peer_msg( &self, conn: &mut FramedConn<KadNetMsgCodec>, ) -> Result<()>
Sends a Peer msg advertising our listen and discovery addresses.
addrs carries every data-plane listen endpoint; discovery_addrs
carries the lookup endpoint and (when set) the udp refresh endpoint.
Sourceasync fn send_shutdown_msg(
&self,
conn: &mut FramedConn<KadNetMsgCodec>,
) -> Result<()>
async fn send_shutdown_msg( &self, conn: &mut FramedConn<KadNetMsgCodec>, ) -> Result<()>
Sends a Shutdown msg.