SocketAddr issues

This commit is contained in:
ssrlive 2023-03-23 20:00:59 +08:00
parent 6fe44f8055
commit d4eed896bb
3 changed files with 13 additions and 14 deletions

View file

@ -165,7 +165,7 @@ impl TcpProxy for HttpConnection {
} }
pub struct HttpManager { pub struct HttpManager {
server: std::net::SocketAddr, server: SocketAddr,
credentials: Option<Credentials>, credentials: Option<Credentials>,
} }

View file

@ -292,7 +292,7 @@ impl TcpProxy for SocksConnection {
} }
pub struct Socks5Manager { pub struct Socks5Manager {
server: std::net::SocketAddr, server: SocketAddr,
credentials: Option<Credentials>, credentials: Option<Credentials>,
} }

View file

@ -14,7 +14,7 @@ use smoltcp::wire::{
UdpPacket, UdpPacket,
}; };
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::From; use std::convert::{From, TryFrom};
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::net::Shutdown::Both; use std::net::Shutdown::Both;
@ -43,17 +43,18 @@ pub(crate) struct Destination {
pub(crate) port: u16, pub(crate) port: u16,
} }
impl From<Destination> for SocketAddr { impl TryFrom<Destination> for SocketAddr {
fn from(value: Destination) -> Self { type Error = Error;
SocketAddr::new( fn try_from(value: Destination) -> Result<Self, Self::Error> {
Ok(SocketAddr::new(
match value.host { match value.host {
DestinationHost::Address(addr) => addr, DestinationHost::Address(addr) => addr,
DestinationHost::Hostname(_) => { DestinationHost::Hostname(e) => {
panic!("Failed to convert hostname destination into socket address") return Err(e.into());
} }
}, },
value.port, value.port,
) ))
} }
} }
@ -74,7 +75,7 @@ impl Display for Destination {
#[derive(Hash, Clone, Eq, PartialEq)] #[derive(Hash, Clone, Eq, PartialEq)]
pub(crate) struct Connection { pub(crate) struct Connection {
pub(crate) src: std::net::SocketAddr, pub(crate) src: SocketAddr,
pub(crate) dst: Destination, pub(crate) dst: Destination,
pub(crate) proto: u8, pub(crate) proto: u8,
} }
@ -396,10 +397,8 @@ impl<'a> TunToProxy<'a> {
smoltcp::socket::tcp::SocketBuffer::new(vec![0; 4096]), smoltcp::socket::tcp::SocketBuffer::new(vec![0; 4096]),
); );
socket.set_ack_delay(None); socket.set_ack_delay(None);
let dst = connection.dst.clone(); let dst = SocketAddr::try_from(connection.dst.clone()).unwrap();
socket socket.listen(dst).unwrap();
.listen(<Destination as Into<SocketAddr>>::into(dst))
.unwrap();
let handle = self.sockets.add(socket); let handle = self.sockets.add(socket);
let client = TcpStream::connect(server).unwrap(); let client = TcpStream::connect(server).unwrap();