pub struct PeerPool {
pub id: PeerID,
conn_queue: Arc<ConnQueue>,
peers: RwLock<HashMap<PeerID, Arc<Peer>>>,
pub(crate) protocols: RwLock<HashMap<ProtocolID, Box<ProtocolConstructor>>>,
pub(crate) protocol_meta: RwLock<HashMap<ProtocolID, ProtocolMeta>>,
peer_emitter: Arc<EventEmitter<PeerEventTopic>>,
task_group: TaskGroup,
pub(crate) executor: Executor,
pub(crate) config: Arc<Config>,
monitor: Arc<Monitor>,
}Fields§
§id: PeerIDPeer’s ID
conn_queue: Arc<ConnQueue>Connection queue
peers: RwLock<HashMap<PeerID, Arc<Peer>>>Holds the running peers.
protocols: RwLock<HashMap<ProtocolID, Box<ProtocolConstructor>>>Hashmap contains protocol constructors.
protocol_meta: RwLock<HashMap<ProtocolID, ProtocolMeta>>Per-protocol metadata (version + kind, extensible). Keyed by protocol id. Source of truth for the handshake’s mandatory check and version negotiation.
peer_emitter: Arc<EventEmitter<PeerEventTopic>>Peer-lifecycle event emitter. Each registered listener gets its own copy of every event.
task_group: TaskGroupManaging spawned tasks.
executor: ExecutorA global Executor
config: Arc<Config>The Configuration for the P2P network.
monitor: Arc<Monitor>Responsible for network and system monitoring.
Implementations§
Source§impl PeerPool
impl PeerPool
Sourcepub fn new(
id: &PeerID,
conn_queue: Arc<ConnQueue>,
config: Arc<Config>,
monitor: Arc<Monitor>,
executor: Executor,
) -> Arc<Self>
pub fn new( id: &PeerID, conn_queue: Arc<ConnQueue>, config: Arc<Config>, monitor: Arc<Monitor>, executor: Executor, ) -> Arc<Self>
Creates a new PeerPool
Sourcepub fn register_peer_events(&self) -> EventListener<PeerEventTopic, PeerEvent>
pub fn register_peer_events(&self) -> EventListener<PeerEventTopic, PeerEvent>
Register a listener for the peer-lifecycle events.
Sourcepub async fn attach_protocol<P: Protocol>(
&self,
c: Box<ProtocolConstructor>,
) -> Result<()>
pub async fn attach_protocol<P: Protocol>( &self, c: Box<ProtocolConstructor>, ) -> Result<()>
Register a protocol’s user-supplied constructor and metadata.
Bloom advertising is handled by Node::attach_protocol.
Sourcepub async fn broadcast(&self, proto_id: &ProtocolID, msg: Vec<u8>)
pub async fn broadcast(&self, proto_id: &ProtocolID, msg: Vec<u8>)
Broadcast a message to all connected peers.
Sourcepub async fn broadcast_to(
&self,
proto_id: &ProtocolID,
msg: Vec<u8>,
targets: &HashSet<PeerID>,
)
pub async fn broadcast_to( &self, proto_id: &ProtocolID, msg: Vec<u8>, targets: &HashSet<PeerID>, )
Broadcast a message to a specific set of peers.
Sourcepub async fn send_to(
&self,
peer_id: &PeerID,
proto_id: &ProtocolID,
msg: Vec<u8>,
) -> Result<()>
pub async fn send_to( &self, peer_id: &PeerID, proto_id: &ProtocolID, msg: Vec<u8>, ) -> Result<()>
Send a message to a specific peer on the given protocol. Returns
PeerNotFound if the peer is not currently in the pool.
Sourcepub async fn peer_protocol_set(
&self,
pid: &PeerID,
) -> Option<HashSet<ProtocolID>>
pub async fn peer_protocol_set( &self, pid: &PeerID, ) -> Option<HashSet<ProtocolID>>
Returns the negotiated protocol set for a peer.
Sourcepub async fn contains_peer(&self, pid: &PeerID) -> bool
pub async fn contains_peer(&self, pid: &PeerID) -> bool
Checks if the peer list contains a peer with the given peer id
Sourcepub async fn inbound_peers(&self) -> HashMap<PeerID, Endpoint>
pub async fn inbound_peers(&self) -> HashMap<PeerID, Endpoint>
Returns a map of inbound peers with their endpoints.
Sourcepub async fn outbound_peers(&self) -> HashMap<PeerID, Endpoint>
pub async fn outbound_peers(&self) -> HashMap<PeerID, Endpoint>
Returns a map of outbound peers with their endpoints.
async fn run(self: Arc<Self>)
Sourceasync fn new_peer(
self: &Arc<Self>,
queued: QueuedConn,
pid: PeerID,
negotiated: Vec<ProtocolID>,
) -> Result<()>
async fn new_peer( self: &Arc<Self>, queued: QueuedConn, pid: PeerID, negotiated: Vec<ProtocolID>, ) -> Result<()>
Build a Peer from a post-handshake QueuedConn and run it.
Sourceasync fn remove_peer(&self, pid: &PeerID) -> Result<()>
async fn remove_peer(&self, pid: &PeerID) -> Result<()>
Shuts down the peer and remove it from the peer list.