Former-commit-id: c4282dccbec4fa9d64fb60334fe83caec963140f [formerly 12eeb52b4a8760d1ec7c13d6cc77c9213a6d3392] [formerly 90e4dda3b1a8e224de2820c387e1e4a07a4db372 [formerly 978616526843c8918e23384b2404ccbf241c4dbf]]
Former-commit-id: 5035c63e099ff2d0729a69c059c4d1ac1a288c8e [formerly 7225907b8ab627bd90b8542d3ba2884764f6a209]
Former-commit-id: 4a1fb1590711e763896b5d525091d35a85a1c70a
Former-commit-id: b343703f7ccfcbb40f1642cd150a9b98d1fcb05e
Former-commit-id: 1e7c5340f1f6bb43041a95f5e405c1e2ec0d7b29
Former-commit-id: dc0d08065cbef90e0b8e890af551ffe6f47a9b17 [formerly e90c7a4f23afd6cbea95ebc55dace2960f6aa003]
Former-commit-id: 4991d306af1ea50d3b0eeb46dc5f47a6a5b2f4b0
This commit is contained in:
Σrebe - Romain GERARD 2023-10-18 09:50:47 +02:00
parent aca065fcab
commit b30bd381e1
4 changed files with 16 additions and 20 deletions

View file

@ -53,14 +53,9 @@ struct Client {
#[arg(short='L', long, value_name = "{tcp,udp,socks5}://[BIND:]PORT:HOST:PORT", value_parser = parse_tunnel_arg)]
local_to_remote: Vec<LocalToRemote>,
/// (linux only) Mark network packet with SO_MARK sockoption with the specified value.
/// You need to use {root, sudo, capabilities} to run wstunnel when using this option
#[arg(long, value_name = "INT", verbatim_doc_comment)]
socket_so_mark: Option<u32>,
/// Domain name that will be use as SNI during TLS handshake
/// Warning: If you are behind a CDN (i.e: Cloudflare) you must set this domain also in the http HOST header.
/// or it will be flag as fishy as your request rejected
/// or it will be flagged as fishy and your request rejected
#[arg(long, value_name = "DOMAIN_NAME", value_parser = parse_sni_override, verbatim_doc_comment)]
tls_sni_override: Option<DnsName>,

View file

@ -61,7 +61,7 @@ pub fn tls_connector(
let certs = rustls_native_certs::load_native_certs()
.with_context(|| "Cannot load system certificates")?;
for cert in certs {
root_store.add(&Certificate(cert.0)).unwrap();
root_store.add(&Certificate(cert.0))?;
}
let mut config = ClientConfig::builder()

View file

@ -293,7 +293,13 @@ async fn server_upgrade(
tokio::spawn(
async move {
let (ws_rx, mut ws_tx) = fut.await.unwrap().split(tokio::io::split);
let (ws_rx, mut ws_tx) = match fut.await {
Ok(ws) => ws.split(tokio::io::split),
Err(err) => {
error!("Error during http upgrade request: {:?}", err);
return;
}
};
let (close_tx, close_rx) = oneshot::channel::<()>();
let connect_timeout = server_config.timeout_connect;
let ping_frequency = server_config
@ -477,8 +483,7 @@ async fn propagate_write(
error!("error while reading from websocket rx {}", err);
break;
}
Err(err) => {
trace!("frame {:?}", err);
Err(_) => {
// TODO: Check that the connection is not closed (no easy method to know if a tx is closed ...)
continue;
}

View file

@ -19,8 +19,7 @@ use tracing::{debug, error, info};
const DEFAULT_UDP_BUFFER_SIZE: usize = 8 * 1024;
struct UdpServer {
listener: UdpSocket,
std_socket: std::net::UdpSocket,
listener: Arc<UdpSocket>,
buffer: Vec<u8>,
peers: HashMap<SocketAddr, DuplexStream, ahash::RandomState>,
keys_to_delete: Arc<RwLock<Vec<SocketAddr>>>,
@ -28,12 +27,9 @@ struct UdpServer {
}
impl UdpServer {
pub fn new(listener: UdpSocket, timeout: Option<Duration>) -> Self {
let socket = listener.into_std().unwrap();
let listener = UdpSocket::from_std(socket.try_clone().unwrap()).unwrap();
pub fn new(listener: Arc<UdpSocket>, timeout: Option<Duration>) -> Self {
Self {
listener,
std_socket: socket,
peers: HashMap::with_hasher(ahash::RandomState::new()),
buffer: vec![0u8; DEFAULT_UDP_BUFFER_SIZE],
keys_to_delete: Default::default(),
@ -55,14 +51,14 @@ impl UdpServer {
keys_to_delete.clear();
}
fn clone_socket(&self) -> UdpSocket {
UdpSocket::from_std(self.std_socket.try_clone().unwrap()).unwrap()
fn clone_socket(&self) -> Arc<UdpSocket> {
self.listener.clone()
}
}
#[pin_project(PinnedDrop)]
pub struct UdpStream {
socket: UdpSocket,
socket: Arc<UdpSocket>,
peer: SocketAddr,
#[pin]
deadline: Option<Sleep>,
@ -144,7 +140,7 @@ pub async fn run_server(
.await
.with_context(|| format!("Cannot create UDP server {:?}", bind))?;
let udp_server = UdpServer::new(listener, timeout);
let udp_server = UdpServer::new(Arc::new(listener), timeout);
let stream = stream::unfold(udp_server, |mut server| async {
loop {
server.clean_dead_keys();