Make libp2p-websocket optional (#624)

This commit is contained in:
Pierre Krieger 2018-11-12 11:42:42 +01:00 committed by GitHub
parent 6a7c722ffc
commit 38b5841801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
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"

View File

@ -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<dns::DnsConfig<tcp::TcpConfig>, websocket::WsConfig<dns::DnsConfig<tcp::TcpConfig>>>;
#[cfg(all(not(target_os = "emscripten"), not(feature = "libp2p-websocket")))]
pub type InnerImplementation = dns::DnsConfig<tcp::TcpConfig>;
#[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 }
}
}