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

Commit

Permalink
Revert "Split Peerset into PeerStore & ProtocolControllers (#13611
Browse files Browse the repository at this point in the history
)"

This reverts commit b9c9522.
  • Loading branch information
dmitry-markin committed Jul 3, 2023
1 parent bbee969 commit 8f8866e
Show file tree
Hide file tree
Showing 19 changed files with 1,728 additions and 2,941 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

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

12 changes: 12 additions & 0 deletions client/consensus/grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ 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: 12 additions & 0 deletions client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ 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: 12 additions & 0 deletions client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,18 @@ 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: 34 additions & 8 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, pending_response: oneshot::Sender<Vec<PeerId>>) {
self.behaviour.reserved_peers(HARDCODED_PEERSETS_SYNC, pending_response);
pub fn reserved_peers(&self) -> impl Iterator<Item = &PeerId> {
self.behaviour.reserved_peers(HARDCODED_PEERSETS_SYNC)
}

/// Adds a `PeerId` to the list of reserved peers for syncing purposes.
Expand Down Expand Up @@ -310,13 +310,39 @@ impl<B: BlockT> Protocol<B> {
}
}

/// Notify the protocol that we have learned about the existence of some peer.
/// Notify the protocol that we have learned about the existence of nodes on the default set.
///
/// 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);
/// 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
);
}
}
}

Expand Down
Loading

0 comments on commit 8f8866e

Please sign in to comment.