mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
NetworkService: change remove_from_peers_set to accept PeerIds (#9964)
* NetworkService: expose split_multiaddr_and_peer_id * Revert "NetworkService: expose split_multiaddr_and_peer_id" This reverts commit 47b9a0d57c3617e64d01c449afca8896bd4bb6b6. * change remove_from_peer_set to accets PeerIds * fixes * try fixing it * try fixing it again * FMT * revert me * Revert "revert me" This reverts commit 1ea34f473f1aedc8b3e6e888d1ad2e1b45eaa1e0.
This commit is contained in:
@@ -1164,25 +1164,12 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
|
||||
}
|
||||
|
||||
/// Remove peers from a peer set.
|
||||
///
|
||||
/// Each `Multiaddr` must end with a `/p2p/` component containing the `PeerId`.
|
||||
///
|
||||
/// Returns an `Err` if one of the given addresses is invalid or contains an
|
||||
/// invalid peer ID (which includes the local peer ID).
|
||||
// NOTE: technically, this function only needs `Vec<PeerId>`, but we use `Multiaddr` here for
|
||||
// convenience.
|
||||
pub fn remove_peers_from_reserved_set(
|
||||
&self,
|
||||
protocol: Cow<'static, str>,
|
||||
peers: HashSet<Multiaddr>,
|
||||
) -> Result<(), String> {
|
||||
let peers = self.split_multiaddr_and_peer_id(peers)?;
|
||||
for (peer_id, _) in peers.into_iter() {
|
||||
pub fn remove_peers_from_reserved_set(&self, protocol: Cow<'static, str>, peers: Vec<PeerId>) {
|
||||
for peer_id in peers.into_iter() {
|
||||
let _ = self
|
||||
.to_worker
|
||||
.unbounded_send(ServiceToWorkerMsg::RemoveSetReserved(protocol.clone(), peer_id));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Configure an explicit fork sync request.
|
||||
@@ -1233,25 +1220,12 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
|
||||
/// Remove peers from a peer set.
|
||||
///
|
||||
/// If we currently have an open substream with this peer, it will soon be closed.
|
||||
///
|
||||
/// Each `Multiaddr` must end with a `/p2p/` component containing the `PeerId`.
|
||||
///
|
||||
/// Returns an `Err` if one of the given addresses is invalid or contains an
|
||||
/// invalid peer ID (which includes the local peer ID).
|
||||
// NOTE: technically, this function only needs `Vec<PeerId>`, but we use `Multiaddr` here for
|
||||
// convenience.
|
||||
pub fn remove_from_peers_set(
|
||||
&self,
|
||||
protocol: Cow<'static, str>,
|
||||
peers: HashSet<Multiaddr>,
|
||||
) -> Result<(), String> {
|
||||
let peers = self.split_multiaddr_and_peer_id(peers)?;
|
||||
for (peer_id, _) in peers.into_iter() {
|
||||
pub fn remove_from_peers_set(&self, protocol: Cow<'static, str>, peers: Vec<PeerId>) {
|
||||
for peer_id in peers.into_iter() {
|
||||
let _ = self
|
||||
.to_worker
|
||||
.unbounded_send(ServiceToWorkerMsg::RemoveFromPeersSet(protocol.clone(), peer_id));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns the number of peers we're connected to.
|
||||
|
||||
@@ -317,15 +317,10 @@ impl<B: BlockT + 'static, H: ExHashT> TransactionsHandler<B, H> {
|
||||
}
|
||||
},
|
||||
Event::SyncDisconnected { remote } => {
|
||||
let addr = iter::once(multiaddr::Protocol::P2p(remote.into()))
|
||||
.collect::<multiaddr::Multiaddr>();
|
||||
let result = self.service.remove_peers_from_reserved_set(
|
||||
self.service.remove_peers_from_reserved_set(
|
||||
self.protocol_name.clone(),
|
||||
iter::once(addr).collect(),
|
||||
iter::once(remote).collect(),
|
||||
);
|
||||
if let Err(err) = result {
|
||||
log::error!(target: "sync", "Removing reserved peer failed: {}", err);
|
||||
}
|
||||
},
|
||||
|
||||
Event::NotificationStreamOpened { remote, protocol, role, .. }
|
||||
|
||||
Reference in New Issue
Block a user