diff --git a/sn_client/Cargo.toml b/sn_client/Cargo.toml index 2363053b88..2f8a0d7d0e 100644 --- a/sn_client/Cargo.toml +++ b/sn_client/Cargo.toml @@ -20,7 +20,6 @@ local-discovery=["sn_networking/local-discovery"] open-metrics = ["sn_networking/open-metrics", "prometheus-client"] # required to pass on flag to node builds quic = ["sn_networking/quic"] -webtransport-websys = ["sn_networking/webtransport-websys"] [dependencies] async-trait = "0.1" @@ -60,4 +59,5 @@ workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "0.2.12", features = ["js"] } \ No newline at end of file +getrandom = { version = "0.2.12", features = ["js"] } +sn_networking = { path = "../sn_networking", version = "0.12.32" } diff --git a/sn_networking/Cargo.toml b/sn_networking/Cargo.toml index 481bbbf9d4..70311fb5c9 100644 --- a/sn_networking/Cargo.toml +++ b/sn_networking/Cargo.toml @@ -11,10 +11,10 @@ repository = "https://github.com/maidsafe/safe_network" version = "0.12.35" [features] -default=[] +default=["quic"] local-discovery=["libp2p/mdns"] quic=["libp2p/quic"] -webtransport-websys=["libp2p/webtransport-websys"] +tcp=["libp2p/tcp"] open-metrics=["libp2p/metrics", "prometheus-client", "hyper", "sysinfo"] [dependencies] @@ -54,3 +54,5 @@ workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.12", features = ["js"] } +libp2p = { version="0.53", features = ["tokio", "dns", "kad", "macros", "request-response", "cbor","identify", "autonat", "noise", "tcp", "yamux", "gossipsub", "webtransport-websys"] } + diff --git a/sn_networking/src/driver.rs b/sn_networking/src/driver.rs index b9d5aed0a0..82c2a4403b 100644 --- a/sn_networking/src/driver.rs +++ b/sn_networking/src/driver.rs @@ -26,14 +26,17 @@ use crate::{ Network, CLOSE_GROUP_SIZE, }; use futures::StreamExt; -#[cfg(any(feature = "quic", feature = "webtransport-websys"))] +#[cfg(not(feature = "tcp"))] use libp2p::core::muxing::StreamMuxerBox; #[cfg(feature = "local-discovery")] use libp2p::mdns; -#[cfg(feature = "quic")] -use libp2p::quic; -#[cfg(feature = "webtransport-websys")] -use libp2p::webtransport_websys; +// default transports +#[cfg(all(not(feature = "tcp"), not(target_arch = "wasm32")))] +use libp2p::quic::{tokio::Transport as TokioTransport, Config as TransportConfig}; +#[cfg(feature = "tcp")] +use libp2p::tcp::{tokio::Transport as TokioTransport, Config as TransportConfig}; +#[cfg(target_arch = "wasm32")] +use libp2p::webtransport_websys::{Config as TransportConfig, Transport as TokioTransport}; use libp2p::{ autonat, identity::Keypair, @@ -319,20 +322,24 @@ impl NetworkBuilder { )?; // Listen on the provided address - let listen_addr = listen_addr.ok_or(Error::ListenAddressNotProvided)?; - #[cfg(not(any(feature = "quic", feature = "webtransport-websys")))] - let listen_addr = Multiaddr::from(listen_addr.ip()).with(Protocol::Tcp(listen_addr.port())); + let listen_socket_addr = listen_addr.ok_or(Error::ListenAddressNotProvided)?; + + // Flesh out the multiaddress + let listen_addr = Multiaddr::from(listen_socket_addr.ip()); #[cfg(feature = "quic")] - let listen_addr = Multiaddr::from(listen_addr.ip()) - .with(Protocol::Udp(listen_addr.port())) + let listen_addr = listen_addr + .with(Protocol::Udp(listen_socket_addr.port())) .with(Protocol::QuicV1); - #[cfg(feature = "webtransport-websys")] - let listen_addr = Multiaddr::from(listen_addr.ip()) - .with(Protocol::Udp(listen_addr.port())) + #[cfg(target_arch = "wasm32")] + let listen_addr = listen_addr + .with(Protocol::Udp(listen_socket_addr.port())) .with(Protocol::WebTransport); + #[cfg(feature = "tcp")] + Multiaddr::from(listen_socket_addr.ip()).with(Protocol::Tcp(listen_socket_addr.port())); + let _listener_id = swarm_driver .swarm .listen_on(listen_addr) @@ -458,9 +465,13 @@ impl NetworkBuilder { libp2p::identify::Behaviour::new(cfg) }; - // Transport - #[cfg(not(any(feature = "quic", feature = "webtransport-websys")))] - let mut transport = libp2p::tcp::tokio::Transport::new(libp2p::tcp::Config::default()) + #[cfg(not(feature = "tcp"))] + let main_transport = TokioTransport::new(TransportConfig::new(&self.keypair)) + .map(|(peer_id, muxer), _| (peer_id, StreamMuxerBox::new(muxer))) + .boxed(); + + #[cfg(feature = "tcp")] + let main_transport = TokioTransport::new(TransportConfig::default()) .upgrade(libp2p::core::upgrade::Version::V1) .authenticate( libp2p::noise::Config::new(&self.keypair) @@ -469,17 +480,6 @@ impl NetworkBuilder { .multiplex(libp2p::yamux::Config::default()) .boxed(); - #[cfg(feature = "quic")] - let mut transport = libp2p::quic::tokio::Transport::new(quic::Config::new(&self.keypair)) - .map(|(peer_id, muxer), _| (peer_id, StreamMuxerBox::new(muxer))) - .boxed(); - - #[cfg(feature = "webtransport-websys")] - let mut transport = - webtransport_websys::Transport::new(webtransport_websys::Config::new(&self.keypair)) - .map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn))) - .boxed(); - let gossipsub = if self.enable_gossip { // Gossipsub behaviour let gossipsub_config = libp2p::gossipsub::ConfigBuilder::default() @@ -516,11 +516,13 @@ impl NetworkBuilder { let gossipsub = Toggle::from(gossipsub); - if !self.local { + let transport = if !self.local { debug!("Preventing non-global dials"); - // Wrap TCP or UDP in a transport that prevents dialing local addresses. - transport = libp2p::core::transport::global_only::Transport::new(transport).boxed(); - } + // Wrap upper in a transport that prevents dialing local addresses. + libp2p::core::transport::global_only::Transport::new(main_transport).boxed() + } else { + main_transport + }; // Disable AutoNAT if we are either running locally or a client. let autonat = if !self.local && !is_client { diff --git a/sn_node/Cargo.toml b/sn_node/Cargo.toml index fbbafd8e99..713356ea9c 100644 --- a/sn_node/Cargo.toml +++ b/sn_node/Cargo.toml @@ -73,7 +73,7 @@ color-eyre = "0.6.2" [dev-dependencies] tempfile = "3.6.0" reqwest = { version="0.11.18", default-features=false, features = ["rustls"] } -sn_protocol = { path = "../sn_protocol", version = "0.10.14", features = ["test-utils"]} +sn_protocol = { path = "../sn_protocol", version = "0.10.14", features = ["test-utils", "rpc"]} [lints] workspace = true diff --git a/sn_peers_acquisition/src/lib.rs b/sn_peers_acquisition/src/lib.rs index 99d20b48d8..70f2452cf2 100644 --- a/sn_peers_acquisition/src/lib.rs +++ b/sn_peers_acquisition/src/lib.rs @@ -124,17 +124,18 @@ async fn get_network_contacts(args: &PeersArgs) -> Result> { pub fn parse_peer_addr(addr: &str) -> Result { // Parse valid IPv4 socket address, e.g. `1.2.3.4:1234`. if let Ok(addr) = addr.parse::() { - #[cfg(not(feature = "quic, webtransport-websys"))] + let multiaddr = Multiaddr::from(*addr.ip()); + #[cfg(feature = "tcp")] // Turn the address into a `/ip4//tcp/` multiaddr. - let multiaddr = Multiaddr::from(*addr.ip()).with(Protocol::Tcp(addr.port())); + let multiaddr = multiaddr.with(Protocol::Tcp(addr.port())); #[cfg(feature = "quic")] // Turn the address into a `/ip4//udp//quic-v1` multiaddr. - let multiaddr = Multiaddr::from(*addr.ip()) + let multiaddr = multiaddr .with(Protocol::Udp(addr.port())) .with(Protocol::QuicV1); - #[cfg(feature = "webtransport-websys")] + #[cfg(target_arch = "wasm32")] // Turn the address into a `/ip4//udp//webtransport-websys-v1` multiaddr. - let multiaddr = Multiaddr::from(*addr.ip()) + let multiaddr = multiaddr .with(Protocol::Udp(addr.port())) .with(Protocol::WebTransport); return Ok(multiaddr);