This commit is contained in:
Σrebe - Romain GERARD 2023-10-31 08:43:24 +01:00
parent 48b18293a5
commit 8a5d89885a
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4
3 changed files with 8 additions and 18 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "wstunnel"
version = "7.8.1"
version = "7.8.2"
edition = "2021"
repository = "https://github.com/erebe/wstunnel.git"

View file

@ -5,14 +5,14 @@ use std::sync::Arc;
use std::time::Duration;
use super::{JwtTunnelConfig, JWT_DECODE};
use crate::{tcp, tls, LocalProtocol, WsServerConfig, udp};
use crate::{tcp, tls, udp, LocalProtocol, WsServerConfig};
use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{http, Body, Request, Response, StatusCode};
use jsonwebtoken::TokenData;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::{TcpListener};
use tokio::net::TcpListener;
use tokio::sync::oneshot;
use tracing::{error, info, span, warn, Instrument, Level, Span};
use url::Host;

View file

@ -9,17 +9,17 @@ use std::io;
use std::io::{Error, ErrorKind};
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use log::warn;
use std::pin::{pin, Pin};
use std::sync::{Arc, Weak};
use std::task::{ready, Poll};
use std::time::Duration;
use log::warn;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio::net::UdpSocket;
use tokio::sync::futures::Notified;
use tokio::sync::Notify;
use tokio::time::{Sleep, timeout};
use tokio::time::{timeout, Sleep};
use tracing::{debug, error, info};
use url::Host;
@ -248,11 +248,7 @@ impl AsyncWrite for MyUdpSocket {
}
}
pub async fn connect(
host: &Host<String>,
port: u16,
connect_timeout: Duration,
) -> anyhow::Result<MyUdpSocket> {
pub async fn connect(host: &Host<String>, port: u16, connect_timeout: Duration) -> anyhow::Result<MyUdpSocket> {
info!("Opening UDP connection to {}:{}", host, port);
let socket_addrs: Vec<SocketAddr> = match host {
@ -264,7 +260,6 @@ pub async fn connect(
Host::Ipv6(ip) => vec![SocketAddr::V6(SocketAddrV6::new(*ip, port, 0, 0))],
};
let mut cnx = None;
let mut last_err = None;
for addr in socket_addrs {
@ -280,7 +275,7 @@ pub async fn connect(
Err(err) => {
warn!("cannot bind udp socket {:?}", err);
continue;
},
}
};
match timeout(connect_timeout, socket.connect(addr)).await {
@ -304,12 +299,7 @@ pub async fn connect(
if let Some(cnx) = cnx {
Ok(MyUdpSocket::new(Arc::new(cnx)))
} else {
Err(anyhow!(
"Cannot connect to udp peer {}:{} reason {:?}",
host,
port,
last_err
))
Err(anyhow!("Cannot connect to udp peer {}:{} reason {:?}", host, port, last_err))
}
}