diff --git a/server/src/connection/dispatch.rs b/server/src/connection/dispatch.rs index 1f6add8..6b5ef8d 100644 --- a/server/src/connection/dispatch.rs +++ b/server/src/connection/dispatch.rs @@ -1,4 +1,4 @@ -use super::{task, Connection, RestoreIpv4, UdpPacketSource}; +use super::{task, Connection, UdpPacketSource}; use bytes::Bytes; use quinn::{RecvStream, SendStream, VarInt}; use std::io::Error as IoError; @@ -7,7 +7,7 @@ use tuic_protocol::{Address, Command}; impl Connection { pub async fn process_uni_stream(&self, mut stream: RecvStream) -> Result<(), DispatchError> { - let rmt_addr = self.controller.remote_address().restore_ipv4(); + let rmt_addr = self.controller.remote_address(); let cmd = Command::read_from(&mut stream).await?; if let Command::Authenticate { digest } = cmd { @@ -87,7 +87,7 @@ impl Connection { mut recv: RecvStream, ) -> Result<(), DispatchError> { let cmd = Command::read_from(&mut recv).await?; - let rmt_addr = self.controller.remote_address().restore_ipv4(); + let rmt_addr = self.controller.remote_address(); if self.is_authenticated.clone().await { match cmd { @@ -113,7 +113,7 @@ impl Connection { pub async fn process_datagram(&self, datagram: Bytes) -> Result<(), DispatchError> { let cmd = Command::read_from(&mut datagram.as_ref()).await?; - let rmt_addr = self.controller.remote_address().restore_ipv4(); + let rmt_addr = self.controller.remote_address(); let cmd_len = cmd.serialized_len(); if self.is_authenticated.clone().await { @@ -159,7 +159,7 @@ impl Connection { pkt: Bytes, addr: Address, ) -> Result<(), DispatchError> { - let rmt_addr = self.controller.remote_address().restore_ipv4(); + let rmt_addr = self.controller.remote_address(); let dst_addr = addr.to_string(); match self.udp_packet_from.check().unwrap() { diff --git a/server/src/connection/mod.rs b/server/src/connection/mod.rs index 258e556..a4c8ff0 100644 --- a/server/src/connection/mod.rs +++ b/server/src/connection/mod.rs @@ -12,7 +12,6 @@ use quinn::{ use std::{ collections::HashSet, future::Future, - net::{IpAddr, SocketAddr}, pin::Pin, sync::{ atomic::{AtomicBool, Ordering}, @@ -44,7 +43,7 @@ impl Connection { auth_timeout: Duration, max_pkt_size: usize, ) { - let rmt_addr = conn.remote_address().restore_ipv4(); + let rmt_addr = conn.remote_address(); match conn.await { Ok(NewConnection { @@ -112,7 +111,7 @@ impl Connection { conn.controller .close(err.as_error_code(), err.to_string().as_bytes()); - let rmt_addr = conn.controller.remote_address().restore_ipv4(); + let rmt_addr = conn.controller.remote_address(); log::error!("[{rmt_addr}] {err}"); } } @@ -137,7 +136,7 @@ impl Connection { conn.controller .close(err.as_error_code(), err.to_string().as_bytes()); - let rmt_addr = conn.controller.remote_address().restore_ipv4(); + let rmt_addr = conn.controller.remote_address(); log::error!("[{rmt_addr}] {err}"); } } @@ -159,7 +158,7 @@ impl Connection { conn.controller .close(err.as_error_code(), err.to_string().as_bytes()); - let rmt_addr = conn.controller.remote_address().restore_ipv4(); + let rmt_addr = conn.controller.remote_address(); log::error!("[{rmt_addr}] {err}"); } } @@ -183,7 +182,7 @@ impl Connection { conn.controller .close(err.as_error_code(), err.to_string().as_bytes()); - let rmt_addr = conn.controller.remote_address().restore_ipv4(); + let rmt_addr = conn.controller.remote_address(); log::error!("[{rmt_addr}] {err}"); } } @@ -208,7 +207,7 @@ impl Connection { .close(err.as_error_code(), err.to_string().as_bytes()); self.is_authenticated.wake(); - let rmt_addr = self.controller.remote_address().restore_ipv4(); + let rmt_addr = self.controller.remote_address(); log::error!("[{rmt_addr}] {err}"); Err(ConnectionError::LocallyClosed) @@ -257,19 +256,3 @@ impl Future for IsClosed { } } } - -pub trait RestoreIpv4 { - fn restore_ipv4(self) -> SocketAddr; -} - -impl RestoreIpv4 for SocketAddr { - fn restore_ipv4(self) -> Self { - if let IpAddr::V6(ip) = self.ip() { - if let Some(ip) = ip.to_ipv4() { - return Self::from((ip, self.port())); - } - } - - self - } -}