Feature gate websockets

This commit is contained in:
Dennis Schwerdel 2021-02-04 21:42:38 +01:00
parent bd0d102358
commit e9122743e9
3 changed files with 16 additions and 11 deletions

View File

@ -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"

View File

@ -500,6 +500,7 @@ pub enum Command {
GenKey,
/// Run a websocket proxy
#[cfg(feature = "websocket")]
#[structopt(alias = "wsproxy")]
WsProxy {
/// Websocket listen address IP:PORT

View File

@ -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<Mutex<File>>
}
@ -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::<payload::Frame, _>(config, socket),
Type::Tun => run::<payload::Packet, _>(config, socket)
}
} else {
let socket = try_fail!(UdpSocket::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
match config.device_type {
Type::Tap => run::<payload::Frame, _>(config, socket),
Type::Tun => run::<payload::Packet, _>(config, socket)
}
return
}
let socket = try_fail!(UdpSocket::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
match config.device_type {
Type::Tap => run::<payload::Frame, _>(config, socket),
Type::Tun => run::<payload::Packet, _>(config, socket)
}
}