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_versions: RwLock<HashMap<ProtocolID, Version>>,
task_group: TaskGroup,
executor: Executor,
config: Arc<Config>,
monitor: Arc<Monitor>,
}
Fields§
§id: PeerID
Peer’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_versions: RwLock<HashMap<ProtocolID, Version>>
Hashmap contains protocols with their versions
task_group: TaskGroup
Managing spawned tasks.
executor: Executor
A 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 async fn attach_protocol<P: Protocol>(
&self,
c: Box<ProtocolConstructor>,
) -> Result<()>
pub async fn attach_protocol<P: Protocol>( &self, c: Box<ProtocolConstructor>, ) -> Result<()>
Attach a custom protocol to the network
Sourcepub async fn broadcast<T: Encode>(&self, proto_id: &ProtocolID, msg: &T)
pub async fn broadcast<T: Encode>(&self, proto_id: &ProtocolID, msg: &T)
Broadcast a message to all connected peers using the specified protocol.
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>, conn: Arc<Connection>) -> Result<()>
async fn new_peer(self: &Arc<Self>, conn: Arc<Connection>) -> Result<()>
Add a new peer to the peer list.
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.
Sourceasync fn setup_core_protocols(&self) -> Result<()>
async fn setup_core_protocols(&self) -> Result<()>
Attach the core protocols.
Auto Trait Implementations§
impl !Freeze for PeerPool
impl !RefUnwindSafe for PeerPool
impl Send for PeerPool
impl Sync for PeerPool
impl Unpin for PeerPool
impl !UnwindSafe for PeerPool
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more