Merge branch 'master' into threading

This commit is contained in:
Dennis Schwerdel 2021-12-19 15:43:17 +01:00
commit 7d86892f6f
26 changed files with 287 additions and 257 deletions

View File

@ -18,6 +18,16 @@ linker = "arm-linux-gnueabihf-gcc"
objcopy = { path = "arm-linux-gnueabihf-objcopy" } objcopy = { path = "arm-linux-gnueabihf-objcopy" }
strip = { path = "arm-linux-gnueabihf-strip" } strip = { path = "arm-linux-gnueabihf-strip" }
[target.armv5te-unknown-linux-gnueabi]
linker = "arm-linux-gnueabi-gcc"
objcopy = { path = "arm-linux-gnueabi-objcopy" }
strip = { path = "arm-linux-gnueabi-strip" }
[target.armv5te-unknown-linux-musleabi]
linker = "arm-linux-gnueabi-gcc"
objcopy = { path = "arm-linux-gnueabi-objcopy" }
strip = { path = "arm-linux-gnueabi-strip" }
[target.aarch64-unknown-linux-gnu] [target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc" linker = "aarch64-linux-gnu-gcc"
objcopy = { path = "aarch64-linux-gnu-objcopy" } objcopy = { path = "aarch64-linux-gnu-objcopy" }

View File

@ -11,8 +11,8 @@ RUN chown vscode: -R /usr/local/rustup /usr/local/cargo
USER vscode USER vscode
RUN rustup default 1.51.0 \ RUN rustup default 1.57.0 \
&& rustup component add clippy rust-src rustfmt && rustup component add clippy rust-src rustfmt
RUN cargo install cargo-outdated cargo-cache \ RUN cargo install cargo-outdated cargo-cache cargo-criterion \
&& cargo cache -a && cargo cache -a

View File

@ -25,7 +25,8 @@
"editorconfig.editorconfig", "editorconfig.editorconfig",
"swellaby.vscode-rust-test-adapter", "swellaby.vscode-rust-test-adapter",
"matklad.rust-analyzer", "matklad.rust-analyzer",
"asciidoctor.asciidoctor-vscode" "asciidoctor.asciidoctor-vscode",
"ms-vscode.test-adapter-converter"
], ],
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [], // "forwardPorts": [],

View File

@ -6,8 +6,10 @@ RUN apt-get update \
curl \ curl \
gcc-aarch64-linux-gnu \ gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \ gcc-arm-linux-gnueabihf \
gcc-arm-linux-gnueabi \
libc6-dev-arm64-cross \ libc6-dev-arm64-cross \
libc6-dev-armhf-cross \ libc6-dev-armhf-cross \
libc6-dev-armel-cross \
libc6-dev-i386 \ libc6-dev-i386 \
gcc-5-multilib \ gcc-5-multilib \
asciidoctor \ asciidoctor \

View File

@ -13,6 +13,7 @@ curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain ${TOOLCHAIN}
source $HOME/.cargo/env source $HOME/.cargo/env
rustup target add i686-unknown-linux-gnu rustup target add i686-unknown-linux-gnu
rustup target add armv5te-unknown-linux-gnueabi
rustup target add armv7-unknown-linux-gnueabihf rustup target add armv7-unknown-linux-gnueabihf
rustup target add aarch64-unknown-linux-gnu rustup target add aarch64-unknown-linux-gnu
@ -32,4 +33,5 @@ cp target/debian/vpncloud_${DEB_VERSION}_amd64.deb dist/vpncloud_${DEB_VERSION}_
build_deb i386 i686-unknown-linux-gnu build_deb i386 i686-unknown-linux-gnu
build_deb armhf armv7-unknown-linux-gnueabihf build_deb armhf armv7-unknown-linux-gnueabihf
build_deb armel armv5te-unknown-linux-gnueabi
build_deb arm64 aarch64-unknown-linux-gnu build_deb arm64 aarch64-unknown-linux-gnu

View File

@ -6,8 +6,10 @@ RUN apt-get update \
curl \ curl \
gcc-aarch64-linux-gnu \ gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \ gcc-arm-linux-gnueabihf \
gcc-arm-linux-gnueabi \
libc6-dev-arm64-cross \ libc6-dev-arm64-cross \
libc6-dev-armhf-cross \ libc6-dev-armhf-cross \
libc6-dev-armel-cross \
libc6-dev-i386 \ libc6-dev-i386 \
gcc-5-multilib \ gcc-5-multilib \
asciidoctor \ asciidoctor \

View File

@ -17,6 +17,7 @@ source $HOME/.cargo/env
rustup target add x86_64-unknown-linux-musl rustup target add x86_64-unknown-linux-musl
rustup target add i686-unknown-linux-musl rustup target add i686-unknown-linux-musl
rustup target add armv5te-unknown-linux-musleabi
rustup target add armv7-unknown-linux-musleabihf rustup target add armv7-unknown-linux-musleabihf
rustup target add aarch64-unknown-linux-musl rustup target add aarch64-unknown-linux-musl
@ -34,4 +35,5 @@ build_static() {
build_static amd64 x86_64-unknown-linux-musl build_static amd64 x86_64-unknown-linux-musl
#build_static i386 i686-unknown-linux-musl #build_static i386 i686-unknown-linux-musl
build_static armhf armv7-unknown-linux-musleabihf build_static armhf armv7-unknown-linux-musleabihf
build_static armel armv5te-unknown-linux-musleabi
build_static arm64 aarch64-unknown-linux-musl build_static arm64 aarch64-unknown-linux-musl

View File

@ -4,8 +4,12 @@ This project follows [semantic versioning](http://semver.org).
### UNRELEASED ### UNRELEASED
- [added] Added build for armv5te (thanks to xek)
- [added] Option to specify advertised addresses - [added] Option to specify advertised addresses
- [added] Peers now learn their own address from peers - [added] Peers now learn their own address from peers
- [changed] Changed Rust version to 1.57.0
- [changed] Updated dependencies
- [fixed] Fixed problem with IPv4 addresses in listen option
### v2.2.0 (2021-04-06) ### v2.2.0 (2021-04-06)

425
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ readme = "README.md"
edition = "2018" edition = "2018"
[package.metadata] [package.metadata]
toolchain = "1.51.0" toolchain = "1.57.0"
upx_version = "3.96" upx_version = "3.96"
[dependencies] [dependencies]
@ -30,10 +30,10 @@ ring = "0.16"
privdrop = "0.5" privdrop = "0.5"
byteorder = "1.4" byteorder = "1.4"
thiserror = "1.0" thiserror = "1.0"
parking_lot = "*" parking_lot = "^0.11.2"
smallvec = "1.6" smallvec = "1.7"
dialoguer = { version = "0.8", optional = true } dialoguer = { version = "0.9", optional = true }
tungstenite = { version = "0.13", optional = true, default-features = false } tungstenite = { version = "0.16", optional = true, default-features = false }
url = { version = "2.2", optional = true } url = { version = "2.2", optional = true }
igd = { version = "0.12", optional = true } igd = { version = "0.12", optional = true }
timeout_io = "0.6" timeout_io = "0.6"

View File

@ -3,8 +3,6 @@
extern crate serde; extern crate serde;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[macro_use]
extern crate tokio;
use criterion::{criterion_group, criterion_main, Criterion, Throughput}; use criterion::{criterion_group, criterion_main, Criterion, Throughput};

View File

@ -3,8 +3,6 @@
extern crate serde; extern crate serde;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[macro_use]
extern crate tokio;
use iai::{black_box, main}; use iai::{black_box, main};

View File

@ -9,8 +9,10 @@ RUN apt-get update \
curl \ curl \
gcc-aarch64-linux-gnu \ gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \ gcc-arm-linux-gnueabihf \
gcc-arm-linux-gnueabi \
libc6-dev-arm64-cross \ libc6-dev-arm64-cross \
libc6-dev-armhf-cross \ libc6-dev-armhf-cross \
libc6-dev-armel-cross \
libc6-dev-i386 \ libc6-dev-i386 \
gcc-5-multilib \ gcc-5-multilib \
asciidoctor \ asciidoctor \
@ -22,6 +24,7 @@ ENV RUSTUP_HOME=/opt/rust/rustup \
RUN curl https://sh.rustup.rs -sSf | env CARGO_HOME=/opt/rust/cargo sh -s -- -y --default-toolchain ${TOOLCHAIN} --profile minimal --no-modify-path RUN curl https://sh.rustup.rs -sSf | env CARGO_HOME=/opt/rust/cargo sh -s -- -y --default-toolchain ${TOOLCHAIN} --profile minimal --no-modify-path
RUN env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-gnu \ RUN env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-gnu \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv5te-unknown-linux-gnueabi \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-gnueabihf \ && env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-gnueabihf \
&& env CARGO_HOME=/opt/rust/cargo rustup target add aarch64-unknown-linux-gnu && env CARGO_HOME=/opt/rust/cargo rustup target add aarch64-unknown-linux-gnu

View File

@ -9,8 +9,10 @@ RUN apt-get update \
curl \ curl \
gcc-aarch64-linux-gnu \ gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabihf \ gcc-arm-linux-gnueabihf \
gcc-arm-linux-gnueabi \
libc6-dev-arm64-cross \ libc6-dev-arm64-cross \
libc6-dev-armhf-cross \ libc6-dev-armhf-cross \
libc6-dev-armel-cross \
libc6-dev-i386 \ libc6-dev-i386 \
gcc-5-multilib \ gcc-5-multilib \
asciidoctor \ asciidoctor \
@ -24,6 +26,7 @@ RUN curl https://sh.rustup.rs -sSf | env CARGO_HOME=/opt/rust/cargo sh -s -- -y
RUN env CARGO_HOME=/opt/rust/cargo rustup target add x86_64-unknown-linux-musl \ RUN env CARGO_HOME=/opt/rust/cargo rustup target add x86_64-unknown-linux-musl \
&& env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-musl \ && env CARGO_HOME=/opt/rust/cargo rustup target add i686-unknown-linux-musl \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv5te-unknown-linux-musleabi \
&& env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-musleabihf \ && env CARGO_HOME=/opt/rust/cargo rustup target add armv7-unknown-linux-musleabihf \
&& env CARGO_HOME=/opt/rust/cargo rustup target add aarch64-unknown-linux-musl && env CARGO_HOME=/opt/rust/cargo rustup target add aarch64-unknown-linux-musl

View File

@ -53,6 +53,7 @@ build_deb() {
build_deb i386 i686-unknown-linux-gnu build_deb i386 i686-unknown-linux-gnu
build_deb armhf armv7-unknown-linux-gnueabihf build_deb armhf armv7-unknown-linux-gnueabihf
build_deb armel armv5te-unknown-linux-gnueabi
build_deb arm64 aarch64-unknown-linux-gnu build_deb arm64 aarch64-unknown-linux-gnu
@ -69,6 +70,7 @@ build_static() {
build_static amd64 x86_64-unknown-linux-musl build_static amd64 x86_64-unknown-linux-musl
#build_static i386 i686-unknown-linux-musl #build_static i386 i686-unknown-linux-musl
build_static armel armv5te-unknown-linux-musleabi
build_static armhf armv7-unknown-linux-musleabihf build_static armhf armv7-unknown-linux-musleabihf
build_static arm64 aarch64-unknown-linux-musl build_static arm64 aarch64-unknown-linux-musl

View File

@ -387,7 +387,7 @@ impl Config {
if let Some(ref s) = self.hook { if let Some(ref s) = self.hook {
script = Some(s); script = Some(s);
} }
if let Some(ref s) = self.hooks.get(event) { if let Some(s) = self.hooks.get(event) {
script = Some(s); script = Some(s);
} }
if script.is_none() { if script.is_none() {

View File

@ -247,7 +247,7 @@ impl PeerCrypto {
match self { match self {
PeerCrypto::Encrypted { trusted_keys, last_init_message, .. } PeerCrypto::Encrypted { trusted_keys, last_init_message, .. }
| PeerCrypto::Unencrypted { trusted_keys, last_init_message, .. } => { | PeerCrypto::Unencrypted { trusted_keys, last_init_message, .. } => {
let (msg, _) = InitMsg::read_from(buffer.buffer(), &trusted_keys)?; let (msg, _) = InitMsg::read_from(buffer.buffer(), trusted_keys)?;
buffer.clear(); buffer.clear();
if msg.stage() == STAGE_PONG { if msg.stage() == STAGE_PONG {
buffer.set_length(last_init_message.len()); buffer.set_length(last_init_message.len());

View File

@ -112,7 +112,7 @@ struct CryptoKey {
impl CryptoKey { impl CryptoKey {
fn new(rand: &SystemRandom, key: LessSafeKey, nonce_half: bool) -> Self { fn new(rand: &SystemRandom, key: LessSafeKey, nonce_half: bool) -> Self {
let mut send_nonce = Nonce::random(&rand); let mut send_nonce = Nonce::random(rand);
send_nonce.set_msb(if nonce_half { 0x80 } else { 0x00 }); send_nonce.set_msb(if nonce_half { 0x80 } else { 0x00 });
CryptoKey { CryptoKey {
key, key,

View File

@ -246,7 +246,7 @@ impl InitMsg {
let signed_data = &r.into_inner()[1..pos]; let signed_data = &r.into_inner()[1..pos];
let public_key = signature::UnparsedPublicKey::new(&ED25519, &public_key_data); let public_key = signature::UnparsedPublicKey::new(&ED25519, &public_key_data);
if public_key.verify(&signed_data, &signature).is_err() { if public_key.verify(signed_data, &signature).is_err() {
return Err(Error::Crypto("invalid signature")); return Err(Error::Crypto("invalid signature"));
} }
@ -331,7 +331,7 @@ impl InitMsg {
w.write_u8(Self::PART_ECDH_PUBLIC_KEY)?; w.write_u8(Self::PART_ECDH_PUBLIC_KEY)?;
let key_bytes = ecdh_public_key.bytes(); let key_bytes = ecdh_public_key.bytes();
w.write_u16::<NetworkEndian>(key_bytes.len() as u16)?; w.write_u16::<NetworkEndian>(key_bytes.len() as u16)?;
w.write_all(&key_bytes)?; w.write_all(key_bytes)?;
} }
_ => (), _ => (),
} }
@ -536,8 +536,8 @@ impl<P: Payload> InitState<P> {
}, },
_ => unreachable!(), _ => unreachable!(),
}; };
let mut bytes = out.buffer(); let bytes = out.buffer();
let len = msg.write_to(&mut bytes, &self.key_pair).expect("Buffer too small"); let len = msg.write_to(bytes, &self.key_pair).expect("Buffer too small");
self.last_message = Some(bytes[0..len].to_vec()); self.last_message = Some(bytes[0..len].to_vec());
out.set_length(len); out.set_length(len);
} }
@ -699,7 +699,7 @@ mod tests {
impl Payload for Vec<u8> { impl Payload for Vec<u8> {
fn write_to(&self, buffer: &mut MsgBuffer) { fn write_to(&self, buffer: &mut MsgBuffer) {
buffer.buffer().write_all(&self).expect("Buffer too small"); buffer.buffer().write_all(self).expect("Buffer too small");
buffer.set_length(self.len()) buffer.set_length(self.len())
} }

View File

@ -176,7 +176,7 @@ impl RotationState {
if let Some(ref private_key) = self.proposed { if let Some(ref private_key) = self.proposed {
// Still a proposed key that has not been confirmed, proposal must have been lost // Still a proposed key that has not been confirmed, proposal must have been lost
if self.timeout { if self.timeout {
let proposed_key = Self::compute_public_key(&private_key); let proposed_key = Self::compute_public_key(private_key);
if let Some((ref confirmed_key, message_id)) = self.confirmed { if let Some((ref confirmed_key, message_id)) = self.confirmed {
// Reconfirm last confirmed key // Reconfirm last confirmed key
Self::send( Self::send(
@ -271,7 +271,7 @@ mod tests {
assert!(key2.is_some()); assert!(key2.is_some());
let key2 = key2.unwrap(); let key2 = key2.unwrap();
assert_eq!(key2.id, 2); assert_eq!(key2.id, 2);
assert_eq!(key2.use_for_sending, false); assert!(!key2.use_for_sending);
assert!(!out2.is_empty()); assert!(!out2.is_empty());
let msg2 = out2.msg().unwrap(); let msg2 = out2.msg().unwrap();
assert_eq!(msg2.message_id, 2); assert_eq!(msg2.message_id, 2);
@ -281,14 +281,14 @@ mod tests {
assert!(key.is_some()); assert!(key.is_some());
let key = key.unwrap(); let key = key.unwrap();
assert_eq!(key.id, 2); assert_eq!(key.id, 2);
assert_eq!(key.use_for_sending, true); assert!(key.use_for_sending);
// Cycle 2 // Cycle 2
let key1 = node1.cycle(&mut out1); let key1 = node1.cycle(&mut out1);
let key2 = node2.cycle(&mut out2); let key2 = node2.cycle(&mut out2);
assert!(key1.is_some()); assert!(key1.is_some());
let key1 = key1.unwrap(); let key1 = key1.unwrap();
assert_eq!(key1.id, 3); assert_eq!(key1.id, 3);
assert_eq!(key1.use_for_sending, false); assert!(!key1.use_for_sending);
assert!(!out1.is_empty()); assert!(!out1.is_empty());
let msg1 = out1.msg().unwrap(); let msg1 = out1.msg().unwrap();
assert_eq!(msg1.message_id, 3); assert_eq!(msg1.message_id, 3);
@ -300,7 +300,7 @@ mod tests {
assert!(key.is_some()); assert!(key.is_some());
let key = key.unwrap(); let key = key.unwrap();
assert_eq!(key.id, 3); assert_eq!(key.id, 3);
assert_eq!(key.use_for_sending, true); assert!(key.use_for_sending);
// Cycle 3 // Cycle 3
let key1 = node1.cycle(&mut out1); let key1 = node1.cycle(&mut out1);
let key2 = node2.cycle(&mut out2); let key2 = node2.cycle(&mut out2);
@ -309,7 +309,7 @@ mod tests {
assert!(key2.is_some()); assert!(key2.is_some());
let key2 = key2.unwrap(); let key2 = key2.unwrap();
assert_eq!(key2.id, 4); assert_eq!(key2.id, 4);
assert_eq!(key2.use_for_sending, false); assert!(!key2.use_for_sending);
assert!(!out2.is_empty()); assert!(!out2.is_empty());
let msg2 = out2.msg().unwrap(); let msg2 = out2.msg().unwrap();
assert_eq!(msg2.message_id, 4); assert_eq!(msg2.message_id, 4);
@ -319,7 +319,7 @@ mod tests {
assert!(key.is_some()); assert!(key.is_some());
let key = key.unwrap(); let key = key.unwrap();
assert_eq!(key.id, 4); assert_eq!(key.id, 4);
assert_eq!(key.use_for_sending, true); assert!(key.use_for_sending);
} }
#[test] #[test]

View File

@ -270,7 +270,7 @@ impl Device for TunTapDevice {
fn read(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> { fn read(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
buffer.clear(); buffer.clear();
let mut read = 0; let mut read = 0;
self.fd.try_read(buffer.buffer(), &mut read, Duration::from_secs(1)).map_err(|e| Error::DeviceRead(e))?; self.fd.try_read(buffer.buffer(), &mut read, Duration::from_secs(1)).map_err(Error::DeviceRead)?;
buffer.set_length(read); buffer.set_length(read);
self.correct_data_after_read(buffer); self.correct_data_after_read(buffer);
Ok(()) Ok(())

View File

@ -50,7 +50,7 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
pub fn new( pub fn new(
config: &Config, socket: S, device: D, port_forwarding: Option<PortForwarding>, stats_file: Option<File>, config: &Config, socket: S, device: D, port_forwarding: Option<PortForwarding>, stats_file: Option<File>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let table = SharedTable::<TS>::new(&config); let table = SharedTable::<TS>::new(config);
let traffic = SharedTraffic::new(); let traffic = SharedTraffic::new();
let peer_crypto = SharedPeerCrypto::new(); let peer_crypto = SharedPeerCrypto::new();
let running = Arc::new(AtomicBool::new(true)); let running = Arc::new(AtomicBool::new(true));

View File

@ -430,7 +430,7 @@ impl<S: Socket, D: Device, P: Protocol, TS: TimeSource> SocketThread<S, D, P, TS
pub fn housekeep(&mut self) -> Result<(), Error> { pub fn housekeep(&mut self) -> Result<(), Error> {
let now = TS::now(); let now = TS::now();
let mut del: SmallVec<[SocketAddr; 3]> = SmallVec::new(); let mut del: SmallVec<[SocketAddr; 3]> = SmallVec::new();
for (&addr, ref data) in &self.peers { for (&addr, data) in &self.peers {
if data.timeout < now { if data.timeout < now {
del.push(addr); del.push(addr);
} }
@ -675,7 +675,7 @@ impl<S: Socket, D: Device, P: Protocol, TS: TimeSource> SocketThread<S, D, P, TS
for entry in &mut self.reconnect_peers { for entry in &mut self.reconnect_peers {
// Schedule for next second if node is connected // Schedule for next second if node is connected
for addr in &entry.resolved { for addr in &entry.resolved {
if self.peers.contains_key(&addr) { if self.peers.contains_key(addr) {
entry.tries = 0; entry.tries = 0;
entry.timeout = 1; entry.timeout = 1;
entry.next = now + 1; entry.next = now + 1;

View File

@ -96,13 +96,15 @@ thread_local! {
static MOCK_SOCKET_NAT: AtomicBool = AtomicBool::new(false); static MOCK_SOCKET_NAT: AtomicBool = AtomicBool::new(false);
} }
type MsgQueue = Arc<Mutex<VecDeque<(SocketAddr, Vec<u8>)>>>;
#[derive(Clone)] #[derive(Clone)]
pub struct MockSocket { pub struct MockSocket {
nat: bool, nat: bool,
nat_peers: Arc<Mutex<HashMap<SocketAddr, Time>>>, nat_peers: Arc<Mutex<HashMap<SocketAddr, Time>>>,
address: SocketAddr, address: SocketAddr,
outbound: Arc<Mutex<VecDeque<(SocketAddr, Vec<u8>)>>>, outbound: MsgQueue,
inbound: Arc<Mutex<VecDeque<(SocketAddr, Vec<u8>)>>>, inbound: MsgQueue,
} }
impl MockSocket { impl MockSocket {

View File

@ -501,8 +501,8 @@ pub fn configure(name: Option<String>) -> Result<(), io::Error> {
println!(" start the VPN: sudo service vpncloud@{0} start", name); println!(" start the VPN: sudo service vpncloud@{0} start", name);
println!(" stop the VPN: sudo service vpncloud@{0} stop", name); println!(" stop the VPN: sudo service vpncloud@{0} stop", name);
println!(" get the status: sudo service vpncloud@{0} status", name); println!(" get the status: sudo service vpncloud@{0} status", name);
println!(" add VPN to autostart: sudo sysctl enable vpncloud@{0}", name); println!(" add VPN to autostart: sudo systemctl enable vpncloud@{0}", name);
println!(" remove VPN from autostart: sudo sysctl disable vpncloud@{0}", name); println!(" remove VPN from autostart: sudo systemctl disable vpncloud@{0}", name);
} }
Ok(()) Ok(())

View File

@ -9,8 +9,13 @@ use super::{
util::MsgBuffer, util::MsgBuffer,
}; };
use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt};
use std::{io::{self, Cursor, Read, Write}, net::{Ipv6Addr, SocketAddr, SocketAddrV6, TcpListener, TcpStream, UdpSocket}, os::unix::io::AsRawFd, sync::Arc, thread}; use std::{
use tungstenite::{client::AutoStream, connect, protocol::WebSocket, server::accept, Message}; io::{self, Cursor, Read, Write},
net::{Ipv6Addr, SocketAddr, SocketAddrV6, TcpListener, TcpStream, UdpSocket},
os::unix::io::{AsRawFd, RawFd},
thread, sync::Arc,
};
use tungstenite::{connect, protocol::WebSocket, Message, accept, stream::{MaybeTlsStream, NoDelay}};
use url::Url; use url::Url;
macro_rules! io_error { macro_rules! io_error {
@ -105,7 +110,7 @@ pub fn run_proxy(listen: &str) -> Result<(), io::Error> {
#[derive(Clone)] #[derive(Clone)]
pub struct ProxyConnection { pub struct ProxyConnection {
addr: SocketAddr, addr: SocketAddr,
socket: Arc<WebSocket<AutoStream>>, socket: Arc<WebSocket<MaybeTlsStream<TcpStream>>>,
} }
impl ProxyConnection { impl ProxyConnection {
@ -132,6 +137,15 @@ impl ProxyConnection {
} }
} }
impl AsRawFd for ProxyConnection {
fn as_raw_fd(&self) -> RawFd {
match self.socket.get_ref() {
MaybeTlsStream::Plain(stream) => stream.as_raw_fd(),
_ => unimplemented!()
}
}
}
impl Socket for ProxyConnection { impl Socket for ProxyConnection {
fn create_port_forwarding(&self) -> Option<PortForwarding> { fn create_port_forwarding(&self) -> Option<PortForwarding> {
None None