mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Split Peerset into PeerStore & ProtocolControllers (#13611)
This commit is contained in:
@@ -257,8 +257,8 @@ impl<B: BlockT> Protocol<B> {
|
||||
}
|
||||
|
||||
/// Returns the list of reserved peers.
|
||||
pub fn reserved_peers(&self) -> impl Iterator<Item = &PeerId> {
|
||||
self.behaviour.reserved_peers(HARDCODED_PEERSETS_SYNC)
|
||||
pub fn reserved_peers(&self, pending_response: oneshot::Sender<Vec<PeerId>>) {
|
||||
self.behaviour.reserved_peers(HARDCODED_PEERSETS_SYNC, pending_response);
|
||||
}
|
||||
|
||||
/// Adds a `PeerId` to the list of reserved peers for syncing purposes.
|
||||
@@ -310,39 +310,13 @@ impl<B: BlockT> Protocol<B> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Notify the protocol that we have learned about the existence of nodes on the default set.
|
||||
/// Notify the protocol that we have learned about the existence of some peer.
|
||||
///
|
||||
/// Can be called multiple times with the same `PeerId`s.
|
||||
pub fn add_default_set_discovered_nodes(&mut self, peer_ids: impl Iterator<Item = PeerId>) {
|
||||
for peer_id in peer_ids {
|
||||
self.peerset_handle.add_to_peers_set(HARDCODED_PEERSETS_SYNC, peer_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a peer to a peers set.
|
||||
pub fn add_to_peers_set(&self, protocol: ProtocolName, peer: PeerId) {
|
||||
if let Some(index) = self.notification_protocols.iter().position(|p| *p == protocol) {
|
||||
self.peerset_handle.add_to_peers_set(sc_peerset::SetId::from(index), peer);
|
||||
} else {
|
||||
error!(
|
||||
target: "sub-libp2p",
|
||||
"add_to_peers_set with unknown protocol: {}",
|
||||
protocol
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a peer from a peers set.
|
||||
pub fn remove_from_peers_set(&self, protocol: ProtocolName, peer: PeerId) {
|
||||
if let Some(index) = self.notification_protocols.iter().position(|p| *p == protocol) {
|
||||
self.peerset_handle.remove_from_peers_set(sc_peerset::SetId::from(index), peer);
|
||||
} else {
|
||||
error!(
|
||||
target: "sub-libp2p",
|
||||
"remove_from_peers_set with unknown protocol: {}",
|
||||
protocol
|
||||
);
|
||||
}
|
||||
/// Can be called multiple times with the same `PeerId`.
|
||||
pub fn add_known_peer(&mut self, peer_id: PeerId) {
|
||||
// TODO: get rid of this function and call `Peerset`/`PeerStore` directly
|
||||
// from `NetworkWorker`.
|
||||
self.peerset_handle.add_known_peer(peer_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user