From 89d058134e2f73565dac6b5e91523c514dc810ec Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Fri, 23 Sep 2022 23:24:08 +0200 Subject: [PATCH] Fix proxy read timeout --- ROADMAP.md | 4 ++-- src/wsproxy.rs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index efcf5a4..2a61af1 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -7,8 +7,8 @@ - [x] Check how async affects performance - [x] Sync traffic stats - [x] Sync forwarding table -- [ ] Fix WS Proxy code -- [ ] Fix Ctrl-C +- [x] Fix WS Proxy code +- [x] Fix Ctrl-C - [x] Fix auto-claim IP ## REST API \ No newline at end of file diff --git a/src/wsproxy.rs b/src/wsproxy.rs index 251a86e..26e2087 100644 --- a/src/wsproxy.rs +++ b/src/wsproxy.rs @@ -13,7 +13,7 @@ use std::{ io::{self, Cursor, Read, Write}, net::{Ipv6Addr, SocketAddr, SocketAddrV6, TcpListener, TcpStream, UdpSocket}, os::unix::io::{AsRawFd, RawFd}, - thread, + thread, time::Duration, }; use tungstenite::{ accept, connect, @@ -122,6 +122,12 @@ impl ProxyConnection { let parsed_url = io_error!(Url::parse(url), "Invalid URL {}: {}", url)?; let (mut socket, _) = io_error!(connect(parsed_url), "Failed to connect to URL {}: {}", url)?; socket.get_mut().set_nodelay(true)?; + match socket.get_mut() { + &mut MaybeTlsStream::Plain(ref mut stream) => { + io_error!(stream.set_read_timeout(Some(Duration::from_secs(1))), "Failed to set read timeout: {}")? + }, + _ => unimplemented!() + } let addr = "0.0.0.0:0".parse::().unwrap(); let mut con = ProxyConnection { addr, socket }; let addr_data = con.read_message()?;