From 6396901481c358a6e04d1bdc382c4a68e0a54f06 Mon Sep 17 00:00:00 2001 From: Pierre Krieger <pierre.krieger1708@gmail.com> Date: Thu, 8 Aug 2019 09:32:07 +0200 Subject: [PATCH] Reintroduce mplex (reverts #3312) (#3328) This reverts commit f11291cd9a89cc1799815e675d817d85fe561aec. --- substrate/core/network/src/lib.rs | 2 ++ substrate/core/network/src/transport.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/substrate/core/network/src/lib.rs b/substrate/core/network/src/lib.rs index 33f9e5d2eb8..e5714c66f20 100644 --- a/substrate/core/network/src/lib.rs +++ b/substrate/core/network/src/lib.rs @@ -89,6 +89,8 @@ //! //! 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. //! - [Yamux](https://github.com/hashicorp/yamux/blob/master/spec.md). //! //! ## Substreams diff --git a/substrate/core/network/src/transport.rs b/substrate/core/network/src/transport.rs index 389a6626610..901ec18581e 100644 --- a/substrate/core/network/src/transport.rs +++ b/substrate/core/network/src/transport.rs @@ -17,14 +17,14 @@ use futures::prelude::*; use libp2p::{ InboundUpgradeExt, OutboundUpgradeExt, PeerId, Transport, - identity, secio, yamux, bandwidth, wasm_ext + mplex, identity, secio, yamux, bandwidth, wasm_ext }; #[cfg(not(target_os = "unknown"))] use libp2p::{tcp, dns, websocket, noise}; #[cfg(not(target_os = "unknown"))] use libp2p::core::{upgrade, either::EitherError, either::EitherOutput}; use libp2p::core::{self, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox}; -use std::{io, sync::Arc, time::Duration}; +use std::{io, sync::Arc, time::Duration, usize}; pub use self::bandwidth::BandwidthSinks; @@ -55,6 +55,9 @@ pub fn build_transport( let secio_config = secio::SecioConfig::new(keypair); // Build configuration objects for multiplexing mechanisms. + let mut mplex_config = mplex::MplexConfig::new(); + mplex_config.max_buffer_len_behaviour(mplex::MaxBufferBehaviour::Block); + mplex_config.max_buffer_len(usize::MAX); let yamux_config = yamux::Config::default(); // Build the base layer of the transport. @@ -113,7 +116,7 @@ pub fn build_transport( // Multiplexing let transport = transport.and_then(move |(stream, peer_id), endpoint| { let peer_id2 = peer_id.clone(); - let upgrade = yamux_config + let upgrade = core::upgrade::SelectUpgrade::new(yamux_config, mplex_config) .map_inbound(move |muxer| (peer_id, muxer)) .map_outbound(move |muxer| (peer_id2, muxer)); -- GitLab