Split Peerset into PeerStore & ProtocolControllers (#13611)

This commit is contained in:
Dmitry Markin
2023-05-23 14:49:02 +03:00
committed by GitHub
parent 194c9edd4a
commit 01107e9ca5
19 changed files with 2915 additions and 1729 deletions
+4 -36
View File
@@ -156,10 +156,6 @@ pub trait NetworkPeers {
/// Disconnect from a node as soon as possible.
///
/// This triggers the same effects as if the connection had closed itself spontaneously.
///
/// See also [`NetworkPeers::remove_from_peers_set`], which has the same effect but also
/// prevents the local node from re-establishing an outgoing substream to this peer until it
/// is added again.
fn disconnect_peer(&self, who: PeerId, protocol: ProtocolName);
/// Connect to unreserved peers and allow unreserved peers to connect for syncing purposes.
@@ -216,26 +212,6 @@ pub trait NetworkPeers {
/// Remove peers from a peer set.
fn remove_peers_from_reserved_set(&self, protocol: ProtocolName, peers: Vec<PeerId>);
/// Add a peer to a set of peers.
///
/// If the set has slots available, it will try to open a substream with this peer.
///
/// Each `Multiaddr` must end with a `/p2p/` component containing the `PeerId`. It can also
/// consist of only `/p2p/<peerid>`.
///
/// Returns an `Err` if one of the given addresses is invalid or contains an
/// invalid peer ID (which includes the local peer ID).
fn add_to_peers_set(
&self,
protocol: ProtocolName,
peers: HashSet<Multiaddr>,
) -> Result<(), String>;
/// Remove peers from a peer set.
///
/// If we currently have an open substream with this peer, it will soon be closed.
fn remove_from_peers_set(&self, protocol: ProtocolName, peers: Vec<PeerId>);
/// Returns the number of peers in the sync peer set we're connected to.
fn sync_num_connected(&self) -> usize;
}
@@ -259,6 +235,10 @@ where
}
fn report_peer(&self, who: PeerId, cost_benefit: ReputationChange) {
// TODO: when we get rid of `Peerset`, we'll likely need to add some kind of async
// interface to `PeerStore`, otherwise we'll have trouble calling functions accepting
// `&mut self` via `Arc`.
// See https://github.com/paritytech/substrate/issues/14170.
T::report_peer(self, who, cost_benefit)
}
@@ -302,18 +282,6 @@ where
T::remove_peers_from_reserved_set(self, protocol, peers)
}
fn add_to_peers_set(
&self,
protocol: ProtocolName,
peers: HashSet<Multiaddr>,
) -> Result<(), String> {
T::add_to_peers_set(self, protocol, peers)
}
fn remove_from_peers_set(&self, protocol: ProtocolName, peers: Vec<PeerId>) {
T::remove_from_peers_set(self, protocol, peers)
}
fn sync_num_connected(&self) -> usize {
T::sync_num_connected(self)
}