Improvements to system_networkState (#2088)

This commit is contained in:
Pierre Krieger
2019-03-26 14:45:11 +01:00
committed by Gav Wood
parent da124d74d1
commit a9420424b2
7 changed files with 49 additions and 23 deletions
+22 -22
View File
@@ -1287,7 +1287,7 @@ dependencies = [
[[package]]
name = "libp2p"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1322,7 +1322,7 @@ dependencies = [
[[package]]
name = "libp2p-core"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1357,7 +1357,7 @@ dependencies = [
[[package]]
name = "libp2p-core-derive"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1366,7 +1366,7 @@ dependencies = [
[[package]]
name = "libp2p-dns"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.5.0 (git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20)",
@@ -1379,7 +1379,7 @@ dependencies = [
[[package]]
name = "libp2p-floodsub"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1398,7 +1398,7 @@ dependencies = [
[[package]]
name = "libp2p-identify"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1419,7 +1419,7 @@ dependencies = [
[[package]]
name = "libp2p-kad"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1447,7 +1447,7 @@ dependencies = [
[[package]]
name = "libp2p-mdns"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1468,7 +1468,7 @@ dependencies = [
[[package]]
name = "libp2p-mplex"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1484,7 +1484,7 @@ dependencies = [
[[package]]
name = "libp2p-noise"
version = "0.3.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"curve25519-dalek 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1502,7 +1502,7 @@ dependencies = [
[[package]]
name = "libp2p-ping"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1521,7 +1521,7 @@ dependencies = [
[[package]]
name = "libp2p-plaintext"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.5.0 (git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20)",
@@ -1531,7 +1531,7 @@ dependencies = [
[[package]]
name = "libp2p-ratelimit"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1544,7 +1544,7 @@ dependencies = [
[[package]]
name = "libp2p-secio"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1570,7 +1570,7 @@ dependencies = [
[[package]]
name = "libp2p-tcp"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.5.0 (git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20)",
@@ -1584,7 +1584,7 @@ dependencies = [
[[package]]
name = "libp2p-uds"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.5.0 (git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20)",
@@ -1596,7 +1596,7 @@ dependencies = [
[[package]]
name = "libp2p-websocket"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.5.0 (git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20)",
@@ -1611,7 +1611,7 @@ dependencies = [
[[package]]
name = "libp2p-yamux"
version = "0.5.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p-core 0.5.0 (git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20)",
@@ -1807,7 +1807,7 @@ dependencies = [
[[package]]
name = "multistream-select"
version = "0.3.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2181,7 +2181,7 @@ dependencies = [
[[package]]
name = "parity-multiaddr"
version = "0.2.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2195,7 +2195,7 @@ dependencies = [
[[package]]
name = "parity-multihash"
version = "0.1.0"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2730,7 +2730,7 @@ dependencies = [
[[package]]
name = "rw-stream-sink"
version = "0.1.1"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#f0a2243eddd71c31e924044e80f03abd2dc61267"
source = "git+https://github.com/tomaka/libp2p-rs?branch=substrate-tmp-2019-03-20#e8e6ccec7409aa19939230d6720035e3ed28dfd6"
dependencies = [
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -129,6 +129,11 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
pub fn drop_node(&mut self, peer_id: &PeerId) {
self.custom_protocols.disconnect_peer(peer_id)
}
/// Returns the state of the peerset manager, for debugging purposes.
pub fn peerset_debug_info(&self) -> serde_json::Value {
self.custom_protocols.peerset_debug_info()
}
}
/// Event that can be emitted by the behaviour.
@@ -317,6 +317,11 @@ impl<TMessage, TSubstream> CustomProto<TMessage, TSubstream> {
self.peerset.discovered(peer_id.clone())
}
/// Returns the state of the peerset manager, for debugging purposes.
pub fn peerset_debug_info(&self) -> serde_json::Value {
self.peerset.debug_info()
}
/// Function that is called when the peerset wants us to connect to a node.
fn peerset_report_connect(&mut self, peer_id: PeerId) {
let mut occ_entry = match self.peers.entry(peer_id) {
+4 -1
View File
@@ -99,7 +99,8 @@ pub struct NetworkState {
pub peer_id: String,
/// List of addresses the node is currently listening on.
pub listened_addresses: HashSet<Multiaddr>,
// TODO (https://github.com/libp2p/rust-libp2p/issues/978): external_addresses: Vec<Multiaddr>,
/// List of addresses the node knows it can be reached as.
pub external_addresses: HashSet<Multiaddr>,
/// List of node we're connected to.
pub connected_peers: HashMap<String, NetworkStatePeer>,
/// List of node that we know of but that we're not connected to.
@@ -108,6 +109,8 @@ pub struct NetworkState {
pub average_download_per_sec: u64,
/// Uploaded bytes per second averaged over the past few seconds.
pub average_upload_per_sec: u64,
/// State of the peerset manager.
pub peerset: serde_json::Value,
}
#[derive(Debug, PartialEq, Serialize)]
@@ -220,10 +220,12 @@ where TMessage: CustomMessage + Send + 'static {
NetworkState {
peer_id: Swarm::local_peer_id(&self.swarm).to_base58(),
listened_addresses: Swarm::listeners(&self.swarm).cloned().collect(),
external_addresses: Swarm::external_addresses(&self.swarm).cloned().collect(),
average_download_per_sec: self.bandwidth.average_download_per_sec(),
average_upload_per_sec: self.bandwidth.average_upload_per_sec(),
connected_peers,
not_connected_peers,
peerset: self.swarm.peerset_debug_info(),
}
}
+7
View File
@@ -23,6 +23,8 @@ use libp2p::PeerId;
use parking_lot::Mutex;
use std::sync::Arc;
pub use serde_json::Value;
/// Shared part of the peer set manager (PSM). Distributed around the code.
pub struct Peerset {
tx: mpsc::UnboundedSender<Message>,
@@ -297,6 +299,11 @@ impl PeersetMut {
}
alloc_slots(&mut inner, &self.parent.tx);
}
/// Produces a JSON object containing the state of the peerset manager, for debugging purposes.
pub fn debug_info(&self) -> serde_json::Value {
serde_json::Value::Null
}
}
impl Stream for PeersetMut {
+4
View File
@@ -50,10 +50,12 @@ impl network::SyncProvider<Block> for Status {
network::NetworkState {
peer_id: String::new(),
listened_addresses: Default::default(),
external_addresses: Default::default(),
connected_peers: Default::default(),
not_connected_peers: Default::default(),
average_download_per_sec: 0,
average_upload_per_sec: 0,
peerset: serde_json::Value::Null,
}
}
@@ -202,10 +204,12 @@ fn system_network_state() {
network::NetworkState {
peer_id: String::new(),
listened_addresses: Default::default(),
external_addresses: Default::default(),
connected_peers: Default::default(),
not_connected_peers: Default::default(),
average_download_per_sec: 0,
average_upload_per_sec: 0,
peerset: serde_json::Value::Null,
}
);
}