From f3cb84e5c47e70edeb32a3e6688e8f81ac539671 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Thu, 25 May 2023 22:12:52 +0900 Subject: [PATCH] indicate socket creating fail --- tuic-server/src/main.rs | 2 ++ tuic-server/src/server.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tuic-server/src/main.rs b/tuic-server/src/main.rs index 1b8d039..3a5e6c0 100644 --- a/tuic-server/src/main.rs +++ b/tuic-server/src/main.rs @@ -64,6 +64,8 @@ pub enum Error { AuthFailed(Uuid), #[error("received packet from unexpected source")] UnexpectedPacketSource, + #[error("create UDP session socket failed: {0}")] + CreateUdpSessionSocket(IoError), #[error("{0} resolved to {1} but IPv6 UDP relay disabled")] UdpRelayIpv6Disabled(Address, SocketAddr), } diff --git a/tuic-server/src/server.rs b/tuic-server/src/server.rs index 5138830..184b254 100644 --- a/tuic-server/src/server.rs +++ b/tuic-server/src/server.rs @@ -492,14 +492,18 @@ impl Connection { (session.socket_v4.clone(), session.socket_v6.clone()) } Entry::Vacant(entry) => { - let session = entry - .insert(UdpSession::new(assoc_id, self.clone(), self.udp_relay_ipv6).await?); + let session = entry.insert( + UdpSession::new(assoc_id, self.clone(), self.udp_relay_ipv6) + .await + .map_err(Error::CreateUdpSessionSocket)?, + ); + (session.socket_v4.clone(), session.socket_v6.clone()) } }; let Some(socket_addr) = resolve_dns(&addr).await?.next() else { - Err(IoError::new(ErrorKind::NotFound, "no address resolved"))? + return Err(Error::from(IoError::new(ErrorKind::NotFound, "no address resolved"))); }; let socket = match socket_addr { @@ -588,7 +592,7 @@ struct UdpSession { } impl UdpSession { - async fn new(assoc_id: u16, conn: Connection, udp_relay_ipv6: bool) -> Result { + async fn new(assoc_id: u16, conn: Connection, udp_relay_ipv6: bool) -> Result { let socket_v4 = Arc::new(UdpSocket::bind(SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))).await?); let socket_v6 = if udp_relay_ipv6 {