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"
|
byteorder = "1.4"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
smallvec = "1.6"
|
smallvec = "1.6"
|
||||||
tungstenite = "0.12"
|
tungstenite = { version = "0.12", optional = true }
|
||||||
url = "2.2"
|
url = { version = "2.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
@ -38,8 +38,8 @@ criterion = "0.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nat"]
|
default = ["nat"]
|
||||||
bench = []
|
|
||||||
nat = ["igd"]
|
nat = ["igd"]
|
||||||
|
websocket = ["tungstenite", "url"]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bench"
|
name = "bench"
|
||||||
|
|
|
@ -500,6 +500,7 @@ pub enum Command {
|
||||||
GenKey,
|
GenKey,
|
||||||
|
|
||||||
/// Run a websocket proxy
|
/// Run a websocket proxy
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
#[structopt(alias = "wsproxy")]
|
#[structopt(alias = "wsproxy")]
|
||||||
WsProxy {
|
WsProxy {
|
||||||
/// Websocket listen address IP:PORT
|
/// 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 table;
|
||||||
pub mod traffic;
|
pub mod traffic;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
pub mod wsproxy;
|
#[cfg(feature = "websocket")] pub mod wsproxy;
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
@ -52,9 +52,11 @@ use crate::{
|
||||||
oldconfig::OldConfigFile,
|
oldconfig::OldConfigFile,
|
||||||
payload::Protocol,
|
payload::Protocol,
|
||||||
util::SystemTimeSource,
|
util::SystemTimeSource,
|
||||||
wsproxy::ProxyConnection
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
|
use crate::wsproxy::ProxyConnection;
|
||||||
|
|
||||||
struct DualLogger {
|
struct DualLogger {
|
||||||
file: Option<Mutex<File>>
|
file: Option<Mutex<File>>
|
||||||
}
|
}
|
||||||
|
@ -268,6 +270,7 @@ fn main() {
|
||||||
Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
|
Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
Command::WsProxy { listen } => {
|
Command::WsProxy { listen } => {
|
||||||
try_fail!(wsproxy::run_proxy(&listen), "Failed to run websocket proxy: {:?}");
|
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");
|
error!("Either password or private key must be set in config or given as parameter");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "websocket")]
|
||||||
if config.listen.starts_with("ws://") {
|
if config.listen.starts_with("ws://") {
|
||||||
let socket = try_fail!(ProxyConnection::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
|
let socket = try_fail!(ProxyConnection::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
|
||||||
match config.device_type {
|
match config.device_type {
|
||||||
Type::Tap => run::<payload::Frame, _>(config, socket),
|
Type::Tap => run::<payload::Frame, _>(config, socket),
|
||||||
Type::Tun => run::<payload::Packet, _>(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);
|
let socket = try_fail!(UdpSocket::listen(&config.listen), "Failed to open socket {}: {}", config.listen);
|
||||||
match config.device_type {
|
match config.device_type {
|
||||||
Type::Tap => run::<payload::Frame, _>(config, socket),
|
Type::Tap => run::<payload::Frame, _>(config, socket),
|
||||||
Type::Tun => run::<payload::Packet, _>(config, socket)
|
Type::Tun => run::<payload::Packet, _>(config, socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue