diff --git a/Cargo.toml b/Cargo.toml index 2eebdcf..01a017f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ privdrop = "0.5" byteorder = "1.4" thiserror = "1.0" smallvec = "1.6" -tungstenite = "0.12" -url = "2.2" +tungstenite = { version = "0.12", optional = true } +url = { version = "2.2", optional = true } [dev-dependencies] tempfile = "3" @@ -38,8 +38,8 @@ criterion = "0.3" [features] default = ["nat"] -bench = [] nat = ["igd"] +websocket = ["tungstenite", "url"] [[bench]] name = "bench" diff --git a/src/config.rs b/src/config.rs index 13a8bfd..cfb59f2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -500,6 +500,7 @@ pub enum Command { GenKey, /// Run a websocket proxy + #[cfg(feature = "websocket")] #[structopt(alias = "wsproxy")] WsProxy { /// Websocket listen address IP:PORT diff --git a/src/main.rs b/src/main.rs index 62d658d..9cdd511 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ pub mod port_forwarding; pub mod table; pub mod traffic; pub mod types; -pub mod wsproxy; +#[cfg(feature = "websocket")] pub mod wsproxy; use structopt::StructOpt; @@ -52,9 +52,11 @@ use crate::{ oldconfig::OldConfigFile, payload::Protocol, util::SystemTimeSource, - wsproxy::ProxyConnection }; +#[cfg(feature = "websocket")] +use crate::wsproxy::ProxyConnection; + struct DualLogger { file: Option> } @@ -268,6 +270,7 @@ fn main() { Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout()); return } + #[cfg(feature = "websocket")] Command::WsProxy { listen } => { try_fail!(wsproxy::run_proxy(&listen), "Failed to run websocket proxy: {:?}"); } @@ -299,17 +302,18 @@ fn main() { error!("Either password or private key must be set in config or given as parameter"); return } + #[cfg(feature = "websocket")] if config.listen.starts_with("ws://") { let socket = try_fail!(ProxyConnection::listen(&config.listen), "Failed to open socket {}: {}", config.listen); match config.device_type { Type::Tap => run::(config, socket), Type::Tun => run::(config, socket) } - } else { - let socket = try_fail!(UdpSocket::listen(&config.listen), "Failed to open socket {}: {}", config.listen); - match config.device_type { - Type::Tap => run::(config, socket), - Type::Tun => run::(config, socket) - } + return + } + let socket = try_fail!(UdpSocket::listen(&config.listen), "Failed to open socket {}: {}", config.listen); + match config.device_type { + Type::Tap => run::(config, socket), + Type::Tun => run::(config, socket) } }