Struct network_clique::manager::Manager
source · pub struct Manager<PK: PublicKey + PeerId, A: Data, D: Data> {
wanted: DirectedPeers<PK, A>,
have: HashMap<PK, UnboundedSender<D>>,
}
Expand description
Network component responsible for holding the list of peers that we want to connect to or let them connect to us, and managing the established connections.
Fields§
§wanted: DirectedPeers<PK, A>
§have: HashMap<PK, UnboundedSender<D>>
Implementations§
source§impl<PK: PublicKey + PeerId, A: Data, D: Data> Manager<PK, A, D>
impl<PK: PublicKey + PeerId, A: Data, D: Data> Manager<PK, A, D>
sourcepub fn new(own_id: PK, metrics: Metrics) -> Self
pub fn new(own_id: PK, metrics: Metrics) -> Self
Create a new Manager with empty list of peers.
fn active_connection(&self, peer_id: &PK) -> bool
sourcepub fn add_peer(&mut self, peer_id: PK, address: A) -> bool
pub fn add_peer(&mut self, peer_id: PK, address: A) -> bool
Add a peer to the list of peers we want to stay connected to, or update the address if the peer was already added. Returns whether we should start attempts at connecting with the peer, which depends on the coorddinated pseudorandom decision on the direction of the connection and whether this was added for the first time.
sourcepub fn peer_address(&self, peer_id: &PK) -> Option<A>
pub fn peer_address(&self, peer_id: &PK) -> Option<A>
Return the address of the given peer, or None if we shouldn’t attempt connecting with the peer.
sourcepub fn add_connection(
&mut self,
peer_id: PK,
data_for_network: UnboundedSender<D>
) -> AddResult
pub fn add_connection( &mut self, peer_id: PK, data_for_network: UnboundedSender<D> ) -> AddResult
Add an established connection with a known peer, but only if the peer is among the peers we want to be connected to.
sourcepub fn remove_peer(&mut self, peer_id: &PK)
pub fn remove_peer(&mut self, peer_id: &PK)
Remove a peer from the list of peers that we want to stay connected with. Close any incoming and outgoing connections that were established.
sourcepub fn send_to(&mut self, peer_id: &PK, data: D) -> Result<(), SendError>
pub fn send_to(&mut self, peer_id: &PK, data: D) -> Result<(), SendError>
Send data to a peer. Returns error if there is no outgoing connection to the peer, or if the connection is dead.
sourcepub fn status_report(&self) -> ManagerStatus<PK>
pub fn status_report(&self) -> ManagerStatus<PK>
A status of the manager, to be displayed somewhere.