Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Split Peerset into PeerStore & ProtocolControllers (#13611)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-markin authored and Ank4n committed Jul 8, 2023
1 parent 3233c9f commit b2eea2b
Show file tree
Hide file tree
Showing 19 changed files with 2,914 additions and 1,728 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions client/consensus/grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,6 @@ impl NetworkPeers for TestNetwork {

fn remove_peers_from_reserved_set(&self, _protocol: ProtocolName, _peers: Vec<PeerId>) {}

fn add_to_peers_set(
&self,
_protocol: ProtocolName,
_peers: HashSet<Multiaddr>,
) -> Result<(), String> {
unimplemented!();
}

fn remove_from_peers_set(&self, _protocol: ProtocolName, _peers: Vec<PeerId>) {
unimplemented!();
}

fn sync_num_connected(&self) -> usize {
unimplemented!();
}
Expand Down
12 changes: 0 additions & 12 deletions client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,6 @@ mod tests {

fn remove_peers_from_reserved_set(&self, _protocol: ProtocolName, _peers: Vec<PeerId>) {}

fn add_to_peers_set(
&self,
_protocol: ProtocolName,
_peers: HashSet<Multiaddr>,
) -> Result<(), String> {
unimplemented!();
}

fn remove_from_peers_set(&self, _protocol: ProtocolName, _peers: Vec<PeerId>) {
unimplemented!();
}

fn sync_num_connected(&self) -> usize {
unimplemented!();
}
Expand Down
12 changes: 0 additions & 12 deletions client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,18 +646,6 @@ mod tests {

fn remove_peers_from_reserved_set(&self, _protocol: ProtocolName, _peers: Vec<PeerId>) {}

fn add_to_peers_set(
&self,
_protocol: ProtocolName,
_peers: HashSet<Multiaddr>,
) -> Result<(), String> {
unimplemented!();
}

fn remove_from_peers_set(&self, _protocol: ProtocolName, _peers: Vec<PeerId>) {
unimplemented!();
}

fn sync_num_connected(&self) -> usize {
unimplemented!();
}
Expand Down
42 changes: 8 additions & 34 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading

0 comments on commit b2eea2b

Please sign in to comment.