1
0

indicate socket creating fail

This commit is contained in:
EAimTY 2023-05-25 22:12:52 +09:00
parent 079e724948
commit f3cb84e5c4
2 changed files with 10 additions and 4 deletions

View File

@ -64,6 +64,8 @@ pub enum Error {
AuthFailed(Uuid), AuthFailed(Uuid),
#[error("received packet from unexpected source")] #[error("received packet from unexpected source")]
UnexpectedPacketSource, UnexpectedPacketSource,
#[error("create UDP session socket failed: {0}")]
CreateUdpSessionSocket(IoError),
#[error("{0} resolved to {1} but IPv6 UDP relay disabled")] #[error("{0} resolved to {1} but IPv6 UDP relay disabled")]
UdpRelayIpv6Disabled(Address, SocketAddr), UdpRelayIpv6Disabled(Address, SocketAddr),
} }

View File

@ -492,14 +492,18 @@ impl Connection {
(session.socket_v4.clone(), session.socket_v6.clone()) (session.socket_v4.clone(), session.socket_v6.clone())
} }
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
let session = entry let session = entry.insert(
.insert(UdpSession::new(assoc_id, self.clone(), self.udp_relay_ipv6).await?); UdpSession::new(assoc_id, self.clone(), self.udp_relay_ipv6)
.await
.map_err(Error::CreateUdpSessionSocket)?,
);
(session.socket_v4.clone(), session.socket_v6.clone()) (session.socket_v4.clone(), session.socket_v6.clone())
} }
}; };
let Some(socket_addr) = resolve_dns(&addr).await?.next() else { 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 { let socket = match socket_addr {
@ -588,7 +592,7 @@ struct UdpSession {
} }
impl UdpSession { impl UdpSession {
async fn new(assoc_id: u16, conn: Connection, udp_relay_ipv6: bool) -> Result<Self, Error> { async fn new(assoc_id: u16, conn: Connection, udp_relay_ipv6: bool) -> Result<Self, IoError> {
let socket_v4 = let socket_v4 =
Arc::new(UdpSocket::bind(SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))).await?); Arc::new(UdpSocket::bind(SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))).await?);
let socket_v6 = if udp_relay_ipv6 { let socket_v6 = if udp_relay_ipv6 {