mirror of https://github.com/dswd/vpncloud.git
Feature gate websockets
This commit is contained in:
parent
bd0d102358
commit
e9122743e9
|
@ -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"
|
||||
|
|
|
@ -500,6 +500,7 @@ pub enum Command {
|
|||
GenKey,
|
||||
|
||||
/// Run a websocket proxy
|
||||
#[cfg(feature = "websocket")]
|
||||
#[structopt(alias = "wsproxy")]
|
||||
WsProxy {
|
||||
/// Websocket listen address IP:PORT
|
||||
|
|
12
src/main.rs
12
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<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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue