From 38b58418017b6c8492058c4b4a7a3d3bbae9faa4 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 12 Nov 2018 11:42:42 +0100 Subject: [PATCH] Make libp2p-websocket optional (#624) --- Cargo.toml | 4 ++-- src/lib.rs | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c42bbcb2..9dae8b13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] license = "MIT" [features] -default = ["secio-rsa", "secio-secp256k1"] +default = ["secio-rsa", "secio-secp256k1", "libp2p-websocket"] secio-rsa = ["libp2p-secio/rsa"] secio-secp256k1 = ["libp2p-secio/secp256k1"] @@ -26,7 +26,7 @@ libp2p-core = { path = "./core" } libp2p-secio = { path = "./protocols/secio", default-features = false } libp2p-transport-timeout = { path = "./transports/timeout" } libp2p-uds = { path = "./transports/uds" } -libp2p-websocket = { path = "./transports/websocket" } +libp2p-websocket = { path = "./transports/websocket", optional = true } libp2p-yamux = { path = "./muxers/yamux" } tokio-codec = "0.1" tokio-executor = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 98f50832..bbbe67d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -155,6 +155,7 @@ pub extern crate libp2p_secio as secio; pub extern crate libp2p_tcp_transport as tcp; pub extern crate libp2p_transport_timeout as transport_timeout; pub extern crate libp2p_uds as uds; +#[cfg(feature = "libp2p-websocket")] pub extern crate libp2p_websocket as websocket; pub extern crate libp2p_yamux as yamux; @@ -178,8 +179,10 @@ pub struct CommonTransport { inner: CommonTransportInner } -#[cfg(not(target_os = "emscripten"))] +#[cfg(all(not(target_os = "emscripten"), feature = "libp2p-websocket"))] pub type InnerImplementation = core::transport::OrTransport, websocket::WsConfig>>; +#[cfg(all(not(target_os = "emscripten"), not(feature = "libp2p-websocket")))] +pub type InnerImplementation = dns::DnsConfig; #[cfg(target_os = "emscripten")] pub type InnerImplementation = websocket::BrowserWsConfig; @@ -193,13 +196,16 @@ impl CommonTransport { #[inline] #[cfg(not(target_os = "emscripten"))] pub fn new() -> CommonTransport { - let tcp = tcp::TcpConfig::new(); - let with_dns = dns::DnsConfig::new(tcp); - let with_ws = websocket::WsConfig::new(with_dns.clone()); - let inner = with_dns.or_transport(with_ws); + let transport = tcp::TcpConfig::new(); + let transport = dns::DnsConfig::new(transport); + #[cfg(feature = "libp2p-websocket")] + let transport = { + let trans_clone = transport.clone(); + transport.or_transport(websocket::WsConfig::new(trans_clone)) + }; CommonTransport { - inner: CommonTransportInner { inner } + inner: CommonTransportInner { inner: transport } } }