From 1402bcf081eb1931e787111dac5ee0d1e99b4acf Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 9 Jun 2020 17:23:14 +0200 Subject: [PATCH 1/2] Add support for QUIC --- Cargo.lock | 154 ++++++++++++++------ Cargo.toml | 4 + bin/node/browser-testing/Cargo.toml | 2 +- bin/utils/subkey/Cargo.toml | 2 +- client/authority-discovery/Cargo.toml | 2 +- client/cli/src/params/network_params.rs | 17 +++ client/network-gossip/Cargo.toml | 2 +- client/network/Cargo.toml | 8 +- client/network/src/config.rs | 8 +- client/network/src/lib.rs | 7 +- client/network/src/service.rs | 8 +- client/network/src/transport.rs | 41 +++++- client/network/test/Cargo.toml | 2 +- client/peerset/Cargo.toml | 2 +- client/telemetry/Cargo.toml | 2 +- primitives/consensus/common/Cargo.toml | 2 +- primitives/npos-elections/fuzzer/Cargo.lock | 2 +- utils/browser/Cargo.toml | 2 +- 18 files changed, 200 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83c98c65c6cb0..7fa6781057a01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1178,6 +1178,20 @@ dependencies = [ "serde", ] +[[package]] +name = "err-derive" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22deed3a8124cff5fa835713fa105621e43bbdc46690c3a6b68328a012d350d4" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote 1.0.6", + "rustversion", + "syn 1.0.17", + "synstructure", +] + [[package]] name = "errno" version = "0.2.5" @@ -2573,8 +2587,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libp2p" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057eba5432d3e740e313c6e13c9153d0cb76b4f71bfc2e5242ae5bdb7d41af67" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "bytes 0.5.4", "futures 0.3.4", @@ -2588,6 +2601,7 @@ dependencies = [ "libp2p-mplex", "libp2p-noise", "libp2p-ping", + "libp2p-quic", "libp2p-secio", "libp2p-swarm", "libp2p-tcp", @@ -2604,9 +2618,8 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80a6000296bdbff540b6c00ef82108ef23aa68d195b9333823ea491562c338d7" +version = "0.19.1" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "asn1_der", "bs58", @@ -2639,8 +2652,7 @@ dependencies = [ [[package]] name = "libp2p-core-derive" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09548626b737ed64080fde595e06ce1117795b8b9fc4d2629fa36561c583171" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "quote 1.0.6", "syn 1.0.17", @@ -2649,8 +2661,7 @@ dependencies = [ [[package]] name = "libp2p-dns" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc186d9a941fd0207cf8f08ef225a735e2d7296258f570155e525f6ee732f87" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "futures 0.3.4", "libp2p-core", @@ -2660,8 +2671,7 @@ dependencies = [ [[package]] name = "libp2p-identify" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6438ed8ca240c7635c9caa3be6c5258bc0058553ae97ba81737f04e5d33804f5" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "futures 0.3.4", "libp2p-core", @@ -2676,8 +2686,7 @@ dependencies = [ [[package]] name = "libp2p-kad" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d6c1d5100973527ae70d82687465b17049c1b717a7964de38b8e65000878ff" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "arrayvec 0.5.1", "bytes 0.5.4", @@ -2703,8 +2712,7 @@ dependencies = [ [[package]] name = "libp2p-mdns" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b00163d13f705aae67c427bea0575f8aaf63da6524f9bd4a5a093b8bda0b38" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "async-std", "data-encoding", @@ -2725,8 +2733,7 @@ dependencies = [ [[package]] name = "libp2p-mplex" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ce63313ad4bce2d76e54c292a1293ea47a0ebbe16708f1513fa62184992f53" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "bytes 0.5.4", "fnv", @@ -2741,8 +2748,7 @@ dependencies = [ [[package]] name = "libp2p-noise" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fd504e27b0eadd451e06b67694ef714bd8374044e7db339bb0cdb83755ddf4" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "curve25519-dalek", "futures 0.3.4", @@ -2762,8 +2768,7 @@ dependencies = [ [[package]] name = "libp2p-ping" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c189cf1dfe4b3f01e2c0fe5e97a6f5df8aeb6f3569e26981015eb7c08015ce5f" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "futures 0.3.4", "libp2p-core", @@ -2774,11 +2779,35 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-quic" +version = "0.19.0" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" +dependencies = [ + "async-std", + "either", + "env_logger 0.7.1", + "futures 0.3.4", + "futures-timer 3.0.2", + "ipnet", + "libp2p-core", + "log", + "parking_lot 0.10.2", + "quinn-proto", + "rcgen", + "ring", + "rustls", + "thiserror", + "untrusted", + "webpki", + "x509-signature", + "yasna", +] + [[package]] name = "libp2p-secio" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b73f0cc119c83a5b619d6d11074a319fdb4aa4daf8088ade00d511418566e28" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "aes-ctr", "ctr", @@ -2807,8 +2836,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a8101a0e0d5f04562137a476bf5f5423cd5bdab2f7e43a75909668e63cb102" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "futures 0.3.4", "libp2p-core", @@ -2822,8 +2850,7 @@ dependencies = [ [[package]] name = "libp2p-tcp" version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309f95fce9bec755eff5406f8b822fd3969990830c2b54f752e1fc181d5ace3e" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "async-std", "futures 0.3.4", @@ -2838,8 +2865,7 @@ dependencies = [ [[package]] name = "libp2p-wasm-ext" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f59fdbb5706f2723ca108c088b1c7a37f735a8c328021f0508007162627e9885" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "futures 0.3.4", "js-sys", @@ -2852,8 +2878,7 @@ dependencies = [ [[package]] name = "libp2p-websocket" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "085fbe4c05c4116c2164ab4d5a521eb6e00516c444f61b3ee9f68c7b1e53580b" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "async-tls", "bytes 0.5.4", @@ -2873,8 +2898,7 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b305d3a8981e68f11c0e17f2d11d5c52fae95e0d7c283f9e462b5b2dab413b2" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "futures 0.3.4", "libp2p-core", @@ -3162,9 +3186,8 @@ checksum = "d8883adfde9756c1d30b0f519c9b8c502a94b41ac62f696453c37c7fc0a958ce" [[package]] name = "multistream-select" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74cdcf7cfb3402881e15a1f95116cb033d69b33c83d481e1234777f5ef0c3d2c" +version = "0.8.1" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "bytes 0.5.4", "futures 0.3.4", @@ -4673,13 +4696,14 @@ dependencies = [ [[package]] name = "parity-multiaddr" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ca96399f4a01aa89c59220c4f52ac371940eb4e53e3ce990da796f364bdf69" +source = "git+https://github.com/tomaka/libp2p-rs?branch=quiccc-again#9eb64789c7aeb2da3bc31ed68fb08135c8e14533" dependencies = [ "arrayref", "bs58", "byteorder", "data-encoding", + "get_if_addrs", + "ipnet", "multihash", "percent-encoding 2.1.0", "serde", @@ -5192,6 +5216,21 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "quinn-proto" +version = "0.6.1" +source = "git+https://github.com/djc/quinn?rev=6e9f7e8063926f8bdab56bbc1615277ff0bdece5#6e9f7e8063926f8bdab56bbc1615277ff0bdece5" +dependencies = [ + "bytes 0.5.4", + "err-derive", + "rand 0.7.3", + "ring", + "rustls", + "slab", + "tracing", + "webpki", +] + [[package]] name = "quote" version = "0.3.15" @@ -5458,6 +5497,17 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "rcgen" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaf214336e8af62987464e9d57f72689822ebf96e913e733a5e32cf7fb7efbd" +dependencies = [ + "chrono", + "ring", + "yasna", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -5655,10 +5705,9 @@ dependencies = [ [[package]] name = "rustls" version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0d4a31f5d68413404705d6982529b0e11a9aacd4839d1d6222ee3b8cb4015e1" +source = "git+https://github.com/ctz/rustls?rev=cac66a8c184f3ef8510bb62b390f241c2760f51d#cac66a8c184f3ef8510bb62b390f241c2760f51d" dependencies = [ - "base64 0.11.0", + "base64 0.12.0", "log", "ring", "sct", @@ -8933,7 +8982,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56" dependencies = [ - "rand 0.7.3", + "rand 0.3.23", ] [[package]] @@ -9486,6 +9535,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "x509-signature" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2859657e49c2b42f5e024e45a0f92e7d5a05555ffa7a62f2629073599e7482f" +dependencies = [ + "ring", + "rustls", + "untrusted", + "webpki", +] + [[package]] name = "yamux" version = "0.4.5" @@ -9500,6 +9561,15 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "yasna" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de7bff972b4f2a06c85f6d8454b09df153af7e3a4ec2aac81db1b105b684ddb" +dependencies = [ + "chrono", +] + [[package]] name = "zeroize" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index d3004fcadca5a..93fc35c1c4912 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -253,3 +253,7 @@ zeroize = { opt-level = 3 } [profile.release] # Substrate runtime requires unwinding. panic = "unwind" + +[patch.crates-io] +rustls = { git = "https://github.com/ctz/rustls", rev = "cac66a8c184f3ef8510bb62b390f241c2760f51d" } +quinn-proto = { git = "https://github.com/djc/quinn", rev = "6e9f7e8063926f8bdab56bbc1615277ff0bdece5" } diff --git a/bin/node/browser-testing/Cargo.toml b/bin/node/browser-testing/Cargo.toml index 9e31d734c3ce6..d8666a3ba813f 100644 --- a/bin/node/browser-testing/Cargo.toml +++ b/bin/node/browser-testing/Cargo.toml @@ -8,7 +8,7 @@ license = "Apache-2.0" [dependencies] futures-timer = "3.0.2" -libp2p = { version = "0.19.1", default-features = false } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false } jsonrpc-core = "14.2.0" serde = "1.0.106" serde_json = "1.0.48" diff --git a/bin/utils/subkey/Cargo.toml b/bin/utils/subkey/Cargo.toml index 064470ea7cb4e..3a0361132f6a4 100644 --- a/bin/utils/subkey/Cargo.toml +++ b/bin/utils/subkey/Cargo.toml @@ -33,7 +33,7 @@ derive_more = { version = "0.99.2" } sc-rpc = { version = "2.0.0-rc3", path = "../../../client/rpc" } jsonrpc-core-client = { version = "14.2.0", features = ["http"] } hyper = "0.12.35" -libp2p = { version = "0.19.1", default-features = false } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false } serde_json = "1.0" [features] diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml index 8833306f06010..77f0080ea867c 100644 --- a/client/authority-discovery/Cargo.toml +++ b/client/authority-discovery/Cargo.toml @@ -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.19.1", default-features = false, features = ["kad"] } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false, features = ["kad"] } log = "0.4.8" prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-rc3"} prost = "0.6.1" diff --git a/client/cli/src/params/network_params.rs b/client/cli/src/params/network_params.rs index 2e0a6f1973064..e5038a88d77c1 100644 --- a/client/cli/src/params/network_params.rs +++ b/client/cli/src/params/network_params.rs @@ -56,6 +56,10 @@ pub struct NetworkParams { #[structopt(long = "port", value_name = "PORT", conflicts_with_all = &[ "listen-addr" ])] pub port: Option, + /// UDP port to use for QUIC connections. + #[structopt(long = "quic-port", value_name = "PORT", conflicts_with_all = &["disable-quic"])] + pub quic_port: Option, + /// Forbid connecting to private IPv4 addresses (as specified in /// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with /// `--reserved-nodes` or `--bootnodes`. @@ -107,6 +111,13 @@ pub struct NetworkParams { /// This option will be removed in the future. #[structopt(long)] pub legacy_network_protocol: bool, + + /// Disable experimental support for the QUIC protocol. This option is provided in case a + /// critical bug is found in the QUIC implementation and we need to urgently shut down the + /// UDP socket. + /// This option will be removed in the future. + #[structopt(long)] + pub disable_quic: bool, } impl NetworkParams { @@ -121,6 +132,7 @@ impl NetworkParams { node_key: NodeKeyConfig, ) -> NetworkConfiguration { let port = self.port.unwrap_or(30333); + let quic_port = self.quic_port.unwrap_or(30333); let listen_addresses = if self.listen_addr.is_empty() { vec![ @@ -166,6 +178,11 @@ impl NetworkParams { max_parallel_downloads: self.max_parallel_downloads, allow_non_globals_in_dht: self.discover_local || is_dev, use_new_block_requests_protocol: !self.legacy_network_protocol, + quic_socket: if self.disable_quic { + None + } else { + Some(From::from(([0, 0, 0, 0], quic_port))) + }, } } } diff --git a/client/network-gossip/Cargo.toml b/client/network-gossip/Cargo.toml index 334a85035f2af..d55964829441d 100644 --- a/client/network-gossip/Cargo.toml +++ b/client/network-gossip/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] futures = "0.3.4" futures-timer = "3.0.1" -libp2p = { version = "0.19.1", default-features = false } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false } log = "0.4.8" lru = "0.4.3" sc-network = { version = "0.8.0-rc3", path = "../network" } diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index 94a7b2b57dca3..4a02b96144837 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -18,6 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"] prost-build = "0.6.1" [dependencies] +async-std = "1.5" # TODO: remove, quick hack bitflags = "1.2.0" bs58 = "0.3.1" bytes = "0.5.0" @@ -63,15 +64,16 @@ wasm-timer = "0.2" zeroize = "1.0.0" [dependencies.libp2p] -version = "0.19.1" +git = "https://github.com/tomaka/libp2p-rs" +branch = "quiccc-again" default-features = false -features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "tcp-async-std", "websocket", "yamux"] +features = ["identify", "kad", "mdns", "mplex", "noise", "ping", "quic", "tcp-async-std", "websocket", "yamux"] [dev-dependencies] async-std = "1.5" assert_matches = "1.3" env_logger = "0.7.0" -libp2p = { version = "0.19.1", default-features = false, features = ["secio"] } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false, features = ["secio"] } quickcheck = "0.9.0" rand = "0.7.2" sp-keyring = { version = "2.0.0-rc3", path = "../../primitives/keyring" } diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 6c9bd3adb9fd7..786e3b7ec7278 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -46,7 +46,7 @@ use std::{ error::Error, fs, io::{self, Write}, - net::Ipv4Addr, + net::{Ipv4Addr, SocketAddr}, path::{Path, PathBuf}, sync::Arc, }; @@ -428,6 +428,11 @@ pub struct NetworkConfiguration { /// If true, uses the `//block-requests/` experimental protocol rather than /// the legacy substream. This option is meant to be hard-wired to `true` in the future. pub use_new_block_requests_protocol: bool, + /// If `Some`, open a UDP socket dedicated to QUIC connections using the given address. This + /// UDP socket is necessary for both incoming and outgoing QUIC connections. Incoming + /// connections won't be accepted unless a QUIC `Multiaddr` is passed as part of + /// `listen_addresses`. + pub quic_socket: Option, } impl NetworkConfiguration { @@ -460,6 +465,7 @@ impl NetworkConfiguration { max_parallel_downloads: 5, allow_non_globals_in_dht: false, use_new_block_requests_protocol: true, + quic_socket: Some(From::from(([0, 0, 0, 0], 30333))), } } } diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index 73e0b525a105d..24fa4c466b3c2 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -72,6 +72,7 @@ //! As of the writing of this documentation, the following base-layer protocols are supported by //! Substrate: //! +//! - QUIC for addresses of the form `/ip4/1.2.3.4/udp/5/quic`. //! - TCP/IP for addresses of the form `/ip4/1.2.3.4/tcp/5`. Once the TCP connection is open, an //! encryption and a multiplexing layer are negotiated on top. //! - WebSockets for addresses of the form `/ip4/1.2.3.4/tcp/5/ws`. A TCP/IP connection is open and @@ -81,10 +82,10 @@ //! node's address can contain a domain name. //! - (All of the above using IPv6 instead of IPv4.) //! -//! On top of the base-layer protocol, the [Noise](https://noiseprotocol.org/) protocol is -//! negotiated and applied. The exact handshake protocol is experimental and is subject to change. +//! With the exception of QUIC, the libp2p-compliant [Noise](https://noiseprotocol.org/) protocol +//! is negotiated and applied on top of the base-layer protocol. //! -//! The following multiplexing protocols are supported: +//! On top of the Noise protocol, the following multiplexing protocols are supported: //! //! - [Mplex](https://github.com/libp2p/specs/tree/master/mplex). Support for mplex will likely //! be deprecated in the future. diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 2297fe6a52f72..109b6595cc840 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -294,7 +294,13 @@ impl NetworkWorker { TransportConfig::Normal { wasm_external_transport, use_yamux_flow_control, .. } => (false, wasm_external_transport, use_yamux_flow_control) }; - transport::build_transport(local_identity, config_mem, config_wasm, flowctrl) + transport::build_transport( + local_identity, + config_mem, + config_wasm, + flowctrl, + params.network_config.quic_socket + ) }; let mut builder = SwarmBuilder::new(transport, behaviour, local_peer_id.clone()) .peer_connection_limit(crate::MAX_CONNECTIONS_PER_PEER) diff --git a/client/network/src/transport.rs b/client/network/src/transport.rs index 0c9a809384e4c..ea385b76f7988 100644 --- a/client/network/src/transport.rs +++ b/client/network/src/transport.rs @@ -26,8 +26,8 @@ use libp2p::{ mplex, identity, bandwidth, wasm_ext, noise }; #[cfg(not(target_os = "unknown"))] -use libp2p::{tcp, dns, websocket}; -use std::{io, sync::Arc, time::Duration, usize}; +use libp2p::{tcp, quic, dns, websocket}; +use std::{io, net::SocketAddr, sync::Arc, time::Duration, usize}; pub use self::bandwidth::BandwidthSinks; @@ -42,7 +42,8 @@ pub fn build_transport( keypair: identity::Keypair, memory_only: bool, wasm_external_transport: Option, - use_yamux_flow_control: bool + use_yamux_flow_control: bool, + quic_socket: Option, ) -> (Boxed<(PeerId, StreamMuxerBox), io::Error>, Arc) { // Build configuration objects for encryption mechanisms. let noise_config = { @@ -106,6 +107,24 @@ pub fn build_transport( let (transport, sinks) = bandwidth::BandwidthLogging::new(transport, Duration::from_secs(5)); + let quic = if let Some(quic_socket) = quic_socket { + let addr = libp2p::Multiaddr::empty() + .with(quic_socket.ip().into()) + .with(libp2p::multiaddr::Protocol::Udp(quic_socket.port())) + .with(libp2p::multiaddr::Protocol::Quic); + + match quic::Endpoint::new(quic::Config::new(&keypair, addr).unwrap()) { + Ok(q) => OptionalTransport::some(quic::QuicTransport(q)), + Err(err) => { + log::error!("Failed to start QUIC endpoint: {}", err); + OptionalTransport::none() + } + } + + } else { + OptionalTransport::none() + }; + // Encryption let transport = transport.and_then(move |stream, endpoint| { core::upgrade::apply(stream, noise_config, endpoint, upgrade::Version::V1) @@ -137,13 +156,21 @@ pub fn build_transport( .map_outbound(move |muxer| (peer_id2, muxer)); core::upgrade::apply(stream, upgrade, endpoint, upgrade::Version::V1) - .map_ok(|(id, muxer)| (id, core::muxing::StreamMuxerBox::new(muxer))) }); + + // TODO: add bandwidth measurement to QUIC as well + let transport = transport.or_transport(quic).map(move |out, _| { + match out { + libp2p::core::either::EitherOutput::First((peer_id, muxer)) => (peer_id, core::muxing::StreamMuxerBox::new(muxer)), + libp2p::core::either::EitherOutput::Second((peer_id, muxer)) => (peer_id, core::muxing::StreamMuxerBox::new(muxer)), + } + }); + let transport = transport - .timeout(Duration::from_secs(20)) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err)) - .boxed(); + .timeout(Duration::from_secs(20)) + .map_err(|err| io::Error::new(io::ErrorKind::Other, err)) + .boxed(); (transport, sinks) } diff --git a/client/network/test/Cargo.toml b/client/network/test/Cargo.toml index 27acabbb220e5..307ec6610107f 100644 --- a/client/network/test/Cargo.toml +++ b/client/network/test/Cargo.toml @@ -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.19.1", default-features = false } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false } sp-consensus = { version = "0.8.0-rc3", path = "../../../primitives/consensus/common" } sc-consensus = { version = "0.8.0-rc3", path = "../../../client/consensus/common" } sc-client-api = { version = "2.0.0-rc3", path = "../../api" } diff --git a/client/peerset/Cargo.toml b/client/peerset/Cargo.toml index 205260ad725ff..b148a1fa60713 100644 --- a/client/peerset/Cargo.toml +++ b/client/peerset/Cargo.toml @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] futures = "0.3.4" -libp2p = { version = "0.19.1", default-features = false } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false } sp-utils = { version = "2.0.0-rc3", path = "../../primitives/utils"} log = "0.4.8" serde_json = "1.0.41" diff --git a/client/telemetry/Cargo.toml b/client/telemetry/Cargo.toml index 13a1c81d15236..2c94cb945179f 100644 --- a/client/telemetry/Cargo.toml +++ b/client/telemetry/Cargo.toml @@ -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.19.1", default-features = false, features = ["dns", "tcp-async-std", "wasm-ext", "websocket"] } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false, features = ["dns", "tcp-async-std", "wasm-ext", "websocket"] } log = "0.4.8" pin-project = "0.4.6" rand = "0.7.2" diff --git a/primitives/consensus/common/Cargo.toml b/primitives/consensus/common/Cargo.toml index 3f256d3f736ce..5006f49f85cc9 100644 --- a/primitives/consensus/common/Cargo.toml +++ b/primitives/consensus/common/Cargo.toml @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] derive_more = "0.99.2" -libp2p = { version = "0.19.1", default-features = false } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", default-features = false } log = "0.4.8" sp-core = { path= "../../core", version = "2.0.0-rc3"} sp-inherents = { version = "2.0.0-rc3", path = "../../inherents" } diff --git a/primitives/npos-elections/fuzzer/Cargo.lock b/primitives/npos-elections/fuzzer/Cargo.lock index cd172421aeb28..63080da1660bf 100644 --- a/primitives/npos-elections/fuzzer/Cargo.lock +++ b/primitives/npos-elections/fuzzer/Cargo.lock @@ -540,7 +540,7 @@ dependencies = [ [[package]] name = "memory-db" -version = "0.19.1" +git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "198831fe8722331a395bc199a5d08efbc197497ef354cb4c77b969c02ffc0fc4" dependencies = [ diff --git a/utils/browser/Cargo.toml b/utils/browser/Cargo.toml index ee4634f0d1cd8..eb6203fb9c31d 100644 --- a/utils/browser/Cargo.toml +++ b/utils/browser/Cargo.toml @@ -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.19.0", features = ["websocket"] } +libp2p-wasm-ext = { git = "https://github.com/tomaka/libp2p-rs", branch = "quiccc-again", features = ["websocket"] } console_error_panic_hook = "0.1.6" console_log = "0.1.2" js-sys = "0.3.34" From 21b5efb64efeea3afa6b10137788537a71b19070 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 22 Jun 2020 17:17:05 +0200 Subject: [PATCH 2/2] Fix bad merge --- client/network/src/config.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 16f25d2c80b56..ed05f2e5e972b 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -461,11 +461,7 @@ impl NetworkConfiguration { }, max_parallel_downloads: 5, allow_non_globals_in_dht: false, -<<<<<<< HEAD - use_new_block_requests_protocol: true, quic_socket: Some(From::from(([0, 0, 0, 0], 30333))), -======= ->>>>>>> upstream/master } } }