From ca1834f977ebf813fbbd8cb44efffe81c5e1bc8e Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 29 Apr 2022 20:32:43 +0800 Subject: [PATCH] Refactor --- leaf/Cargo.toml | 2 + leaf/src/app/outbound/manager.rs | 18 +++++-- leaf/src/app/outbound/mod.rs | 4 +- leaf/src/app/outbound/plugin.rs | 44 +++++---------- leaf/src/proxy/amux/inbound/tcp.rs | 7 +-- leaf/src/proxy/amux/outbound/tcp.rs | 6 +-- leaf/src/proxy/chain/inbound/tcp.rs | 7 +-- leaf/src/proxy/chain/inbound/udp.rs | 7 +-- leaf/src/proxy/chain/outbound/tcp.rs | 6 +-- leaf/src/proxy/chain/outbound/udp.rs | 7 +-- leaf/src/proxy/direct/tcp.rs | 6 +-- leaf/src/proxy/direct/udp.rs | 7 +-- leaf/src/proxy/drop/tcp.rs | 6 +-- leaf/src/proxy/drop/udp.rs | 7 +-- leaf/src/proxy/failover/tcp.rs | 6 +-- leaf/src/proxy/failover/udp.rs | 7 +-- leaf/src/proxy/inbound.rs | 14 ++--- leaf/src/proxy/mod.rs | 62 ++++++---------------- leaf/src/proxy/null/outbound/tcp.rs | 6 +-- leaf/src/proxy/null/outbound/udp.rs | 7 +-- leaf/src/proxy/outbound.rs | 13 ++--- leaf/src/proxy/quic/inbound/udp.rs | 7 +-- leaf/src/proxy/quic/outbound/tcp.rs | 6 +-- leaf/src/proxy/redirect/tcp.rs | 6 +-- leaf/src/proxy/redirect/udp.rs | 7 +-- leaf/src/proxy/select/tcp.rs | 10 ++-- leaf/src/proxy/select/udp.rs | 16 ++---- leaf/src/proxy/shadowsocks/inbound/tcp.rs | 7 +-- leaf/src/proxy/shadowsocks/inbound/udp.rs | 10 +--- leaf/src/proxy/shadowsocks/outbound/tcp.rs | 6 +-- leaf/src/proxy/shadowsocks/outbound/udp.rs | 7 +-- leaf/src/proxy/socks/inbound/tcp.rs | 7 +-- leaf/src/proxy/socks/inbound/udp.rs | 7 +-- leaf/src/proxy/socks/outbound/tcp.rs | 6 +-- leaf/src/proxy/socks/outbound/udp.rs | 7 +-- leaf/src/proxy/static/tcp.rs | 6 +-- leaf/src/proxy/static/udp.rs | 7 +-- leaf/src/proxy/tls/inbound/tcp.rs | 7 +-- leaf/src/proxy/tls/outbound/tcp.rs | 6 +-- leaf/src/proxy/trojan/inbound/tcp.rs | 7 +-- leaf/src/proxy/trojan/outbound/tcp.rs | 6 +-- leaf/src/proxy/trojan/outbound/udp.rs | 7 +-- leaf/src/proxy/tryall/tcp.rs | 6 +-- leaf/src/proxy/tryall/udp.rs | 7 +-- leaf/src/proxy/ws/inbound/tcp.rs | 7 +-- leaf/src/proxy/ws/outbound/tcp.rs | 6 +-- 46 files changed, 138 insertions(+), 292 deletions(-) diff --git a/leaf/Cargo.toml b/leaf/Cargo.toml index 80b5432..1416032 100644 --- a/leaf/Cargo.toml +++ b/leaf/Cargo.toml @@ -24,6 +24,7 @@ default-ring = [ "outbound-quic", "api", "stat", + # "plugin", ] default-openssl = [ @@ -109,6 +110,7 @@ inbound-quic = ["quinn", "rustls", "webpki-roots"] inbound-tls = [] inbound-chain = [] +plugin = [] stat = [] api = ["warp"] auto-reload = ["notify"] diff --git a/leaf/src/app/outbound/manager.rs b/leaf/src/app/outbound/manager.rs index 41f7c5d..8cb9499 100644 --- a/leaf/src/app/outbound/manager.rs +++ b/leaf/src/app/outbound/manager.rs @@ -56,6 +56,7 @@ use super::selector::OutboundSelector; pub struct OutboundManager { handlers: HashMap, + #[cfg(feature = "plugin")] external_handlers: super::plugin::ExternalHandlers, selectors: Arc, default_handler: Option, @@ -68,7 +69,7 @@ impl OutboundManager { outbounds: &protobuf::RepeatedField, dns_client: SyncDnsClient, handlers: &mut HashMap, - external_handlers: &mut super::plugin::ExternalHandlers, + #[cfg(feature = "plugin")] external_handlers: &mut super::plugin::ExternalHandlers, default_handler: &mut Option, abort_handles: &mut Vec, ) -> Result<()> { @@ -564,6 +565,7 @@ impl OutboundManager { settings.actors.join(",") ); } + #[cfg(feature = "plugin")] "plugin" => { let settings = config::PluginOutboundSettings::parse_from_bytes(&outbound.settings) @@ -601,7 +603,7 @@ impl OutboundManager { fn load_selectors( outbounds: &protobuf::RepeatedField, handlers: &mut HashMap, - external_handlers: &mut super::plugin::ExternalHandlers, + #[cfg(feature = "plugin")] external_handlers: &mut super::plugin::ExternalHandlers, selectors: &mut super::Selectors, ) -> Result<()> { // FIXME a better way to find outbound deps? @@ -684,6 +686,7 @@ impl OutboundManager { // Load new outbounds. let mut handlers: HashMap = HashMap::new(); + #[cfg(feature = "plugin")] let mut external_handlers = super::plugin::ExternalHandlers::new(); let mut default_handler: Option = None; let mut abort_handles: Vec = Vec::new(); @@ -693,6 +696,7 @@ impl OutboundManager { outbounds, dns_client.clone(), &mut handlers, + #[cfg(feature = "plugin")] &mut external_handlers, &mut default_handler, &mut abort_handles, @@ -700,6 +704,7 @@ impl OutboundManager { Self::load_selectors( outbounds, &mut handlers, + #[cfg(feature = "plugin")] &mut external_handlers, &mut selectors, )?; @@ -722,7 +727,10 @@ impl OutboundManager { } self.handlers = handlers; - self.external_handlers = external_handlers; + #[cfg(feature = "plugin")] + { + self.external_handlers = external_handlers; + } self.selectors = Arc::new(selectors); self.default_handler = default_handler; self.abort_handles = abort_handles; @@ -734,6 +742,7 @@ impl OutboundManager { dns_client: SyncDnsClient, ) -> Result { let mut handlers: HashMap = HashMap::new(); + #[cfg(feature = "plugin")] let mut external_handlers = super::plugin::ExternalHandlers::new(); let mut default_handler: Option = None; let mut abort_handles: Vec = Vec::new(); @@ -743,6 +752,7 @@ impl OutboundManager { outbounds, dns_client.clone(), &mut handlers, + #[cfg(feature = "plugin")] &mut external_handlers, &mut default_handler, &mut abort_handles, @@ -750,12 +760,14 @@ impl OutboundManager { Self::load_selectors( outbounds, &mut handlers, + #[cfg(feature = "plugin")] &mut external_handlers, &mut selectors, )?; } Ok(OutboundManager { handlers, + #[cfg(feature = "plugin")] external_handlers, selectors: Arc::new(selectors), default_handler, diff --git a/leaf/src/app/outbound/mod.rs b/leaf/src/app/outbound/mod.rs index 1dec0e8..9d45794 100644 --- a/leaf/src/app/outbound/mod.rs +++ b/leaf/src/app/outbound/mod.rs @@ -4,8 +4,10 @@ use std::sync::Arc; use tokio::sync::RwLock; pub mod manager; -pub mod plugin; pub mod selector; pub mod selector_cache; +#[cfg(feature = "plugin")] +pub mod plugin; + pub type Selectors = HashMap>>; diff --git a/leaf/src/app/outbound/plugin.rs b/leaf/src/app/outbound/plugin.rs index 125d07a..8c16ee2 100644 --- a/leaf/src/app/outbound/plugin.rs +++ b/leaf/src/app/outbound/plugin.rs @@ -23,22 +23,17 @@ pub trait PluginRegistrar { } pub trait ExternalTcpOutboundHandler: Send + Sync + Unpin { - type Stream; - fn connect_addr(&self) -> Option; fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> BorrowingFfiFuture<'a, io::Result>; + stream: Option, + ) -> BorrowingFfiFuture<'a, io::Result>; } -pub type AnyExternalTcpOutboundHandler = Arc>; +pub type AnyExternalTcpOutboundHandler = Arc; pub trait ExternalUdpOutboundHandler: Send + Sync + Unpin { - type Stream; - type Datagram; - fn connect_addr(&self) -> Option; fn transport_type(&self) -> DatagramTransportType; @@ -46,8 +41,8 @@ pub trait ExternalUdpOutboundHandler: Send + Sync + Unpin { fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> BorrowingFfiFuture<'a, io::Result>; + transport: Option, + ) -> BorrowingFfiFuture<'a, io::Result>; } struct PluginRegistrarImpl { @@ -98,8 +93,6 @@ impl TcpOutboundHandlerProxy { } impl ExternalTcpOutboundHandler for TcpOutboundHandlerProxy { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { self.handler.connect_addr() } @@ -107,8 +100,8 @@ impl ExternalTcpOutboundHandler for TcpOutboundHandlerProxy { fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> BorrowingFfiFuture<'a, io::Result> { + stream: Option, + ) -> BorrowingFfiFuture<'a, io::Result> { self.handler.handle(sess, stream) } } @@ -125,9 +118,6 @@ impl UdpOutboundHandlerProxy { } impl ExternalUdpOutboundHandler for UdpOutboundHandlerProxy { - type Stream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { self.handler.connect_addr() } @@ -139,14 +129,13 @@ impl ExternalUdpOutboundHandler for UdpOutboundHandlerProxy { fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> BorrowingFfiFuture<'a, io::Result> { + transport: Option, + ) -> BorrowingFfiFuture<'a, io::Result> { self.handler.handle(sess, transport) } } -pub type AnyExternalUdpOutboundHandler = - Arc>; +pub type AnyExternalUdpOutboundHandler = Arc; #[derive(Default)] pub struct ExternalHandlers { @@ -193,8 +182,6 @@ pub struct ExternalTcpOutboundHandlerProxy(pub AnyExternalTcpOutboundHandler); #[async_trait] impl TcpOutboundHandler for ExternalTcpOutboundHandlerProxy { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { self.0.connect_addr() } @@ -202,8 +189,8 @@ impl TcpOutboundHandler for ExternalTcpOutboundHandlerProxy { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { self.0.handle(sess, stream).await } } @@ -212,9 +199,6 @@ pub struct ExternalUdpOutboundHandlerProxy(pub AnyExternalUdpOutboundHandler); #[async_trait] impl UdpOutboundHandler for ExternalUdpOutboundHandlerProxy { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { self.0.connect_addr() } @@ -226,8 +210,8 @@ impl UdpOutboundHandler for ExternalUdpOutboundHandlerProxy { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { self.0.handle(sess, transport).await } } diff --git a/leaf/src/proxy/amux/inbound/tcp.rs b/leaf/src/proxy/amux/inbound/tcp.rs index 2e7fd9c..bc3f286 100644 --- a/leaf/src/proxy/amux/inbound/tcp.rs +++ b/leaf/src/proxy/amux/inbound/tcp.rs @@ -46,14 +46,11 @@ pub struct Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, mut sess: Session, - mut stream: Self::TStream, - ) -> std::io::Result> { + mut stream: AnyStream, + ) -> std::io::Result { for (_, a) in self.actors.iter().enumerate() { match TcpInboundHandler::handle(a.as_ref(), sess, stream).await? { InboundTransport::Stream(new_stream, new_sess) => { diff --git a/leaf/src/proxy/amux/outbound/tcp.rs b/leaf/src/proxy/amux/outbound/tcp.rs index 64041d6..59640f5 100644 --- a/leaf/src/proxy/amux/outbound/tcp.rs +++ b/leaf/src/proxy/amux/outbound/tcp.rs @@ -136,8 +136,6 @@ impl Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::NoConnect) } @@ -145,8 +143,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { Ok(Box::new(self.manager.new_stream(sess).await?)) } } diff --git a/leaf/src/proxy/chain/inbound/tcp.rs b/leaf/src/proxy/chain/inbound/tcp.rs index a1369ff..2e68c41 100644 --- a/leaf/src/proxy/chain/inbound/tcp.rs +++ b/leaf/src/proxy/chain/inbound/tcp.rs @@ -12,14 +12,11 @@ pub struct Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, mut sess: Session, - mut stream: Self::TStream, - ) -> std::io::Result> { + mut stream: AnyStream, + ) -> std::io::Result { for (i, a) in self.actors.iter().enumerate() { let transport = TcpInboundHandler::handle(a.as_ref(), sess.clone(), stream).await?; match transport { diff --git a/leaf/src/proxy/chain/inbound/udp.rs b/leaf/src/proxy/chain/inbound/udp.rs index 74cae8d..4631c8f 100644 --- a/leaf/src/proxy/chain/inbound/udp.rs +++ b/leaf/src/proxy/chain/inbound/udp.rs @@ -12,13 +12,10 @@ pub struct Handler { #[async_trait] impl UdpInboundHandler for Handler { - type UStream = AnyStream; - type UDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, - mut socket: Self::UDatagram, - ) -> io::Result> { + mut socket: AnyInboundDatagram, + ) -> io::Result { let mut sess: Option = None; for (i, a) in self.actors.iter().enumerate() { let transport = UdpInboundHandler::handle(a.as_ref(), socket).await?; diff --git a/leaf/src/proxy/chain/outbound/tcp.rs b/leaf/src/proxy/chain/outbound/tcp.rs index 356c0ed..1094ec0 100644 --- a/leaf/src/proxy/chain/outbound/tcp.rs +++ b/leaf/src/proxy/chain/outbound/tcp.rs @@ -34,8 +34,6 @@ impl Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { for a in self.actors.iter() { if let Some(addr) = TcpOutboundHandler::connect_addr(a.as_ref()) { @@ -48,8 +46,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - mut stream: Option, - ) -> io::Result { + mut stream: Option, + ) -> io::Result { match self.connect_addr() { Some(OutboundConnect::NoConnect) => (), _ => { diff --git a/leaf/src/proxy/chain/outbound/udp.rs b/leaf/src/proxy/chain/outbound/udp.rs index 81d52d5..66db79b 100644 --- a/leaf/src/proxy/chain/outbound/udp.rs +++ b/leaf/src/proxy/chain/outbound/udp.rs @@ -115,9 +115,6 @@ impl Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { for a in self.actors.iter() { if let Some(addr) = UdpOutboundHandler::connect_addr(a.as_ref()) { @@ -139,8 +136,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { match transport { Some(transport) => match transport { OutboundTransport::Datagram(dgram) => self.handle(sess, None, Some(dgram)).await, diff --git a/leaf/src/proxy/direct/tcp.rs b/leaf/src/proxy/direct/tcp.rs index efefe50..22457dc 100644 --- a/leaf/src/proxy/direct/tcp.rs +++ b/leaf/src/proxy/direct/tcp.rs @@ -8,8 +8,6 @@ pub struct Handler; #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Direct) } @@ -17,8 +15,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input")) } } diff --git a/leaf/src/proxy/direct/udp.rs b/leaf/src/proxy/direct/udp.rs index e588ec7..823b2ff 100644 --- a/leaf/src/proxy/direct/udp.rs +++ b/leaf/src/proxy/direct/udp.rs @@ -8,9 +8,6 @@ pub struct Handler; #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Direct) } @@ -22,8 +19,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { if let Some(OutboundTransport::Datagram(dgram)) = transport { Ok(dgram) } else { diff --git a/leaf/src/proxy/drop/tcp.rs b/leaf/src/proxy/drop/tcp.rs index eee9aac..5a3b388 100644 --- a/leaf/src/proxy/drop/tcp.rs +++ b/leaf/src/proxy/drop/tcp.rs @@ -8,8 +8,6 @@ pub struct Handler; #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { None } @@ -17,8 +15,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "dropped")) } } diff --git a/leaf/src/proxy/drop/udp.rs b/leaf/src/proxy/drop/udp.rs index a840431..0e4eaa7 100644 --- a/leaf/src/proxy/drop/udp.rs +++ b/leaf/src/proxy/drop/udp.rs @@ -8,9 +8,6 @@ pub struct Handler; #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { None } @@ -22,8 +19,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - _transport: Option>, - ) -> io::Result { + _transport: Option, + ) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "dropped")) } } diff --git a/leaf/src/proxy/failover/tcp.rs b/leaf/src/proxy/failover/tcp.rs index 434b67b..dc11ca6 100644 --- a/leaf/src/proxy/failover/tcp.rs +++ b/leaf/src/proxy/failover/tcp.rs @@ -221,8 +221,6 @@ impl Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { None } @@ -230,8 +228,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { if let Some(task) = self.health_check_task.lock().await.take() { tokio::spawn(task); } diff --git a/leaf/src/proxy/failover/udp.rs b/leaf/src/proxy/failover/udp.rs index d6d7806..cd98d1a 100644 --- a/leaf/src/proxy/failover/udp.rs +++ b/leaf/src/proxy/failover/udp.rs @@ -239,9 +239,6 @@ impl Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { None } @@ -253,8 +250,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _transport: Option>, - ) -> io::Result { + _transport: Option, + ) -> io::Result { if let Some(task) = self.health_check_task.lock().await.take() { tokio::spawn(task); } diff --git a/leaf/src/proxy/inbound.rs b/leaf/src/proxy/inbound.rs index 82dd3d5..e1220d6 100644 --- a/leaf/src/proxy/inbound.rs +++ b/leaf/src/proxy/inbound.rs @@ -46,14 +46,11 @@ impl InboundHandler for Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, sess: Session, - stream: Self::TStream, - ) -> std::io::Result> { + stream: AnyStream, + ) -> std::io::Result { if let Some(handler) = &self.tcp_handler { handler.handle(sess, stream).await } else { @@ -64,13 +61,10 @@ impl TcpInboundHandler for Handler { #[async_trait] impl UdpInboundHandler for Handler { - type UStream = AnyStream; - type UDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, - socket: Self::UDatagram, - ) -> std::io::Result> { + socket: AnyInboundDatagram, + ) -> std::io::Result { if let Some(handler) = &self.udp_handler { handler.handle(socket).await } else { diff --git a/leaf/src/proxy/mod.rs b/leaf/src/proxy/mod.rs index 449ac50..44b323d 100644 --- a/leaf/src/proxy/mod.rs +++ b/leaf/src/proxy/mod.rs @@ -509,9 +509,7 @@ pub trait OutboundHandler: { } -pub type AnyOutboundHandler = Arc< - dyn OutboundHandler, ->; +pub type AnyOutboundHandler = Arc; #[derive(Debug, Clone)] pub enum OutboundConnect { @@ -522,23 +520,17 @@ pub enum OutboundConnect { /// An outbound handler for outgoing TCP conections. #[async_trait] -pub trait TcpOutboundHandler: Send + Sync + Unpin { - type Stream; - +pub trait TcpOutboundHandler: Send + Sync + Unpin { /// Returns the address which the underlying transport should /// communicate with. fn connect_addr(&self) -> Option; /// Handles a session with the given stream. On success, returns a /// stream wraps the incoming stream. - async fn handle<'a>( - &'a self, - sess: &'a Session, - stream: Option, - ) -> io::Result; + async fn handle<'a>(&'a self, sess: &'a Session, stream: Option) -> io::Result; } -type AnyTcpOutboundHandler = Box>; +type AnyTcpOutboundHandler = Box; /// An unreliable transport for outbound handlers. pub trait OutboundDatagram: Send + Unpin { @@ -573,10 +565,7 @@ pub trait OutboundDatagramSendHalf: Sync + Send + Unpin { /// An outbound handler for outgoing UDP connections. #[async_trait] -pub trait UdpOutboundHandler: Send + Sync + Unpin { - type UStream; - type Datagram; - +pub trait UdpOutboundHandler: Send + Sync + Unpin { /// Returns the address which the underlying transport should /// communicate with. fn connect_addr(&self) -> Option; @@ -594,12 +583,11 @@ pub trait UdpOutboundHandler: Send + Sync + Unpin { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result; + transport: Option>, + ) -> io::Result; } -type AnyUdpOutboundHandler = - Box>; +type AnyUdpOutboundHandler = Box; /// An outbound transport represents either a reliable or unreliable transport. pub enum OutboundTransport { @@ -618,45 +606,27 @@ pub trait InboundHandler: fn has_udp(&self) -> bool; } -pub type AnyInboundHandler = Arc< - dyn InboundHandler< - TStream = AnyStream, - TDatagram = AnyInboundDatagram, - UStream = AnyStream, - UDatagram = AnyInboundDatagram, - >, ->; +pub type AnyInboundHandler = Arc; /// An inbound handler for incoming TCP connections. #[async_trait] -pub trait TcpInboundHandler: Send + Sync + Unpin { - type TStream; - type TDatagram; - +pub trait TcpInboundHandler: Send + Sync + Unpin { async fn handle<'a>( &'a self, sess: Session, - stream: Self::TStream, - ) -> std::io::Result>; + stream: S, + ) -> std::io::Result>; } -pub type AnyTcpInboundHandler = - Arc>; +pub type AnyTcpInboundHandler = Arc; /// An inbound handler for incoming UDP connections. #[async_trait] -pub trait UdpInboundHandler: Send + Sync + Unpin { - type UStream; - type UDatagram; - - async fn handle<'a>( - &'a self, - socket: Self::UDatagram, - ) -> io::Result>; +pub trait UdpInboundHandler: Send + Sync + Unpin { + async fn handle<'a>(&'a self, socket: D) -> io::Result>; } -pub type AnyUdpInboundHandler = - Arc>; +pub type AnyUdpInboundHandler = Arc; /// An unreliable transport for inbound handlers. pub trait InboundDatagram: Send + Sync + Unpin { diff --git a/leaf/src/proxy/null/outbound/tcp.rs b/leaf/src/proxy/null/outbound/tcp.rs index 76243bd..c511292 100644 --- a/leaf/src/proxy/null/outbound/tcp.rs +++ b/leaf/src/proxy/null/outbound/tcp.rs @@ -10,8 +10,6 @@ pub struct Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { self.connect.clone() } @@ -19,8 +17,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "null handler")) } } diff --git a/leaf/src/proxy/null/outbound/udp.rs b/leaf/src/proxy/null/outbound/udp.rs index fff18f1..fa4360e 100644 --- a/leaf/src/proxy/null/outbound/udp.rs +++ b/leaf/src/proxy/null/outbound/udp.rs @@ -11,9 +11,6 @@ pub struct Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { self.connect.clone() } @@ -25,8 +22,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - _transport: Option>, - ) -> io::Result { + _transport: Option, + ) -> io::Result { Err(io::Error::new(io::ErrorKind::Other, "null handler")) } } diff --git a/leaf/src/proxy/outbound.rs b/leaf/src/proxy/outbound.rs index 3c9384b..62ce8dd 100644 --- a/leaf/src/proxy/outbound.rs +++ b/leaf/src/proxy/outbound.rs @@ -48,8 +48,6 @@ impl Color for Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { self.tcp_handler.connect_addr() } @@ -57,17 +55,14 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { self.tcp_handler.handle(sess, stream).await } } #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { self.udp_handler.connect_addr() } @@ -79,8 +74,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { self.udp_handler.handle(sess, transport).await } } diff --git a/leaf/src/proxy/quic/inbound/udp.rs b/leaf/src/proxy/quic/inbound/udp.rs index 2bb5ae6..40e29d7 100644 --- a/leaf/src/proxy/quic/inbound/udp.rs +++ b/leaf/src/proxy/quic/inbound/udp.rs @@ -140,13 +140,10 @@ impl Handler { #[async_trait] impl UdpInboundHandler for Handler { - type UStream = AnyStream; - type UDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, - socket: Self::UDatagram, - ) -> io::Result> { + socket: AnyInboundDatagram, + ) -> io::Result { let (cert, key) = fs::read(&self.certificate).and_then(|x| Ok((x, fs::read(&self.certificate_key)?)))?; diff --git a/leaf/src/proxy/quic/outbound/tcp.rs b/leaf/src/proxy/quic/outbound/tcp.rs index 41d5b14..ec59212 100644 --- a/leaf/src/proxy/quic/outbound/tcp.rs +++ b/leaf/src/proxy/quic/outbound/tcp.rs @@ -205,8 +205,6 @@ impl UdpConnector for Handler {} #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::NoConnect) } @@ -214,8 +212,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { Ok(Box::new(self.new_stream().await?)) } } diff --git a/leaf/src/proxy/redirect/tcp.rs b/leaf/src/proxy/redirect/tcp.rs index 1df4019..19d4e92 100644 --- a/leaf/src/proxy/redirect/tcp.rs +++ b/leaf/src/proxy/redirect/tcp.rs @@ -12,8 +12,6 @@ pub struct Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -21,8 +19,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, _sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input")) } } diff --git a/leaf/src/proxy/redirect/udp.rs b/leaf/src/proxy/redirect/udp.rs index f37a8aa..1a95983 100644 --- a/leaf/src/proxy/redirect/udp.rs +++ b/leaf/src/proxy/redirect/udp.rs @@ -16,9 +16,6 @@ pub struct Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -30,8 +27,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { let dgram = if let Some(OutboundTransport::Datagram(dgram)) = transport { dgram } else { diff --git a/leaf/src/proxy/select/tcp.rs b/leaf/src/proxy/select/tcp.rs index 7485a26..a48e211 100644 --- a/leaf/src/proxy/select/tcp.rs +++ b/leaf/src/proxy/select/tcp.rs @@ -4,11 +4,7 @@ use async_trait::async_trait; use log::*; use tokio::sync::RwLock; -use crate::{ - app::outbound::selector::OutboundSelector, - proxy::{OutboundConnect, ProxyStream, TcpOutboundHandler}, - session::Session, -}; +use crate::{app::outbound::selector::OutboundSelector, proxy::*, session::Session}; pub struct Handler { pub selector: Arc>, @@ -23,8 +19,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option>, - ) -> io::Result> { + stream: Option, + ) -> io::Result { if let Some(a) = self.selector.read().await.get_selected() { debug!("select handles tcp [{}] to [{}]", sess.destination, a.tag()); TcpOutboundHandler::handle(a.as_ref(), sess, stream).await diff --git a/leaf/src/proxy/select/udp.rs b/leaf/src/proxy/select/udp.rs index 0e1a5dd..ba750c1 100644 --- a/leaf/src/proxy/select/udp.rs +++ b/leaf/src/proxy/select/udp.rs @@ -5,14 +5,7 @@ use async_trait::async_trait; use log::*; use tokio::sync::RwLock; -use crate::{ - app::outbound::selector::OutboundSelector, - proxy::{ - DatagramTransportType, OutboundConnect, OutboundDatagram, OutboundTransport, - UdpOutboundHandler, - }, - session::Session, -}; +use crate::{app::outbound::selector::OutboundSelector, proxy::*, session::Session}; pub struct Handler { pub selector: Arc>, @@ -20,9 +13,6 @@ pub struct Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { None } @@ -34,8 +24,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { if let Some(a) = self.selector.read().await.get_selected() { debug!("select handles tcp [{}] to [{}]", sess.destination, a.tag()); UdpOutboundHandler::handle(a.as_ref(), sess, transport).await diff --git a/leaf/src/proxy/shadowsocks/inbound/tcp.rs b/leaf/src/proxy/shadowsocks/inbound/tcp.rs index 094a804..bac0a26 100644 --- a/leaf/src/proxy/shadowsocks/inbound/tcp.rs +++ b/leaf/src/proxy/shadowsocks/inbound/tcp.rs @@ -14,14 +14,11 @@ pub struct Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, mut sess: Session, - stream: Self::TStream, - ) -> std::io::Result> { + stream: AnyStream, + ) -> std::io::Result { let mut stream = ShadowedStream::new(stream, &self.cipher, &self.password)?; let destination = SocksAddr::read_from(&mut stream, SocksAddrWireType::PortLast).await?; sess.destination = destination; diff --git a/leaf/src/proxy/shadowsocks/inbound/udp.rs b/leaf/src/proxy/shadowsocks/inbound/udp.rs index 011113c..0846199 100644 --- a/leaf/src/proxy/shadowsocks/inbound/udp.rs +++ b/leaf/src/proxy/shadowsocks/inbound/udp.rs @@ -21,13 +21,7 @@ pub struct Handler { #[async_trait] impl UdpInboundHandler for Handler { - type UStream = AnyStream; - type UDatagram = AnyInboundDatagram; - - async fn handle<'a>( - &'a self, - socket: Self::UDatagram, - ) -> io::Result> { + async fn handle<'a>(&'a self, socket: AnyInboundDatagram) -> io::Result { let dgram = ShadowedDatagram::new(&self.cipher, &self.password)?; Ok(InboundTransport::Datagram( Box::new(Datagram { dgram, socket }), @@ -38,7 +32,7 @@ impl UdpInboundHandler for Handler { pub struct Datagram { dgram: ShadowedDatagram, - socket: Box, + socket: AnyInboundDatagram, } impl InboundDatagram for Datagram { diff --git a/leaf/src/proxy/shadowsocks/outbound/tcp.rs b/leaf/src/proxy/shadowsocks/outbound/tcp.rs index 04f4218..f3fcf17 100644 --- a/leaf/src/proxy/shadowsocks/outbound/tcp.rs +++ b/leaf/src/proxy/shadowsocks/outbound/tcp.rs @@ -19,8 +19,6 @@ pub struct Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -28,8 +26,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { let stream = stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))?; let mut stream = ShadowedStream::new(stream, &self.cipher, &self.password)?; let mut buf = BytesMut::new(); diff --git a/leaf/src/proxy/shadowsocks/outbound/udp.rs b/leaf/src/proxy/shadowsocks/outbound/udp.rs index 94c7115..e6c91e0 100644 --- a/leaf/src/proxy/shadowsocks/outbound/udp.rs +++ b/leaf/src/proxy/shadowsocks/outbound/udp.rs @@ -19,9 +19,6 @@ pub struct Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -33,8 +30,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { let server_addr = SocksAddr::try_from((&self.address, self.port))?; let socket = if let Some(OutboundTransport::Datagram(socket)) = transport { diff --git a/leaf/src/proxy/socks/inbound/tcp.rs b/leaf/src/proxy/socks/inbound/tcp.rs index de7733d..e6b1879 100644 --- a/leaf/src/proxy/socks/inbound/tcp.rs +++ b/leaf/src/proxy/socks/inbound/tcp.rs @@ -14,14 +14,11 @@ pub struct Handler; #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, mut sess: Session, - mut stream: Self::TStream, - ) -> std::io::Result> { + mut stream: AnyStream, + ) -> std::io::Result { let mut buf = BytesMut::new(); // handle auth diff --git a/leaf/src/proxy/socks/inbound/udp.rs b/leaf/src/proxy/socks/inbound/udp.rs index 2cd9ec4..a8d7667 100644 --- a/leaf/src/proxy/socks/inbound/udp.rs +++ b/leaf/src/proxy/socks/inbound/udp.rs @@ -15,13 +15,10 @@ pub struct Handler; #[async_trait] impl UdpInboundHandler for Handler { - type UStream = AnyStream; - type UDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, - socket: Self::UDatagram, - ) -> io::Result> { + socket: AnyInboundDatagram, + ) -> io::Result { Ok(InboundTransport::Datagram( Box::new(Datagram { socket }), None, diff --git a/leaf/src/proxy/socks/outbound/tcp.rs b/leaf/src/proxy/socks/outbound/tcp.rs index ec023b8..2bf814b 100644 --- a/leaf/src/proxy/socks/outbound/tcp.rs +++ b/leaf/src/proxy/socks/outbound/tcp.rs @@ -15,8 +15,6 @@ pub struct Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -24,8 +22,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { let mut stream = stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))?; match &sess.destination { diff --git a/leaf/src/proxy/socks/outbound/udp.rs b/leaf/src/proxy/socks/outbound/udp.rs index 3c6f382..1738912 100644 --- a/leaf/src/proxy/socks/outbound/udp.rs +++ b/leaf/src/proxy/socks/outbound/udp.rs @@ -25,9 +25,6 @@ impl UdpConnector for Handler {} #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -39,8 +36,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _transport: Option>, - ) -> io::Result { + _transport: Option, + ) -> io::Result { // TODO support chaining, this requires implementing our own socks5 client let stream = self .new_tcp_stream(self.dns_client.clone(), &self.address, &self.port) diff --git a/leaf/src/proxy/static/tcp.rs b/leaf/src/proxy/static/tcp.rs index dae0fd3..f094f61 100644 --- a/leaf/src/proxy/static/tcp.rs +++ b/leaf/src/proxy/static/tcp.rs @@ -38,8 +38,6 @@ impl Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { None } @@ -47,8 +45,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { match self.method { Method::Random => { let mut rng = StdRng::from_entropy(); diff --git a/leaf/src/proxy/static/udp.rs b/leaf/src/proxy/static/udp.rs index c0a5ab6..bf30b11 100644 --- a/leaf/src/proxy/static/udp.rs +++ b/leaf/src/proxy/static/udp.rs @@ -38,9 +38,6 @@ impl Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { None } @@ -52,8 +49,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _transport: Option>, - ) -> io::Result { + _transport: Option, + ) -> io::Result { match self.method { Method::Random => { let mut rng = StdRng::from_entropy(); diff --git a/leaf/src/proxy/tls/inbound/tcp.rs b/leaf/src/proxy/tls/inbound/tcp.rs index e5db4c4..b201b28 100644 --- a/leaf/src/proxy/tls/inbound/tcp.rs +++ b/leaf/src/proxy/tls/inbound/tcp.rs @@ -58,14 +58,11 @@ impl Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, sess: Session, - stream: Self::TStream, - ) -> std::io::Result> { + stream: AnyStream, + ) -> std::io::Result { #[cfg(feature = "rustls-tls")] { Ok(InboundTransport::Stream( diff --git a/leaf/src/proxy/tls/outbound/tcp.rs b/leaf/src/proxy/tls/outbound/tcp.rs index c52a5ea..915501e 100644 --- a/leaf/src/proxy/tls/outbound/tcp.rs +++ b/leaf/src/proxy/tls/outbound/tcp.rs @@ -114,8 +114,6 @@ where #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { None } @@ -123,8 +121,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { // TODO optimize, dont need copy let name = if !&self.server_name.is_empty() { self.server_name.clone() diff --git a/leaf/src/proxy/trojan/inbound/tcp.rs b/leaf/src/proxy/trojan/inbound/tcp.rs index 0522b55..727b737 100644 --- a/leaf/src/proxy/trojan/inbound/tcp.rs +++ b/leaf/src/proxy/trojan/inbound/tcp.rs @@ -129,14 +129,11 @@ impl Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, mut sess: Session, - mut stream: Self::TStream, - ) -> std::io::Result> { + mut stream: AnyStream, + ) -> std::io::Result { let mut buf = BytesMut::new(); // read key buf.resize(56, 0); diff --git a/leaf/src/proxy/trojan/outbound/tcp.rs b/leaf/src/proxy/trojan/outbound/tcp.rs index 68ac25e..f06d4cc 100644 --- a/leaf/src/proxy/trojan/outbound/tcp.rs +++ b/leaf/src/proxy/trojan/outbound/tcp.rs @@ -18,8 +18,6 @@ pub struct Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -27,8 +25,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { let mut stream = stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))?; let mut buf = BytesMut::new(); diff --git a/leaf/src/proxy/trojan/outbound/udp.rs b/leaf/src/proxy/trojan/outbound/udp.rs index c44a7ec..4f1e516 100644 --- a/leaf/src/proxy/trojan/outbound/udp.rs +++ b/leaf/src/proxy/trojan/outbound/udp.rs @@ -21,9 +21,6 @@ pub struct Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { Some(OutboundConnect::Proxy(self.address.clone(), self.port)) } @@ -35,8 +32,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - transport: Option>, - ) -> io::Result { + transport: Option, + ) -> io::Result { let stream = if let Some(OutboundTransport::Stream(stream)) = transport { stream } else { diff --git a/leaf/src/proxy/tryall/tcp.rs b/leaf/src/proxy/tryall/tcp.rs index 6feba15..89d2db8 100644 --- a/leaf/src/proxy/tryall/tcp.rs +++ b/leaf/src/proxy/tryall/tcp.rs @@ -13,8 +13,6 @@ pub struct Handler { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { None } @@ -22,8 +20,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _stream: Option, - ) -> io::Result { + _stream: Option, + ) -> io::Result { let mut tasks = Vec::new(); for (i, a) in self.actors.iter().enumerate() { let t = async move { diff --git a/leaf/src/proxy/tryall/udp.rs b/leaf/src/proxy/tryall/udp.rs index 068978d..f70c6af 100644 --- a/leaf/src/proxy/tryall/udp.rs +++ b/leaf/src/proxy/tryall/udp.rs @@ -13,9 +13,6 @@ pub struct Handler { #[async_trait] impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - fn connect_addr(&self) -> Option { None } @@ -27,8 +24,8 @@ impl UdpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - _transport: Option>, - ) -> io::Result { + _transport: Option, + ) -> io::Result { let mut tasks = Vec::new(); for (i, a) in self.actors.iter().enumerate() { let t = async move { diff --git a/leaf/src/proxy/ws/inbound/tcp.rs b/leaf/src/proxy/ws/inbound/tcp.rs index 69db55b..209df18 100644 --- a/leaf/src/proxy/ws/inbound/tcp.rs +++ b/leaf/src/proxy/ws/inbound/tcp.rs @@ -60,14 +60,11 @@ impl Handler { #[async_trait] impl TcpInboundHandler for Handler { - type TStream = AnyStream; - type TDatagram = AnyInboundDatagram; - async fn handle<'a>( &'a self, mut sess: Session, - stream: Self::TStream, - ) -> std::io::Result> { + stream: AnyStream, + ) -> std::io::Result { Ok(InboundTransport::Stream( Box::new(stream::WebSocketToStream::new( accept_hdr_async(stream, SimpleCallback::new(&mut sess, &self.path)) diff --git a/leaf/src/proxy/ws/outbound/tcp.rs b/leaf/src/proxy/ws/outbound/tcp.rs index acf9ff7..2ad9a9d 100644 --- a/leaf/src/proxy/ws/outbound/tcp.rs +++ b/leaf/src/proxy/ws/outbound/tcp.rs @@ -40,8 +40,6 @@ impl<'a> tungstenite::client::IntoClientRequest for Request<'a> { #[async_trait] impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - fn connect_addr(&self) -> Option { None } @@ -49,8 +47,8 @@ impl TcpOutboundHandler for Handler { async fn handle<'a>( &'a self, sess: &'a Session, - stream: Option, - ) -> io::Result { + stream: Option, + ) -> io::Result { if let Some(stream) = stream { let host = if let Some(host) = self.headers.get("Host") { host.to_owned()