mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
Make NetworkService::add_reserved_peer() accept MultiaddrWithPeerId (#12102)
* Make `add_reserved_peer()` accept `MultiaddrWithPeerId` * minor: cargo fmt * minor: error to string conversion Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -62,7 +62,7 @@ use parking_lot::Mutex;
|
||||
use sc_client_api::{BlockBackend, ProofProvider};
|
||||
use sc_consensus::{BlockImportError, BlockImportStatus, ImportQueue, Link};
|
||||
use sc_network_common::{
|
||||
config::parse_str_addr,
|
||||
config::MultiaddrWithPeerId,
|
||||
protocol::event::{DhtEvent, Event},
|
||||
request_responses::{IfDisconnected, RequestFailure},
|
||||
service::{
|
||||
@@ -702,9 +702,8 @@ where
|
||||
self.service.remove_reserved_peer(peer);
|
||||
}
|
||||
|
||||
/// Adds a `PeerId` and its address as reserved. The string should encode the address
|
||||
/// and peer ID of the remote node.
|
||||
pub fn add_reserved_peer(&self, peer: String) -> Result<(), String> {
|
||||
/// Adds a `PeerId` and its `Multiaddr` as reserved.
|
||||
pub fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String> {
|
||||
self.service.add_reserved_peer(peer)
|
||||
}
|
||||
|
||||
@@ -912,17 +911,16 @@ where
|
||||
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::SetReservedOnly(true));
|
||||
}
|
||||
|
||||
fn add_reserved_peer(&self, peer: String) -> Result<(), String> {
|
||||
let (peer_id, addr) = parse_str_addr(&peer).map_err(|e| format!("{:?}", e))?;
|
||||
fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String> {
|
||||
// Make sure the local peer ID is never added to the PSM.
|
||||
if peer_id == self.local_peer_id {
|
||||
if peer.peer_id == self.local_peer_id {
|
||||
return Err("Local peer ID cannot be added as a reserved peer.".to_string())
|
||||
}
|
||||
|
||||
let _ = self
|
||||
.to_worker
|
||||
.unbounded_send(ServiceToWorkerMsg::AddKnownAddress(peer_id, addr));
|
||||
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::AddReserved(peer_id));
|
||||
.unbounded_send(ServiceToWorkerMsg::AddKnownAddress(peer.peer_id, peer.multiaddr));
|
||||
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::AddReserved(peer.peer_id));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user