Add typealias socks5 udp

This commit is contained in:
Σrebe - Romain GERARD 2024-01-09 21:04:46 +01:00
parent f183e648a7
commit db6f3ea3ce
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4

View file

@ -24,13 +24,15 @@ use tokio::time::Interval;
use tracing::{debug, error, info}; use tracing::{debug, error, info};
use url::Host; use url::Host;
type PeerMapKey = (SocketAddr, TargetAddr);
struct IoInner { struct IoInner {
sender: mpsc::Sender<Bytes>, sender: mpsc::Sender<Bytes>,
} }
struct Socks5UdpServer { struct Socks5UdpServer {
listener: Arc<UdpSocket>, listener: Arc<UdpSocket>,
peers: HashMap<(SocketAddr, TargetAddr), Pin<Arc<IoInner>>, ahash::RandomState>, peers: HashMap<PeerMapKey, Pin<Arc<IoInner>>, ahash::RandomState>,
keys_to_delete: Arc<RwLock<Vec<(SocketAddr, TargetAddr)>>>, keys_to_delete: Arc<RwLock<Vec<PeerMapKey>>>,
cnx_timeout: Option<Duration>, cnx_timeout: Option<Duration>,
} }
@ -82,7 +84,7 @@ pub struct Socks5UdpStream {
pub watchdog_deadline: Option<Interval>, pub watchdog_deadline: Option<Interval>,
data_read_before_deadline: bool, data_read_before_deadline: bool,
io: Pin<Arc<IoInner>>, io: Pin<Arc<IoInner>>,
keys_to_delete: Weak<RwLock<Vec<(SocketAddr, TargetAddr)>>>, keys_to_delete: Weak<RwLock<Vec<PeerMapKey>>>,
} }
#[pinned_drop] #[pinned_drop]
@ -100,7 +102,7 @@ impl Socks5UdpStream {
peer: SocketAddr, peer: SocketAddr,
destination: TargetAddr, destination: TargetAddr,
watchdog_deadline: Option<Duration>, watchdog_deadline: Option<Duration>,
keys_to_delete: Weak<RwLock<Vec<(SocketAddr, TargetAddr)>>>, keys_to_delete: Weak<RwLock<Vec<PeerMapKey>>>,
) -> (Self, Pin<Arc<IoInner>>) { ) -> (Self, Pin<Arc<IoInner>>) {
let (tx, rx) = mpsc::channel(1024); let (tx, rx) = mpsc::channel(1024);
let io = Arc::pin(IoInner { sender: tx }); let io = Arc::pin(IoInner { sender: tx });