Struct network_clique::manager::direction::DirectedPeers
source · pub struct DirectedPeers<PK: PublicKey, A: Data> {
own_id: PK,
outgoing: HashMap<PK, A>,
incoming: HashSet<PK>,
metrics: Metrics,
}
Expand description
Data about peers we know and whether we should connect to them or they to us. For the former case also keeps the peers’ addresses.
Fields§
§own_id: PK
§outgoing: HashMap<PK, A>
§incoming: HashSet<PK>
§metrics: Metrics
Implementations§
source§impl<PK: PublicKey, A: Data> DirectedPeers<PK, A>
impl<PK: PublicKey, A: Data> DirectedPeers<PK, A>
sourcepub fn new(own_id: PK, metrics: Metrics) -> Self
pub fn new(own_id: PK, metrics: Metrics) -> Self
Create a new set of peers directed using our own peer id.
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 is the case exactly when the peer is one with which we should attempt connections AND it 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 interested(&self, peer_id: &PK) -> bool
pub fn interested(&self, peer_id: &PK) -> bool
Whether we should be maintaining a connection with this peer.
sourcepub fn incoming_peers(&self) -> impl Iterator<Item = &PK>
pub fn incoming_peers(&self) -> impl Iterator<Item = &PK>
Iterator over the peers we want connections from.
sourcepub fn outgoing_peers(&self) -> impl Iterator<Item = &PK>
pub fn outgoing_peers(&self) -> impl Iterator<Item = &PK>
Iterator over the peers we want to connect 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, whether the connection was supposed to be incoming or outgoing.