diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index a7e24f5d616..40847d703f5 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -12,6 +12,11 @@ - Improve error messages in case keys cannot be decoded because of missing feature flags. See [PR 2972]. +- Add `Transport::box_multiplexed` implementation for boxing multiplexed transports into the + `Boxed<(PeerId, StreamMuxerBox)>` type used with the swarm. + Deprecate `Multiplexed::boxed` in favor of `box_multiplexed`. See [PR 3313]. + +[PR 3313]: https://github.com/libp2p/rust-libp2p/pull/3313 [PR 3031]: https://github.com/libp2p/rust-libp2p/pull/3031 [PR 3058]: https://github.com/libp2p/rust-libp2p/pull/3058 [PR 3097]: https://github.com/libp2p/rust-libp2p/pull/3097 diff --git a/core/src/either.rs b/core/src/either.rs index a34552bf28f..2a947059663 100644 --- a/core/src/either.rs +++ b/core/src/either.rs @@ -255,6 +255,24 @@ where } } +impl From> for (T, EitherOutput) { + fn from(either_output: EitherOutput<(T, A), (T, B)>) -> Self { + match either_output { + EitherOutput::First((t, a)) => (t, EitherOutput::First(a)), + EitherOutput::Second((t, b)) => (t, EitherOutput::Second(b)), + } + } +} + +impl From> for (EitherOutput, T) { + fn from(either_output: EitherOutput<(A, T), (B, T)>) -> Self { + match either_output { + EitherOutput::First((a, t)) => (EitherOutput::First(a), t), + EitherOutput::Second((b, t)) => (EitherOutput::Second(b), t), + } + } +} + /// Implements `Future` and dispatches all method calls to either `First` or `Second`. #[pin_project(project = EitherFutureProj)] #[derive(Debug, Copy, Clone)] diff --git a/core/src/transport.rs b/core/src/transport.rs index 04196efca13..b0f7b4d17bb 100644 --- a/core/src/transport.rs +++ b/core/src/transport.rs @@ -46,8 +46,9 @@ pub mod upgrade; mod boxed; mod optional; -use crate::ConnectedPoint; +use crate::{muxing::StreamMuxerBox, ConnectedPoint, PeerId, StreamMuxer}; +use self::boxed::boxed; pub use self::boxed::Boxed; pub use self::choice::OrTransport; pub use self::memory::MemoryTransport; @@ -236,6 +237,25 @@ pub trait Transport { { upgrade::Builder::new(self, version) } + + /// Box a multiplexed transport, including the inner muxer + /// and all errors. + fn box_multiplexed(self) -> Boxed<(PeerId, StreamMuxerBox)> + where + Self: Sized + Send + Unpin + 'static, + Self::Dial: Send + 'static, + Self::ListenerUpgrade: Send + 'static, + Self::Error: Send + Sync, + Self::Output: Into<(PeerId, M)>, + M: StreamMuxer + Send + 'static, + M::Substream: Send + 'static, + M::Error: Send + Sync + 'static, + { + boxed(self.map(|o, _| { + let (i, m) = o.into(); + (i, StreamMuxerBox::new(m)) + })) + } } /// The ID of a single listener. diff --git a/core/src/transport/upgrade.rs b/core/src/transport/upgrade.rs index 4f28296065b..e7252767d20 100644 --- a/core/src/transport/upgrade.rs +++ b/core/src/transport/upgrade.rs @@ -26,8 +26,8 @@ use crate::{ connection::ConnectedPoint, muxing::{StreamMuxer, StreamMuxerBox}, transport::{ - and_then::AndThen, boxed::boxed, timeout::TransportTimeout, ListenerId, Transport, - TransportError, TransportEvent, + and_then::AndThen, timeout::TransportTimeout, ListenerId, Transport, TransportError, + TransportEvent, }, upgrade::{ self, apply_inbound, apply_outbound, InboundUpgrade, InboundUpgradeApply, OutboundUpgrade, @@ -293,6 +293,7 @@ pub struct Multiplexed(#[pin] T); impl Multiplexed { /// Boxes the authenticated, multiplexed transport, including /// the [`StreamMuxer`] and custom transport errors. + #[deprecated(since = "0.39.0", note = "Use `Transport::box_multiplexed` instead.")] pub fn boxed(self) -> super::Boxed<(PeerId, StreamMuxerBox)> where T: Transport + Sized + Send + Unpin + 'static, @@ -303,7 +304,7 @@ impl Multiplexed { M::Substream: Send + 'static, M::Error: Send + Sync + 'static, { - boxed(self.map(|(i, m), _| (i, StreamMuxerBox::new(m)))) + self.box_multiplexed() } /// Adds a timeout to the setup and protocol upgrade process for all diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs index dac84534369..75c793a743d 100644 --- a/core/tests/transport_upgrade.rs +++ b/core/tests/transport_upgrade.rs @@ -86,7 +86,7 @@ fn upgrade_pipeline() { .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) .multiplex(MplexConfig::default()) - .boxed(); + .box_multiplexed(); let dialer_keys = identity::Keypair::generate_ed25519(); let dialer_id = dialer_keys.public().to_peer_id(); @@ -97,7 +97,7 @@ fn upgrade_pipeline() { .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) .multiplex(MplexConfig::default()) - .boxed(); + .box_multiplexed(); let listen_addr1 = Multiaddr::from(Protocol::Memory(random::())); let listen_addr2 = listen_addr1.clone(); diff --git a/examples/chat-tokio.rs b/examples/chat-tokio.rs index e2f88201fb8..d345850d118 100644 --- a/examples/chat-tokio.rs +++ b/examples/chat-tokio.rs @@ -58,7 +58,7 @@ async fn main() -> Result<(), Box> { .expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(mplex::MplexConfig::new()) - .boxed(); + .box_multiplexed(); // Create a Floodsub topic let floodsub_topic = floodsub::Topic::new("chat"); diff --git a/examples/ipfs-private.rs b/examples/ipfs-private.rs index db3907f4496..4c1730112f6 100644 --- a/examples/ipfs-private.rs +++ b/examples/ipfs-private.rs @@ -69,7 +69,7 @@ pub fn build_transport( .authenticate(noise_config) .multiplex(yamux_config) .timeout(Duration::from_secs(20)) - .boxed() + .box_multiplexed() } /// Get the current ipfs repo path, either from the IPFS_PATH environment variable or diff --git a/misc/metrics/examples/metrics/main.rs b/misc/metrics/examples/metrics/main.rs index 22c3bd2f0a1..f880414959b 100644 --- a/misc/metrics/examples/metrics/main.rs +++ b/misc/metrics/examples/metrics/main.rs @@ -82,7 +82,7 @@ fn main() -> Result<(), Box> { .upgrade(Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) .multiplex(yamux::YamuxConfig::default()) - .boxed(), + .box_multiplexed(), Behaviour::new(local_pub_key), local_peer_id, ); diff --git a/misc/multistream-select/tests/transport.rs b/misc/multistream-select/tests/transport.rs index 77fcc1ca4ca..05d9fc84e91 100644 --- a/misc/multistream-select/tests/transport.rs +++ b/misc/multistream-select/tests/transport.rs @@ -45,7 +45,7 @@ fn mk_transport(up: upgrade::Version) -> (PeerId, TestTransport) { local_public_key: keys.public(), }) .multiplex(MplexConfig::default()) - .boxed(), + .box_multiplexed(), ) } diff --git a/muxers/mplex/benches/split_send_size.rs b/muxers/mplex/benches/split_send_size.rs index 65cc76eed08..9bb23573c09 100644 --- a/muxers/mplex/benches/split_send_size.rs +++ b/muxers/mplex/benches/split_send_size.rs @@ -174,7 +174,7 @@ fn tcp_transport(split_send_size: usize) -> BenchTransport { .authenticate(PlainText2Config { local_public_key }) .multiplex(mplex) .timeout(Duration::from_secs(5)) - .boxed() + .box_multiplexed() } fn mem_transport(split_send_size: usize) -> BenchTransport { @@ -189,7 +189,7 @@ fn mem_transport(split_send_size: usize) -> BenchTransport { .authenticate(PlainText2Config { local_public_key }) .multiplex(mplex) .timeout(Duration::from_secs(5)) - .boxed() + .box_multiplexed() } criterion_group!(split_send_size, prepare); diff --git a/protocols/autonat/examples/autonat_client.rs b/protocols/autonat/examples/autonat_client.rs index d2a7b2dee2f..042563f3af3 100644 --- a/protocols/autonat/examples/autonat_client.rs +++ b/protocols/autonat/examples/autonat_client.rs @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box> { .upgrade(Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour::new(local_key.public()); diff --git a/protocols/autonat/examples/autonat_server.rs b/protocols/autonat/examples/autonat_server.rs index 8163826c830..8ffade7584e 100644 --- a/protocols/autonat/examples/autonat_server.rs +++ b/protocols/autonat/examples/autonat_server.rs @@ -59,7 +59,7 @@ async fn main() -> Result<(), Box> { .upgrade(Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour::new(local_key.public()); diff --git a/protocols/autonat/tests/test_client.rs b/protocols/autonat/tests/test_client.rs index 8006d3dbd76..22d0402f840 100644 --- a/protocols/autonat/tests/test_client.rs +++ b/protocols/autonat/tests/test_client.rs @@ -41,7 +41,7 @@ async fn init_swarm(config: Config) -> Swarm { .upgrade(Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour::new(local_id, config); Swarm::with_async_std_executor(transport, behaviour, local_id) } diff --git a/protocols/autonat/tests/test_server.rs b/protocols/autonat/tests/test_server.rs index 44ad7fdfba8..12dde2f62f8 100644 --- a/protocols/autonat/tests/test_server.rs +++ b/protocols/autonat/tests/test_server.rs @@ -41,7 +41,7 @@ async fn init_swarm(config: Config) -> Swarm { .upgrade(Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour::new(local_id, config); Swarm::with_async_std_executor(transport, behaviour, local_id) } diff --git a/protocols/dcutr/examples/dcutr.rs b/protocols/dcutr/examples/dcutr.rs index 63a55c0dc2f..d996adf8e6e 100644 --- a/protocols/dcutr/examples/dcutr.rs +++ b/protocols/dcutr/examples/dcutr.rs @@ -102,7 +102,7 @@ fn main() -> Result<(), Box> { .expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); #[derive(NetworkBehaviour)] #[behaviour( diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index 7119b0899c2..0d4d3fba58a 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -142,7 +142,7 @@ where .upgrade(Version::V1) .authenticate(PlainText2Config { local_public_key }) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed() + .box_multiplexed() } #[derive(NetworkBehaviour)] diff --git a/protocols/gossipsub/src/lib.rs b/protocols/gossipsub/src/lib.rs index ad2c1f1fbf0..59ddbd8b0ea 100644 --- a/protocols/gossipsub/src/lib.rs +++ b/protocols/gossipsub/src/lib.rs @@ -103,7 +103,7 @@ //! .upgrade(libp2p_core::upgrade::Version::V1) //! .authenticate(libp2p_noise::NoiseAuthenticated::xx(&local_key).unwrap()) //! .multiplex(libp2p_mplex::MplexConfig::new()) -//! .boxed(); +//! .box_multiplexed(); //! //! // Create a Gossipsub topic //! let topic = libp2p_gossipsub::IdentTopic::new("example"); diff --git a/protocols/gossipsub/tests/smoke.rs b/protocols/gossipsub/tests/smoke.rs index 40605d2aab8..652d682f640 100644 --- a/protocols/gossipsub/tests/smoke.rs +++ b/protocols/gossipsub/tests/smoke.rs @@ -153,7 +153,7 @@ fn build_node() -> (Multiaddr, Swarm) { local_public_key: public_key.clone(), }) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let peer_id = public_key.to_peer_id(); diff --git a/protocols/identify/examples/identify.rs b/protocols/identify/examples/identify.rs index 12fe084a989..a1787cd8953 100644 --- a/protocols/identify/examples/identify.rs +++ b/protocols/identify/examples/identify.rs @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box> { .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&local_key).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); // Create a identify network behaviour. let behaviour = identify::Behaviour::new(identify::Config::new( diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 123c8140ecd..d4c200d494c 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -545,7 +545,7 @@ mod tests { .upgrade(upgrade::Version::V1) .authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated()) .multiplex(MplexConfig::new()) - .boxed(); + .box_multiplexed(); (pubkey, transport) } diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index bf3bd7cf17a..313f253917b 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -60,7 +60,7 @@ fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) { .upgrade(upgrade::Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap()) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let local_id = local_public_key.to_peer_id(); let store = MemoryStore::new(local_id); diff --git a/protocols/mdns/tests/use-async-std.rs b/protocols/mdns/tests/use-async-std.rs index e12eeb09299..946086677ef 100644 --- a/protocols/mdns/tests/use-async-std.rs +++ b/protocols/mdns/tests/use-async-std.rs @@ -62,7 +62,7 @@ async fn create_swarm(config: Config) -> Result, Box .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&id_keys).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour::new(config, peer_id)?; let mut swarm = Swarm::with_async_std_executor(transport, behaviour, peer_id); swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; diff --git a/protocols/mdns/tests/use-tokio.rs b/protocols/mdns/tests/use-tokio.rs index 77deae55412..30e77e847e4 100644 --- a/protocols/mdns/tests/use-tokio.rs +++ b/protocols/mdns/tests/use-tokio.rs @@ -58,7 +58,7 @@ async fn create_swarm(config: Config) -> Result, Box .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&id_keys).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour::new(config, peer_id)?; let mut swarm = Swarm::with_tokio_executor(transport, behaviour, peer_id); swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?; diff --git a/protocols/ping/tests/ping.rs b/protocols/ping/tests/ping.rs index c4eaea4ecba..56b9857312e 100644 --- a/protocols/ping/tests/ping.rs +++ b/protocols/ping/tests/ping.rs @@ -254,7 +254,7 @@ fn mk_transport(muxer: MuxerChoice) -> (PeerId, transport::Boxed<(PeerId, Stream MuxerChoice::Yamux => upgrade::EitherUpgrade::A(yamux::YamuxConfig::default()), MuxerChoice::Mplex => upgrade::EitherUpgrade::B(mplex::MplexConfig::default()), }) - .boxed(), + .box_multiplexed(), ) } diff --git a/protocols/relay/examples/relay.rs b/protocols/relay/examples/relay.rs index 5d88f1739df..d39a23e7502 100644 --- a/protocols/relay/examples/relay.rs +++ b/protocols/relay/examples/relay.rs @@ -54,7 +54,7 @@ fn main() -> Result<(), Box> { .expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = Behaviour { relay: relay::Behaviour::new(local_peer_id, Default::default()), diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index a26d09e6e3b..02a4eff45c2 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -338,7 +338,7 @@ where .upgrade(upgrade::Version::V1) .authenticate(PlainText2Config { local_public_key }) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed() + .box_multiplexed() } #[derive(NetworkBehaviour)] diff --git a/protocols/rendezvous/examples/discover.rs b/protocols/rendezvous/examples/discover.rs index 274432bc2d3..e6dc4f7afbc 100644 --- a/protocols/rendezvous/examples/discover.rs +++ b/protocols/rendezvous/examples/discover.rs @@ -43,7 +43,7 @@ async fn main() { .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(), + .box_multiplexed(), MyBehaviour { rendezvous: rendezvous::client::Behaviour::new(identity.clone()), ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))), diff --git a/protocols/rendezvous/examples/register.rs b/protocols/rendezvous/examples/register.rs index 98060c5cd96..b5cbd9eeb99 100644 --- a/protocols/rendezvous/examples/register.rs +++ b/protocols/rendezvous/examples/register.rs @@ -42,7 +42,7 @@ async fn main() { .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(), + .box_multiplexed(), MyBehaviour { rendezvous: rendezvous::client::Behaviour::new(identity.clone()), ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))), diff --git a/protocols/rendezvous/examples/register_with_identify.rs b/protocols/rendezvous/examples/register_with_identify.rs index 8e0fac23a85..a721516ad20 100644 --- a/protocols/rendezvous/examples/register_with_identify.rs +++ b/protocols/rendezvous/examples/register_with_identify.rs @@ -43,7 +43,7 @@ async fn main() { .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(), + .box_multiplexed(), MyBehaviour { identify: identify::Behaviour::new(identify::Config::new( "rendezvous-example/1.0.0".to_string(), diff --git a/protocols/rendezvous/examples/rendezvous_point.rs b/protocols/rendezvous/examples/rendezvous_point.rs index 49680bfd940..97e914cd3a1 100644 --- a/protocols/rendezvous/examples/rendezvous_point.rs +++ b/protocols/rendezvous/examples/rendezvous_point.rs @@ -47,7 +47,7 @@ async fn main() { .upgrade(Version::V1) .authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(), + .box_multiplexed(), MyBehaviour { identify: identify::Behaviour::new(identify::Config::new( "rendezvous-example/1.0.0".to_string(), diff --git a/protocols/rendezvous/tests/harness.rs b/protocols/rendezvous/tests/harness.rs index 460df22b812..0397b5d3ce3 100644 --- a/protocols/rendezvous/tests/harness.rs +++ b/protocols/rendezvous/tests/harness.rs @@ -51,7 +51,7 @@ where MplexConfig::new(), )) .timeout(Duration::from_secs(5)) - .boxed(); + .box_multiplexed(); Swarm::with_tokio_executor(transport, behaviour_fn(peer_id, identity), peer_id) } diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index 9837f6d6ec6..0f9ee70fc29 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -302,7 +302,7 @@ fn mk_transport() -> (PeerId, transport::Boxed<(PeerId, StreamMuxerBox)>) { .upgrade(upgrade::Version::V1) .authenticate(NoiseAuthenticated::xx(&id_keys).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(), + .box_multiplexed(), ) } diff --git a/src/lib.rs b/src/lib.rs index e87a5f746da..18b75b473d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -211,7 +211,7 @@ pub async fn development_transport( mplex::MplexConfig::default(), )) .timeout(std::time::Duration::from_secs(20)) - .boxed()) + .box_multiplexed()) } /// Builds a `Transport` based on TCP/IP that supports the most commonly-used features of libp2p: @@ -267,5 +267,5 @@ pub fn tokio_development_transport( mplex::MplexConfig::default(), )) .timeout(std::time::Duration::from_secs(20)) - .boxed()) + .box_multiplexed()) } diff --git a/src/transport_ext.rs b/src/transport_ext.rs index 2a4c30f17e3..696d8e054f8 100644 --- a/src/transport_ext.rs +++ b/src/transport_ext.rs @@ -62,7 +62,7 @@ pub trait TransportExt: Transport { /// .expect("Signing libp2p-noise static DH keypair failed."), /// ) /// .multiplex(mplex::MplexConfig::new()) - /// .boxed(); + /// .box_multiplexed(); /// /// let (transport, sinks) = transport.with_bandwidth_logging(); /// ``` diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 6fc494b1578..29ace75a734 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -285,7 +285,7 @@ pub enum NetworkBehaviourAction< /// # .upgrade(upgrade::Version::V1) /// # .authenticate(PlainText2Config { local_public_key }) /// # .multiplex(yamux::YamuxConfig::default()) - /// # .boxed(); + /// # .box_multiplexed(); /// # /// # let mut swarm = Swarm::with_threadpool_executor(transport, MyBehaviour::default(), local_peer_id); /// # diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index cf0b4c3b08a..7406f35b378 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1789,7 +1789,7 @@ mod tests { local_public_key: local_public_key.clone(), }) .multiplex(yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); let behaviour = CallTraceBehaviour::new(MockBehaviour::new(handler_proto)); match ThreadPool::new().ok() { Some(tp) => { diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index a147864528c..bad1fc09c45 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -4,7 +4,6 @@ use futures::channel::{mpsc, oneshot}; use futures::future::{poll_fn, Either}; use futures::stream::StreamExt; use futures::{future, AsyncReadExt, AsyncWriteExt, FutureExt, SinkExt}; -use libp2p_core::either::EitherOutput; use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt, SubstreamBox}; use libp2p_core::transport::{Boxed, OrTransport, TransportEvent}; use libp2p_core::{multiaddr::Protocol, upgrade, Multiaddr, PeerId, Transport}; @@ -129,12 +128,7 @@ fn new_tcp_quic_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { ) .multiplex(yamux::YamuxConfig::default()); - let transport = OrTransport::new(quic_transport, tcp_transport) - .map(|either_output, _| match either_output { - EitherOutput::First((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)), - EitherOutput::Second((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)), - }) - .boxed(); + let transport = OrTransport::new(quic_transport, tcp_transport).box_multiplexed(); (peer_id, transport) } @@ -394,9 +388,7 @@ fn create_transport( let peer_id = keypair.public().to_peer_id(); let mut config = quic::Config::new(&keypair); with_config(&mut config); - let transport = quic::GenTransport::

::new(config) - .map(|(p, c), _| (p, StreamMuxerBox::new(c))) - .boxed(); + let transport = quic::GenTransport::

::new(config).box_multiplexed(); (peer_id, transport) } diff --git a/transports/tls/tests/smoke.rs b/transports/tls/tests/smoke.rs index 37be61c0caf..1ba52ae55b0 100644 --- a/transports/tls/tests/smoke.rs +++ b/transports/tls/tests/smoke.rs @@ -62,7 +62,7 @@ fn make_swarm() -> Swarm { .upgrade(Version::V1) .authenticate(libp2p_tls::Config::new(&identity).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) - .boxed(); + .box_multiplexed(); Swarm::without_executor( transport, diff --git a/transports/webrtc/examples/listen_ping.rs b/transports/webrtc/examples/listen_ping.rs index b6cf16e693e..b97a1370c25 100644 --- a/transports/webrtc/examples/listen_ping.rs +++ b/transports/webrtc/examples/listen_ping.rs @@ -1,7 +1,6 @@ use anyhow::Result; use futures::StreamExt; use libp2p_core::identity; -use libp2p_core::muxing::StreamMuxerBox; use libp2p_core::Transport; use libp2p_ping as ping; use libp2p_swarm::{keep_alive, NetworkBehaviour, Swarm}; @@ -29,12 +28,8 @@ fn create_swarm() -> Result> { libp2p_webrtc::tokio::Certificate::generate(&mut thread_rng())?, ); - let transport = transport - .map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn))) - .boxed(); - Ok(Swarm::with_tokio_executor( - transport, + transport.box_multiplexed(), Behaviour::default(), peer_id, )) diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index 26779d13ce9..2faf09356ca 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -73,8 +73,7 @@ fn create_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { keypair, webrtc::tokio::Certificate::generate(&mut thread_rng()).unwrap(), ) - .map(|(p, c), _| (p, StreamMuxerBox::new(c))) - .boxed(); + .box_multiplexed(); (peer_id, transport) }