RPCs for reserved peers (#4423)

* RPC forwarders for adding reserved peers

* implement service side of reserved-peer RPCs

* Clean up unnecessary format! invocation

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* add some tests for the new RPC methods

* remove redundant `data` field

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Robert Habermeier
2019-12-18 14:12:15 +01:00
committed by GitHub
parent 637d95e5ea
commit da87c3c1e3
6 changed files with 125 additions and 3 deletions
+13 -1
View File
@@ -408,6 +408,17 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkWorker
.map(|(id, info)| (id.clone(), info.clone()))
.collect()
}
/// Removes a `PeerId` from the list of reserved peers.
pub fn remove_reserved_peer(&self, peer: PeerId) {
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> {
self.service.add_reserved_peer(peer)
}
}
impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkService<B, S, H> {
@@ -553,7 +564,8 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
self.peerset.remove_reserved_peer(peer);
}
/// Adds a `PeerId` and its address as reserved.
/// 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> {
let (peer_id, addr) = parse_str_addr(&peer).map_err(|e| format!("{:?}", e))?;
self.peerset.add_reserved_peer(peer_id.clone());