Upgrade to libp2p v0.19 - Changes the default PeerId representation (#6064)

* Upgrade to libp2p v0.19

* Listen on IPv6 by default

* Increase channels sizes

* Use spec-compliant noise protocol

* Show legacy PeerId

* Switch order of Noise protocols

* Switch to crates.io version

* Fix subkey's version

* Fix line width and Wasm build

* I think Wasm is fixed for real this time
This commit is contained in:
Pierre Krieger
2020-05-18 19:57:08 +02:00
committed by GitHub
parent 80accdbf7c
commit 8b9bd9018e
15 changed files with 143 additions and 93 deletions
+66 -52
View File
@@ -452,9 +452,9 @@ dependencies = [
[[package]]
name = "bs58"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae"
checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb"
[[package]]
name = "bstr"
@@ -2598,9 +2598,9 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
[[package]]
name = "libp2p"
version = "0.18.1"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32ea742c86405b659c358223a8f0f9f5a9eb27bb6083894c6340959b05269662"
checksum = "3ec214d189b57e4412f079ac5a1442578d06b12ca7282ba4696104cc92ab96c1"
dependencies = [
"bytes 0.5.4",
"futures 0.3.4",
@@ -2627,7 +2627,7 @@ dependencies = [
"libp2p-websocket",
"libp2p-yamux",
"multihash",
"parity-multiaddr 0.8.0",
"parity-multiaddr 0.9.0",
"parking_lot 0.10.2",
"pin-project",
"smallvec 1.3.0",
@@ -2636,9 +2636,9 @@ dependencies = [
[[package]]
name = "libp2p-core"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d2c17158c4dca984a77a5927aac6f0862d7f50c013470a415f93be498b5739"
checksum = "80a6000296bdbff540b6c00ef82108ef23aa68d195b9333823ea491562c338d7"
dependencies = [
"asn1_der",
"bs58",
@@ -2652,7 +2652,7 @@ dependencies = [
"log",
"multihash",
"multistream-select",
"parity-multiaddr 0.8.0",
"parity-multiaddr 0.9.0",
"parking_lot 0.10.2",
"pin-project",
"prost",
@@ -2670,9 +2670,9 @@ dependencies = [
[[package]]
name = "libp2p-core-derive"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "329127858e4728db5ab60c33d5ae352a999325fdf190ed022ec7d3a4685ae2e6"
checksum = "67f0d915bee5d457a6d113377101e1f06e86a4286778aa4c6939553e9a4d7033"
dependencies = [
"quote 1.0.3",
"syn 1.0.17",
@@ -2680,9 +2680,9 @@ dependencies = [
[[package]]
name = "libp2p-deflate"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ad32b006ea922da8cc66e537cf2df4b0fad8ebaa467d2a8c63d7784ac252ec6"
checksum = "975c847575ef9b3d63f9c11d465e9a9b0ea940cfa408b93cc6981bbc3b1bac40"
dependencies = [
"flate2",
"futures 0.3.4",
@@ -2691,9 +2691,9 @@ dependencies = [
[[package]]
name = "libp2p-dns"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0d0993481203d68e5ce2f787d033fb0cac6b850659ed6c784612db678977c71"
checksum = "3cc186d9a941fd0207cf8f08ef225a735e2d7296258f570155e525f6ee732f87"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@@ -2702,9 +2702,9 @@ dependencies = [
[[package]]
name = "libp2p-floodsub"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3673153ca967c179d745fadf047d069355d6669ecf7f261b450fbaebf1bffd3d"
checksum = "c6dd8cc558e0edde2d4a423d017efd6b36c1b6bf97f4304c83076895c5edaed8"
dependencies = [
"cuckoofilter",
"fnv",
@@ -2719,9 +2719,9 @@ dependencies = [
[[package]]
name = "libp2p-gossipsub"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f7f3f79f060864db0317cc47641b7d35276dee52a0ffa91553fbd0c153863a3"
checksum = "ce48659363fe765c09d77eb5b2248e04362557b11bba3701f05879ad34919ccd"
dependencies = [
"base64 0.11.0",
"byteorder 1.3.4",
@@ -2744,9 +2744,9 @@ dependencies = [
[[package]]
name = "libp2p-identify"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a38ca3eb807789e26f41c82ca7cd2b3843c66c5587b8b5f709a2f421f3061414"
checksum = "6a455af71c59473444eba05e83dbaa20262bdbd9b4154f22389510fbac16f201"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@@ -2760,9 +2760,9 @@ dependencies = [
[[package]]
name = "libp2p-kad"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92cda1fb8149ea64d092a2b99d2bd7a2c309eee38ea322d02e4480bd6ee1759"
checksum = "41d6c1d5100973527ae70d82687465b17049c1b717a7964de38b8e65000878ff"
dependencies = [
"arrayvec 0.5.1",
"bytes 0.5.4",
@@ -2787,9 +2787,9 @@ dependencies = [
[[package]]
name = "libp2p-mdns"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41e908d2aaf8ff0ec6ad1f02fe1844fd777fb0b03a68a226423630750ab99471"
checksum = "d5bc788d92111802cb0c92d2e032fa6f46333aaeb5650c2f37b5d3eba78cabe6"
dependencies = [
"async-std",
"data-encoding",
@@ -2809,9 +2809,9 @@ dependencies = [
[[package]]
name = "libp2p-mplex"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0832882b06619b2e81d74e71447753ea3c068164a0bca67847d272e856a04a02"
checksum = "4095bce2100f840883f1f75dbd010c966ee4ad323ae9f82026396da5cf6cce68"
dependencies = [
"bytes 0.5.4",
"fnv",
@@ -2825,9 +2825,9 @@ dependencies = [
[[package]]
name = "libp2p-noise"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "918e94a649e1139c24ee9f1f8c1f2adaba6d157b9471af787f2d9beac8c29c77"
checksum = "84fd504e27b0eadd451e06b67694ef714bd8374044e7db339bb0cdb83755ddf4"
dependencies = [
"curve25519-dalek",
"futures 0.3.4",
@@ -2846,9 +2846,9 @@ dependencies = [
[[package]]
name = "libp2p-ping"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9bfbf87eebb492d040f9899c5c81c9738730465ac5e78d9b7a7d086d0f07230"
checksum = "82930c36490008b1ef2f26c237a2c205c38ef6edc263738d0528b842740ab09f"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@@ -2861,9 +2861,9 @@ dependencies = [
[[package]]
name = "libp2p-plaintext"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fabb00553a49bf6d4a8ce362f6eefac410227a14d03c3acffbb8cc3f022ea019"
checksum = "ad28fe7beaa3e516ee8ba2af8c4f6820f269afa60d661831e879f2afea64f4a0"
dependencies = [
"bytes 0.5.4",
"futures 0.3.4",
@@ -2879,9 +2879,9 @@ dependencies = [
[[package]]
name = "libp2p-pnet"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f81b8b37ff529e1f51c20c396dac657def2108da174c1d27e57e72c9fe2d411"
checksum = "dabaa2194e1ce3c51cd78d734dd4c81dc5c7b150b309cbf9029df044034ac261"
dependencies = [
"futures 0.3.4",
"log",
@@ -2893,9 +2893,9 @@ dependencies = [
[[package]]
name = "libp2p-secio"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a0509a7e47245259954fef58b85b81bf4d29ae33a4365e38d718a866698774"
checksum = "22e30b873276846181fa9c04126653678c2797cb1556361d01b7b7fd6bf24682"
dependencies = [
"aes-ctr",
"ctr",
@@ -2923,9 +2923,9 @@ dependencies = [
[[package]]
name = "libp2p-swarm"
version = "0.18.1"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44ab289ae44cc691da0a6fe96aefa43f26c86c6c7813998e203f6d80f1860f18"
checksum = "b4a8101a0e0d5f04562137a476bf5f5423cd5bdab2f7e43a75909668e63cb102"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@@ -2938,9 +2938,9 @@ dependencies = [
[[package]]
name = "libp2p-tcp"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b37ea44823d3ed223e4605da94b50177bc520f05ae2452286700549a32d81669"
checksum = "4462bd96b97cac3f3a83b1b343ad3c3460cebbc8d929c040b1520c30e3611e08"
dependencies = [
"async-std",
"futures 0.3.4",
@@ -2949,13 +2949,14 @@ dependencies = [
"ipnet",
"libp2p-core",
"log",
"socket2",
]
[[package]]
name = "libp2p-uds"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "281c18ea2faacb9c8a6ff76c4405df5918d9a263770e3847bf03f099abadc010"
checksum = "69660d235449bb2d99333b9892c9176d06fd2b380490cb8213feb5b015678cf1"
dependencies = [
"async-std",
"futures 0.3.4",
@@ -2965,9 +2966,9 @@ dependencies = [
[[package]]
name = "libp2p-wasm-ext"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3ac7dbde0f88cad191dcdfd073b8bae28d01823e8ca313f117b6ecb914160c3"
checksum = "f59fdbb5706f2723ca108c088b1c7a37f735a8c328021f0508007162627e9885"
dependencies = [
"futures 0.3.4",
"js-sys",
@@ -2979,9 +2980,9 @@ dependencies = [
[[package]]
name = "libp2p-websocket"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6874c9069ce93d899df9dc7b29f129c706b2a0fdc048f11d878935352b580190"
checksum = "085fbe4c05c4116c2164ab4d5a521eb6e00516c444f61b3ee9f68c7b1e53580b"
dependencies = [
"async-tls",
"bytes 0.5.4",
@@ -3000,9 +3001,9 @@ dependencies = [
[[package]]
name = "libp2p-yamux"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02f91aea50f6571e0bc6c058dc0e9b270afd41ec28dd94e9e4bf607e78b9ab87"
checksum = "0b305d3a8981e68f11c0e17f2d11d5c52fae95e0d7c283f9e462b5b2dab413b2"
dependencies = [
"futures 0.3.4",
"libp2p-core",
@@ -3269,9 +3270,9 @@ checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238"
[[package]]
name = "multihash"
version = "0.10.1"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47fbc227f7e2b1cb701f95404579ecb2668abbdd3c7ef7a6cbb3cc0d3b236869"
checksum = "ae32179a9904ccc6e063de8beee7f5dd55fae85ecb851ca923d55722bc28cf5d"
dependencies = [
"blake2b_simd",
"blake2s_simd",
@@ -4773,9 +4774,9 @@ dependencies = [
[[package]]
name = "parity-multiaddr"
version = "0.8.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4db35e222f783ef4e6661873f6c165c4eb7b65e0c408349818517d5705c2d7d3"
checksum = "12ca96399f4a01aa89c59220c4f52ac371940eb4e53e3ce990da796f364bdf69"
dependencies = [
"arrayref",
"bs58",
@@ -6461,6 +6462,7 @@ dependencies = [
"assert_matches",
"async-std",
"bitflags",
"bs58",
"bytes 0.5.4",
"derive_more",
"either",
@@ -7218,6 +7220,18 @@ dependencies = [
"x25519-dalek",
]
[[package]]
name = "socket2"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi 0.3.8",
]
[[package]]
name = "soketto"
version = "0.3.2"
@@ -8,7 +8,7 @@ license = "Apache-2.0"
[dependencies]
futures-timer = "3.0.2"
libp2p = { version = "0.18.0", default-features = false }
libp2p = { version = "0.19.0", default-features = false }
jsonrpc-core = "14.0.5"
serde = "1.0.106"
serde_json = "1.0.48"
+1 -1
View File
@@ -33,7 +33,7 @@ derive_more = { version = "0.99.2" }
sc-rpc = { version = "2.0.0-dev", path = "../../../client/rpc" }
jsonrpc-core-client = { version = "14.0.3", features = ["http"] }
hyper = "0.12.35"
libp2p = "0.18.1"
libp2p = "0.19.0"
serde_json = "1.0"
[features]
@@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", default-features = false, version = "1
derive_more = "0.99.2"
futures = "0.3.4"
futures-timer = "3.0.1"
libp2p = { version = "0.18.1", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
libp2p = { version = "0.19.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-dev"}
prost = "0.6.1"
@@ -123,6 +123,9 @@ impl NetworkParams {
let listen_addresses = if self.listen_addr.is_empty() {
vec![
Multiaddr::empty()
.with(Protocol::Ip6([0, 0, 0, 0, 0, 0, 0, 0].into()))
.with(Protocol::Tcp(port)),
Multiaddr::empty()
.with(Protocol::Ip4([0, 0, 0, 0].into()))
.with(Protocol::Tcp(port)),
+1 -1
View File
@@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.4"
futures-timer = "3.0.1"
libp2p = { version = "0.18.1", default-features = false, features = ["websocket"] }
libp2p = { version = "0.19.0", default-features = false, features = ["websocket"] }
log = "0.4.8"
lru = "0.4.3"
sc-network = { version = "0.8.0-dev", path = "../network" }
+4 -3
View File
@@ -19,6 +19,7 @@ prost-build = "0.6.1"
[dependencies]
bitflags = "1.2.0"
bs58 = "0.3.1"
bytes = "0.5.0"
codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] }
derive_more = "0.99.2"
@@ -62,15 +63,15 @@ wasm-timer = "0.2"
zeroize = "1.0.0"
[dependencies.libp2p]
version = "0.18.1"
version = "0.19.0"
default-features = false
features = ["websocket", "kad", "mdns", "ping", "identify", "mplex", "yamux", "noise"]
features = ["websocket", "kad", "mdns", "ping", "identify", "mplex", "yamux", "noise", "tcp-async-std"]
[dev-dependencies]
async-std = "1.5"
assert_matches = "1.3"
env_logger = "0.7.0"
libp2p = { version = "0.18.1", default-features = false, features = ["secio"] }
libp2p = { version = "0.19.0", default-features = false, features = ["secio"] }
quickcheck = "0.9.0"
rand = "0.7.2"
sp-keyring = { version = "2.0.0-dev", path = "../../primitives/keyring" }
+18 -17
View File
@@ -52,7 +52,7 @@ use ip_network::IpNetwork;
use libp2p::core::{connection::{ConnectionId, ListenerId}, ConnectedPoint, Multiaddr, PeerId, PublicKey};
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters, ProtocolsHandler};
use libp2p::swarm::protocols_handler::multi::MultiHandler;
use libp2p::kad::{Kademlia, KademliaConfig, KademliaEvent, Quorum, Record};
use libp2p::kad::{Kademlia, KademliaConfig, KademliaEvent, QueryResult, Quorum, Record};
use libp2p::kad::GetClosestPeersError;
use libp2p::kad::handler::KademliaHandler;
use libp2p::kad::QueryId;
@@ -177,7 +177,7 @@ impl DiscoveryConfig {
kademlias: self.kademlias,
next_kad_random_query: Delay::new(Duration::new(0, 0)),
duration_to_next_kad: Duration::from_secs(1),
discoveries: VecDeque::new(),
pending_events: VecDeque::new(),
local_peer_id: self.local_peer_id,
num_connections: 0,
allow_private_ipv4: self.allow_private_ipv4,
@@ -213,8 +213,8 @@ pub struct DiscoveryBehaviour {
next_kad_random_query: Delay,
/// After `next_kad_random_query` triggers, the next one triggers after this duration.
duration_to_next_kad: Duration,
/// Discovered nodes to return.
discoveries: VecDeque<PeerId>,
/// Events to return in priority when polled.
pending_events: VecDeque<DiscoveryOut>,
/// Identity of our local node.
local_peer_id: PeerId,
/// Number of nodes we're currently connected to.
@@ -248,7 +248,7 @@ impl DiscoveryBehaviour {
for k in self.kademlias.values_mut() {
k.add_address(&peer_id, addr.clone())
}
self.discoveries.push_back(peer_id.clone());
self.pending_events.push_back(DiscoveryOut::Discovered(peer_id.clone()));
self.user_defined.push((peer_id, addr));
}
}
@@ -272,7 +272,7 @@ impl DiscoveryBehaviour {
/// A corresponding `ValueFound` or `ValueNotFound` event will later be generated.
pub fn get_value(&mut self, key: &record::Key) {
for k in self.kademlias.values_mut() {
k.get_record(key, Quorum::One)
k.get_record(key, Quorum::One);
}
}
@@ -282,7 +282,10 @@ impl DiscoveryBehaviour {
/// A corresponding `ValuePut` or `ValuePutFailed` event will later be generated.
pub fn put_value(&mut self, key: record::Key, value: Vec<u8>) {
for k in self.kademlias.values_mut() {
k.put_record(Record::new(key.clone(), value.clone()), Quorum::All)
if let Err(e) = k.put_record(Record::new(key.clone(), value.clone()), Quorum::All) {
warn!(target: "sub-libp2p", "Libp2p => Failed to put record: {:?}", e);
self.pending_events.push_back(DiscoveryOut::ValuePutFailed(key.clone()));
}
}
}
@@ -528,8 +531,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
>,
> {
// Immediately process the content of `discovered`.
if let Some(peer_id) = self.discoveries.pop_front() {
let ev = DiscoveryOut::Discovered(peer_id);
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
@@ -541,7 +543,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
"Libp2p <= Starting random Kademlia request for {:?}",
random_peer_id);
for k in self.kademlias.values_mut() {
k.get_closest_peers(random_peer_id.clone())
k.get_closest_peers(random_peer_id.clone());
}
true
} else {
@@ -578,7 +580,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
let ev = DiscoveryOut::Discovered(peer);
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
KademliaEvent::GetClosestPeersResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::GetClosestPeers(res), .. } => {
match res {
Err(GetClosestPeersError::Timeout { key, peers }) => {
debug!(target: "sub-libp2p",
@@ -596,7 +598,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
}
}
}
KademliaEvent::GetRecordResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::GetRecord(res), .. } => {
let ev = match res {
Ok(ok) => {
let results = ok.records
@@ -619,7 +621,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
};
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
KademliaEvent::PutRecordResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::PutRecord(res), .. } => {
let ev = match res {
Ok(ok) => DiscoveryOut::ValuePut(ok.key),
Err(e) => {
@@ -630,7 +632,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
};
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
KademliaEvent::RepublishRecordResult(res) => {
KademliaEvent::QueryResult { result: QueryResult::RepublishRecord(res), .. } => {
match res {
Ok(ok) => debug!(target: "sub-libp2p",
"Libp2p => Record republished: {:?}",
@@ -675,9 +677,8 @@ impl NetworkBehaviour for DiscoveryBehaviour {
continue;
}
self.discoveries.extend(list.map(|(peer_id, _)| peer_id));
if let Some(peer_id) = self.discoveries.pop_front() {
let ev = DiscoveryOut::Discovered(peer_id);
self.pending_events.extend(list.map(|(peer_id, _)| DiscoveryOut::Discovered(peer_id)));
if let Some(ev) = self.pending_events.pop_front() {
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(ev));
}
},
+12 -3
View File
@@ -59,10 +59,11 @@ use sp_runtime::{
};
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use std::{
borrow::Cow,
borrow::{Borrow, Cow},
collections::HashSet,
fs, io,
marker::PhantomData,
num:: NonZeroUsize,
pin::Pin,
str,
sync::{
@@ -185,7 +186,13 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let local_identity = params.network_config.node_key.clone().into_keypair()?;
let local_public = local_identity.public();
let local_peer_id = local_public.clone().into_peer_id();
info!(target: "sub-libp2p", "🏷 Local node identity is: {}", local_peer_id.to_base58());
let local_peer_id_legacy = bs58::encode(Borrow::<[u8]>::borrow(&local_peer_id)).into_string();
info!(
target: "sub-libp2p",
"🏷 Local node identity is: {} (legacy representation: {})",
local_peer_id.to_base58(),
local_peer_id_legacy
);
// Initialize the metrics.
let metrics = match &params.metrics_registry {
@@ -287,7 +294,9 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
transport::build_transport(local_identity, config_mem, config_wasm, flowctrl)
};
let mut builder = SwarmBuilder::new(transport, behaviour, local_peer_id.clone())
.peer_connection_limit(crate::MAX_CONNECTIONS_PER_PEER);
.peer_connection_limit(crate::MAX_CONNECTIONS_PER_PEER)
.notify_handler_buffer_size(NonZeroUsize::new(16).expect("16 != 0; qed"))
.connection_event_buffer_size(128);
if let Some(spawner) = params.executor {
struct SpawnImpl<F>(F);
impl<F: Fn(Pin<Box<dyn Future<Output = ()> + Send>>)> Executor for SpawnImpl<F> {
+31 -9
View File
@@ -18,11 +18,14 @@
use futures::prelude::*;
use libp2p::{
InboundUpgradeExt, OutboundUpgradeExt, PeerId, Transport,
core::{
self, either::{EitherError, EitherOutput}, muxing::StreamMuxerBox,
transport::{boxed::Boxed, OptionalTransport}, upgrade
},
mplex, identity, bandwidth, wasm_ext, noise
};
#[cfg(not(target_os = "unknown"))]
use libp2p::{tcp, dns, websocket};
use libp2p::core::{self, upgrade, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox};
use std::{io, sync::Arc, time::Duration, usize};
pub use self::bandwidth::BandwidthSinks;
@@ -42,14 +45,22 @@ pub fn build_transport(
) -> (Boxed<(PeerId, StreamMuxerBox), io::Error>, Arc<bandwidth::BandwidthSinks>) {
// Build configuration objects for encryption mechanisms.
let noise_config = {
let noise_keypair = noise::Keypair::new().into_authentic(&keypair)
// For more information about this panic, see in "On the Importance of Checking
// Cryptographic Protocols for Faults" by Dan Boneh, Richard A. DeMillo,
// and Richard J. Lipton.
// For more information about these two panics, see in "On the Importance of
// Checking Cryptographic Protocols for Faults" by Dan Boneh, Richard A. DeMillo,
// and Richard J. Lipton.
let noise_keypair_legacy = noise::Keypair::<noise::X25519>::new().into_authentic(&keypair)
.expect("can only fail in case of a hardware bug; since this signing is performed only \
once and at initialization, we're taking the bet that the inconvenience of a very \
rare panic here is basically zero");
noise::NoiseConfig::ix(noise_keypair)
let noise_keypair_spec = noise::Keypair::<noise::X25519Spec>::new().into_authentic(&keypair)
.expect("can only fail in case of a hardware bug; since this signing is performed only \
once and at initialization, we're taking the bet that the inconvenience of a very \
rare panic here is basically zero");
core::upgrade::SelectUpgrade::new(
noise::NoiseConfig::xx(noise_keypair_spec),
noise::NoiseConfig::ix(noise_keypair_legacy)
)
};
// Build configuration objects for multiplexing mechanisms.
@@ -97,11 +108,22 @@ pub fn build_transport(
// Encryption
let transport = transport.and_then(move |stream, endpoint| {
core::upgrade::apply(stream, noise_config, endpoint, upgrade::Version::V1)
.and_then(|(remote_id, out)| async move {
let remote_key = match remote_id {
noise::RemoteIdentity::IdentityKey(key) => key,
.map_err(|err|
err.map_err(|err| match err {
EitherError::A(err) => err,
EitherError::B(err) => err,
})
)
.and_then(|result| async move {
let remote_key = match &result {
EitherOutput::First((noise::RemoteIdentity::IdentityKey(key), _)) => key.clone(),
EitherOutput::Second((noise::RemoteIdentity::IdentityKey(key), _)) => key.clone(),
_ => return Err(upgrade::UpgradeError::Apply(noise::NoiseError::InvalidKey))
};
let out = match result {
EitherOutput::First((_, o)) => o,
EitherOutput::Second((_, o)) => o,
};
Ok((out, remote_key.into_peer_id()))
})
});
+1 -1
View File
@@ -19,7 +19,7 @@ parking_lot = "0.10.0"
futures = "0.3.4"
futures-timer = "3.0.1"
rand = "0.7.2"
libp2p = { version = "0.18.1", default-features = false, features = ["libp2p-websocket"] }
libp2p = { version = "0.19.0", default-features = false, features = ["libp2p-websocket"] }
sp-consensus = { version = "0.8.0-dev", path = "../../../primitives/consensus/common" }
sc-consensus = { version = "0.8.0-dev", path = "../../../client/consensus/common" }
sc-client-api = { version = "2.0.0-dev", path = "../../api" }
+1 -1
View File
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.4"
libp2p = { version = "0.18.1", default-features = false }
libp2p = { version = "0.19.0", default-features = false }
sp-utils = { version = "2.0.0-dev", path = "../../primitives/utils"}
log = "0.4.8"
serde_json = "1.0.41"
+1 -1
View File
@@ -19,7 +19,7 @@ parking_lot = "0.10.0"
futures = "0.3.4"
futures-timer = "3.0.1"
wasm-timer = "0.2.0"
libp2p = { version = "0.18.1", default-features = false, features = ["websocket", "wasm-ext", "tcp", "dns"] }
libp2p = { version = "0.19.0", default-features = false, features = ["websocket", "wasm-ext", "tcp-async-std", "dns"] }
log = "0.4.8"
pin-project = "0.4.6"
rand = "0.7.2"
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
derive_more = "0.99.2"
libp2p = { version = "0.18.1", default-features = false }
libp2p = { version = "0.19.0", default-features = false }
log = "0.4.8"
sp-core = { path= "../../core", version = "2.0.0-dev"}
sp-inherents = { version = "2.0.0-dev", path = "../../inherents" }
+1 -1
View File
@@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
futures = { version = "0.3", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }
log = "0.4.8"
libp2p-wasm-ext = { version = "0.18.0", features = ["websocket"] }
libp2p-wasm-ext = { version = "0.19.0", features = ["websocket"] }
console_error_panic_hook = "0.1.6"
console_log = "0.1.2"
js-sys = "0.3.34"