1
0

remove RestoreIpv4

This commit is contained in:
EAimTY 2022-07-01 23:49:13 +09:00
parent 63c7ee3e1d
commit fc5fda4d4a
2 changed files with 11 additions and 28 deletions

View File

@ -1,4 +1,4 @@
use super::{task, Connection, RestoreIpv4, UdpPacketSource}; use super::{task, Connection, UdpPacketSource};
use bytes::Bytes; use bytes::Bytes;
use quinn::{RecvStream, SendStream, VarInt}; use quinn::{RecvStream, SendStream, VarInt};
use std::io::Error as IoError; use std::io::Error as IoError;
@ -7,7 +7,7 @@ use tuic_protocol::{Address, Command};
impl Connection { impl Connection {
pub async fn process_uni_stream(&self, mut stream: RecvStream) -> Result<(), DispatchError> { 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?; let cmd = Command::read_from(&mut stream).await?;
if let Command::Authenticate { digest } = cmd { if let Command::Authenticate { digest } = cmd {
@ -87,7 +87,7 @@ impl Connection {
mut recv: RecvStream, mut recv: RecvStream,
) -> Result<(), DispatchError> { ) -> Result<(), DispatchError> {
let cmd = Command::read_from(&mut recv).await?; 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 { if self.is_authenticated.clone().await {
match cmd { match cmd {
@ -113,7 +113,7 @@ impl Connection {
pub async fn process_datagram(&self, datagram: Bytes) -> Result<(), DispatchError> { pub async fn process_datagram(&self, datagram: Bytes) -> Result<(), DispatchError> {
let cmd = Command::read_from(&mut datagram.as_ref()).await?; 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(); let cmd_len = cmd.serialized_len();
if self.is_authenticated.clone().await { if self.is_authenticated.clone().await {
@ -159,7 +159,7 @@ impl Connection {
pkt: Bytes, pkt: Bytes,
addr: Address, addr: Address,
) -> Result<(), DispatchError> { ) -> Result<(), DispatchError> {
let rmt_addr = self.controller.remote_address().restore_ipv4(); let rmt_addr = self.controller.remote_address();
let dst_addr = addr.to_string(); let dst_addr = addr.to_string();
match self.udp_packet_from.check().unwrap() { match self.udp_packet_from.check().unwrap() {

View File

@ -12,7 +12,6 @@ use quinn::{
use std::{ use std::{
collections::HashSet, collections::HashSet,
future::Future, future::Future,
net::{IpAddr, SocketAddr},
pin::Pin, pin::Pin,
sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
@ -44,7 +43,7 @@ impl Connection {
auth_timeout: Duration, auth_timeout: Duration,
max_pkt_size: usize, max_pkt_size: usize,
) { ) {
let rmt_addr = conn.remote_address().restore_ipv4(); let rmt_addr = conn.remote_address();
match conn.await { match conn.await {
Ok(NewConnection { Ok(NewConnection {
@ -112,7 +111,7 @@ impl Connection {
conn.controller conn.controller
.close(err.as_error_code(), err.to_string().as_bytes()); .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}"); log::error!("[{rmt_addr}] {err}");
} }
} }
@ -137,7 +136,7 @@ impl Connection {
conn.controller conn.controller
.close(err.as_error_code(), err.to_string().as_bytes()); .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}"); log::error!("[{rmt_addr}] {err}");
} }
} }
@ -159,7 +158,7 @@ impl Connection {
conn.controller conn.controller
.close(err.as_error_code(), err.to_string().as_bytes()); .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}"); log::error!("[{rmt_addr}] {err}");
} }
} }
@ -183,7 +182,7 @@ impl Connection {
conn.controller conn.controller
.close(err.as_error_code(), err.to_string().as_bytes()); .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}"); log::error!("[{rmt_addr}] {err}");
} }
} }
@ -208,7 +207,7 @@ impl Connection {
.close(err.as_error_code(), err.to_string().as_bytes()); .close(err.as_error_code(), err.to_string().as_bytes());
self.is_authenticated.wake(); 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}"); log::error!("[{rmt_addr}] {err}");
Err(ConnectionError::LocallyClosed) 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
}
}