From 625918394a355c8038b102f79ae61b4e8f76aa60 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 20 Jul 2018 00:44:21 +0200 Subject: [PATCH] Introduce support for yamux (#388) --- substrate/Cargo.lock | 6 +++--- substrate/substrate/network-libp2p/src/transport.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 7be42d10ab..45ac69ea90 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -2228,7 +2228,7 @@ dependencies = [ "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2713,7 +2713,7 @@ dependencies = [ "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3860,7 +3860,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "yamux" version = "0.1.0" -source = "git+https://github.com/paritytech/yamux#b2104369a4f676e11d1fc86cfc33e9a68d21c4f3" +source = "git+https://github.com/paritytech/yamux#99a40f41824e33ed52d94659f7c05feb324411fa" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/substrate/network-libp2p/src/transport.rs b/substrate/substrate/network-libp2p/src/transport.rs index 9dc084a681..82b7a9a5fc 100644 --- a/substrate/substrate/network-libp2p/src/transport.rs +++ b/substrate/substrate/network-libp2p/src/transport.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see .? -use libp2p::{self, Transport, secio}; +use libp2p::{self, Transport, mplex, secio, yamux}; use libp2p::core::{MuxedTransport, either, upgrade}; use libp2p::transport_timeout::TransportTimeout; use std::time::Duration; @@ -52,7 +52,11 @@ pub fn build_transport( }) // TODO: check that the public key matches what is reported by identify .map(|(socket, _key), _| socket) - .with_upgrade(libp2p::mplex::MultiplexConfig::new()) + // TODO: this `EitherOutput` thing shows that libp2p's API could be improved + .with_upgrade(upgrade::or( + upgrade::map(mplex::MultiplexConfig::new(), either::EitherOutput::First), + upgrade::map(yamux::Config::default(), either::EitherOutput::Second), + )) .into_connection_reuse(); TransportTimeout::new(base, Duration::from_secs(20))