expose peer information via rpc (#1362)

* expose peer information via rpc

* fixes tests

* cleanup

Co-Authored-By: xlc <xlchen1291@gmail.com>

* Update docs

Co-Authored-By: xlc <xlchen1291@gmail.com>

* Add missing docs

* keep original type for PeerInfo best_hash/best_number

* cleanup

* Update mod.rs
This commit is contained in:
Xiliang Chen
2019-01-10 00:18:24 +13:00
committed by Gav Wood
parent 43269f0dbc
commit eb3503b0c7
8 changed files with 91 additions and 9 deletions
+14
View File
@@ -240,6 +240,20 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
}
}
pub fn peers(&self) -> Vec<(NodeIndex, PeerInfo<B>)> {
self.context_data.peers.read().iter().map(|(idx, p)| {
(
*idx,
PeerInfo {
roles: p.roles,
protocol_version: p.protocol_version,
best_hash: p.best_hash,
best_number: p.best_number,
}
)
}).collect()
}
pub fn handle_packet(&self, io: &mut SyncIo, who: NodeIndex, mut data: &[u8]) {
let message: Message<B> = match Decode::decode(&mut data) {
Some(m) => m,