From dede7b38f9c7a308b36a1078957e5d7dcd6a5cf7 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Fri, 11 Jun 2021 16:00:17 +1000 Subject: [PATCH] mplex --- libp2p-tor/Cargo.toml | 2 +- libp2p-tor/examples/dialer.rs | 13 ++++++++++--- libp2p-tor/examples/listener.rs | 8 ++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libp2p-tor/Cargo.toml b/libp2p-tor/Cargo.toml index b31a5334..86c3777c 100644 --- a/libp2p-tor/Cargo.toml +++ b/libp2p-tor/Cargo.toml @@ -19,7 +19,7 @@ torut = { version = "0.1", default-features = false, features = [ "v3", "control tracing = "0.1" [dev-dependencies] -libp2p = { version = "0.37", default-features = false, features = [ "yamux", "noise", "ping" ] } +libp2p = { version = "0.37", default-features = false, features = [ "yamux", "noise", "ping", "mplex" ] } rand = "0.8" tempfile = "3" testcontainers = "0.12" diff --git a/libp2p-tor/examples/dialer.rs b/libp2p-tor/examples/dialer.rs index fca1b647..0a99fa5e 100644 --- a/libp2p-tor/examples/dialer.rs +++ b/libp2p-tor/examples/dialer.rs @@ -1,10 +1,11 @@ use libp2p::core::muxing::StreamMuxerBox; -use libp2p::core::upgrade::Version; +use libp2p::core::upgrade::{Version, SelectUpgrade}; use libp2p::ping::{Ping, PingEvent, PingSuccess}; use libp2p::swarm::{SwarmBuilder, SwarmEvent}; use libp2p::{identity, noise, yamux, Multiaddr, Swarm, Transport}; use libp2p_tor::dial_only; use std::time::Duration; +use libp2p::mplex::MplexConfig; #[tokio::main] async fn main() { @@ -55,6 +56,9 @@ async fn main() { /// Builds a new swarm that is capable of dialling onion address. fn new_swarm() -> Swarm { let identity = identity::Keypair::generate_ed25519(); + let peer_id = identity.public().into_peer_id(); + + println!("peer id upon swarm setup: {}", peer_id); SwarmBuilder::new( dial_only::TorConfig::new(9050) @@ -67,12 +71,15 @@ fn new_swarm() -> Swarm { ) .into_authenticated(), ) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(SelectUpgrade::new( + yamux::YamuxConfig::default(), + MplexConfig::new(), + )) .timeout(Duration::from_secs(20)) .map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer))) .boxed(), Ping::default(), - identity.public().into_peer_id(), + peer_id, ) .executor(Box::new(|f| { tokio::spawn(f); diff --git a/libp2p-tor/examples/listener.rs b/libp2p-tor/examples/listener.rs index 79270b7c..a265275d 100644 --- a/libp2p-tor/examples/listener.rs +++ b/libp2p-tor/examples/listener.rs @@ -1,5 +1,5 @@ use libp2p::core::muxing::StreamMuxerBox; -use libp2p::core::upgrade::Version; +use libp2p::core::upgrade::{Version, SelectUpgrade}; use libp2p::ping::{Ping, PingEvent, PingSuccess}; use libp2p::swarm::{SwarmBuilder, SwarmEvent}; use libp2p::{identity, noise, yamux, Swarm, Transport, Multiaddr}; @@ -11,6 +11,7 @@ use std::time::Duration; use torut::control::AuthenticatedConn; use torut::onion::TorSecretKeyV3; use std::str::FromStr; +use libp2p::mplex::MplexConfig; #[tokio::main] async fn main() { @@ -83,7 +84,10 @@ async fn new_swarm(key: TorSecretKeyV3) -> Swarm { ) .into_authenticated(), ) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(SelectUpgrade::new( + yamux::YamuxConfig::default(), + MplexConfig::new(), + )) .timeout(Duration::from_secs(20)) .map(|(peer, muxer), _| (peer, StreamMuxerBox::new(muxer))) .boxed(),