diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 23cd0ed6f1995ec38706c950f875b56c1cb758ef..416e0d4a5281acc941ec92276e38bcda41eadb13 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -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)", diff --git a/substrate/core/network-libp2p/src/behaviour.rs b/substrate/core/network-libp2p/src/behaviour.rs index bc41a9cf5539ca06330bf9bebd5f367bb436d88e..c1d175bb1687da2876f0b558f1d7f278025726c2 100644 --- a/substrate/core/network-libp2p/src/behaviour.rs +++ b/substrate/core/network-libp2p/src/behaviour.rs @@ -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. diff --git a/substrate/core/network-libp2p/src/custom_proto/behaviour.rs b/substrate/core/network-libp2p/src/custom_proto/behaviour.rs index fa5b1a3b727cb7932f473d0e615351b49efabd8c..eb60bb9ba4df9ae384959067f1335913ed3c4beb 100644 --- a/substrate/core/network-libp2p/src/custom_proto/behaviour.rs +++ b/substrate/core/network-libp2p/src/custom_proto/behaviour.rs @@ -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) { diff --git a/substrate/core/network-libp2p/src/lib.rs b/substrate/core/network-libp2p/src/lib.rs index 34644da440397c0830c6c16d0f723e2ed857dbf0..5b73db636b0f4d9b54db3418eab58f5ec1aceae4 100644 --- a/substrate/core/network-libp2p/src/lib.rs +++ b/substrate/core/network-libp2p/src/lib.rs @@ -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)] diff --git a/substrate/core/network-libp2p/src/service_task.rs b/substrate/core/network-libp2p/src/service_task.rs index bd4ff45440999fab96e1dd0fb9415434a595c110..a8d184cb73378dd03d69a0822a2cec04b1ae8470 100644 --- a/substrate/core/network-libp2p/src/service_task.rs +++ b/substrate/core/network-libp2p/src/service_task.rs @@ -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(), } } diff --git a/substrate/core/peerset/src/lib.rs b/substrate/core/peerset/src/lib.rs index 74444a2c388a3f2d46dab2af7cbc2327397753fc..b64cafc3e564fa5d3c452f2618bbb102485caf68 100644 --- a/substrate/core/peerset/src/lib.rs +++ b/substrate/core/peerset/src/lib.rs @@ -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 { diff --git a/substrate/core/rpc/src/system/tests.rs b/substrate/core/rpc/src/system/tests.rs index 8f85d9c2df4786f9aaef88f115cfa1fcc7515eaf..b4b71a7937af16e988e6e156a1bdecde1b05ecca 100644 --- a/substrate/core/rpc/src/system/tests.rs +++ b/substrate/core/rpc/src/system/tests.rs @@ -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, } ); }