mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-05 16:02:32 +00:00
Refactor
This commit is contained in:
1 parent
530a734bc4
commit
ca1834f977
46 files changed
+138
-292
No files matched your search
@@ -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"]
|
||||
|
||||
@@ -56,6 +56,7 @@ use super::selector::OutboundSelector;
|
||||
|
||||
pub struct OutboundManager {
|
||||
handlers: HashMap<String, AnyOutboundHandler>,
|
||||
#[cfg(feature = "plugin")]
|
||||
external_handlers: super::plugin::ExternalHandlers,
|
||||
selectors: Arc<super::Selectors>,
|
||||
default_handler: Option<String>,
|
||||
@@ -68,7 +69,7 @@ impl OutboundManager {
|
||||
outbounds: &protobuf::RepeatedField<Outbound>,
|
||||
dns_client: SyncDnsClient,
|
||||
handlers: &mut HashMap<String, AnyOutboundHandler>,
|
||||
external_handlers: &mut super::plugin::ExternalHandlers,
|
||||
#[cfg(feature = "plugin")] external_handlers: &mut super::plugin::ExternalHandlers,
|
||||
default_handler: &mut Option<String>,
|
||||
abort_handles: &mut Vec<AbortHandle>,
|
||||
) -> 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<Outbound>,
|
||||
handlers: &mut HashMap<String, AnyOutboundHandler>,
|
||||
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<String, AnyOutboundHandler> = HashMap::new();
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
let mut external_handlers = super::plugin::ExternalHandlers::new();
|
||||
let mut default_handler: Option<String> = None;
|
||||
let mut abort_handles: Vec<AbortHandle> = 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<Self> {
|
||||
let mut handlers: HashMap<String, AnyOutboundHandler> = HashMap::new();
|
||||
#[cfg(feature = "plugin")]
|
||||
let mut external_handlers = super::plugin::ExternalHandlers::new();
|
||||
let mut default_handler: Option<String> = None;
|
||||
let mut abort_handles: Vec<AbortHandle> = 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,
|
||||
|
||||
@@ -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<String, Arc<RwLock<selector::OutboundSelector>>>;
|
||||
@@ -23,22 +23,17 @@ pub trait PluginRegistrar {
|
||||
}
|
||||
|
||||
pub trait ExternalTcpOutboundHandler: Send + Sync + Unpin {
|
||||
type Stream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect>;
|
||||
|
||||
fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<Self::Stream>>;
|
||||
stream: Option<AnyStream>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<AnyStream>>;
|
||||
}
|
||||
pub type AnyExternalTcpOutboundHandler = Arc<dyn ExternalTcpOutboundHandler<Stream = AnyStream>>;
|
||||
pub type AnyExternalTcpOutboundHandler = Arc<dyn ExternalTcpOutboundHandler>;
|
||||
|
||||
pub trait ExternalUdpOutboundHandler: Send + Sync + Unpin {
|
||||
type Stream;
|
||||
type Datagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect>;
|
||||
|
||||
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<OutboundTransport<Self::Stream, Self::Datagram>>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<Self::Datagram>>;
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<AnyOutboundDatagram>>;
|
||||
}
|
||||
|
||||
struct PluginRegistrarImpl {
|
||||
@@ -98,8 +93,6 @@ impl TcpOutboundHandlerProxy {
|
||||
}
|
||||
|
||||
impl ExternalTcpOutboundHandler for TcpOutboundHandlerProxy {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
self.handler.connect_addr()
|
||||
}
|
||||
@@ -107,8 +100,8 @@ impl ExternalTcpOutboundHandler for TcpOutboundHandlerProxy {
|
||||
fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<Self::Stream>> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<AnyStream>> {
|
||||
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<OutboundConnect> {
|
||||
self.handler.connect_addr()
|
||||
}
|
||||
@@ -139,14 +129,13 @@ impl ExternalUdpOutboundHandler for UdpOutboundHandlerProxy {
|
||||
fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
transport: Option<OutboundTransport<Self::Stream, Self::Datagram>>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<Self::Datagram>> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> BorrowingFfiFuture<'a, io::Result<AnyOutboundDatagram>> {
|
||||
self.handler.handle(sess, transport)
|
||||
}
|
||||
}
|
||||
|
||||
pub type AnyExternalUdpOutboundHandler =
|
||||
Arc<dyn ExternalUdpOutboundHandler<Stream = AnyStream, Datagram = AnyOutboundDatagram>>;
|
||||
pub type AnyExternalUdpOutboundHandler = Arc<dyn ExternalUdpOutboundHandler>;
|
||||
|
||||
#[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<OutboundConnect> {
|
||||
self.0.connect_addr()
|
||||
}
|
||||
@@ -202,8 +189,8 @@ impl TcpOutboundHandler for ExternalTcpOutboundHandlerProxy {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
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<OutboundConnect> {
|
||||
self.0.connect_addr()
|
||||
}
|
||||
@@ -226,8 +210,8 @@ impl UdpOutboundHandler for ExternalUdpOutboundHandlerProxy {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
self.0.handle(sess, transport).await
|
||||
}
|
||||
}
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
mut stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
for (_, a) in self.actors.iter().enumerate() {
|
||||
match TcpInboundHandler::handle(a.as_ref(), sess, stream).await? {
|
||||
InboundTransport::Stream(new_stream, new_sess) => {
|
||||
|
||||
@@ -136,8 +136,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
Some(OutboundConnect::NoConnect)
|
||||
}
|
||||
@@ -145,8 +143,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
Ok(Box::new(self.manager.new_stream(sess).await?))
|
||||
}
|
||||
}
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
mut stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
for (i, a) in self.actors.iter().enumerate() {
|
||||
let transport = TcpInboundHandler::handle(a.as_ref(), sess.clone(), stream).await?;
|
||||
match transport {
|
||||
|
||||
@@ -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<InboundTransport<Self::UStream, Self::UDatagram>> {
|
||||
mut socket: AnyInboundDatagram,
|
||||
) -> io::Result<AnyInboundTransport> {
|
||||
let mut sess: Option<Session> = None;
|
||||
for (i, a) in self.actors.iter().enumerate() {
|
||||
let transport = UdpInboundHandler::handle(a.as_ref(), socket).await?;
|
||||
|
||||
@@ -34,8 +34,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
mut stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
match self.connect_addr() {
|
||||
Some(OutboundConnect::NoConnect) => (),
|
||||
_ => {
|
||||
|
||||
@@ -115,9 +115,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
match transport {
|
||||
Some(transport) => match transport {
|
||||
OutboundTransport::Datagram(dgram) => self.handle(sess, None, Some(dgram)).await,
|
||||
|
||||
@@ -8,8 +8,6 @@ pub struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
Some(OutboundConnect::Direct)
|
||||
}
|
||||
@@ -17,8 +15,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,6 @@ pub struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
Some(OutboundConnect::Direct)
|
||||
}
|
||||
@@ -22,8 +19,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
if let Some(OutboundTransport::Datagram(dgram)) = transport {
|
||||
Ok(dgram)
|
||||
} else {
|
||||
|
||||
@@ -8,8 +8,6 @@ pub struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -17,8 +15,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "dropped"))
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,6 @@ pub struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -22,8 +19,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
_transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
_transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "dropped"))
|
||||
}
|
||||
}
|
||||
@@ -221,8 +221,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -230,8 +228,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
if let Some(task) = self.health_check_task.lock().await.take() {
|
||||
tokio::spawn(task);
|
||||
}
|
||||
|
||||
@@ -239,9 +239,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -253,8 +250,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
_transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
if let Some(task) = self.health_check_task.lock().await.take() {
|
||||
tokio::spawn(task);
|
||||
}
|
||||
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
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<InboundTransport<Self::UStream, Self::UDatagram>> {
|
||||
socket: AnyInboundDatagram,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
if let Some(handler) = &self.udp_handler {
|
||||
handler.handle(socket).await
|
||||
} else {
|
||||
|
||||
+16
-46
@@ -509,9 +509,7 @@ pub trait OutboundHandler:
|
||||
{
|
||||
}
|
||||
|
||||
pub type AnyOutboundHandler = Arc<
|
||||
dyn OutboundHandler<Stream = AnyStream, UStream = AnyStream, Datagram = AnyOutboundDatagram>,
|
||||
>;
|
||||
pub type AnyOutboundHandler = Arc<dyn OutboundHandler>;
|
||||
|
||||
#[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<S = AnyStream>: Send + Sync + Unpin {
|
||||
/// Returns the address which the underlying transport should
|
||||
/// communicate with.
|
||||
fn connect_addr(&self) -> Option<OutboundConnect>;
|
||||
|
||||
/// 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<Self::Stream>,
|
||||
) -> io::Result<Self::Stream>;
|
||||
async fn handle<'a>(&'a self, sess: &'a Session, stream: Option<S>) -> io::Result<S>;
|
||||
}
|
||||
|
||||
type AnyTcpOutboundHandler = Box<dyn TcpOutboundHandler<Stream = AnyStream>>;
|
||||
type AnyTcpOutboundHandler = Box<dyn TcpOutboundHandler>;
|
||||
|
||||
/// 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<S = AnyStream, D = AnyOutboundDatagram>: Send + Sync + Unpin {
|
||||
/// Returns the address which the underlying transport should
|
||||
/// communicate with.
|
||||
fn connect_addr(&self) -> Option<OutboundConnect>;
|
||||
@@ -594,12 +583,11 @@ pub trait UdpOutboundHandler: Send + Sync + Unpin {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram>;
|
||||
transport: Option<OutboundTransport<S, D>>,
|
||||
) -> io::Result<D>;
|
||||
}
|
||||
|
||||
type AnyUdpOutboundHandler =
|
||||
Box<dyn UdpOutboundHandler<UStream = AnyStream, Datagram = AnyOutboundDatagram>>;
|
||||
type AnyUdpOutboundHandler = Box<dyn UdpOutboundHandler>;
|
||||
|
||||
/// An outbound transport represents either a reliable or unreliable transport.
|
||||
pub enum OutboundTransport<S, D> {
|
||||
@@ -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<dyn InboundHandler>;
|
||||
|
||||
/// An inbound handler for incoming TCP connections.
|
||||
#[async_trait]
|
||||
pub trait TcpInboundHandler: Send + Sync + Unpin {
|
||||
type TStream;
|
||||
type TDatagram;
|
||||
|
||||
pub trait TcpInboundHandler<S = AnyStream, D = AnyInboundDatagram>: Send + Sync + Unpin {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: Session,
|
||||
stream: Self::TStream,
|
||||
) -> std::io::Result<InboundTransport<Self::TStream, Self::TDatagram>>;
|
||||
stream: S,
|
||||
) -> std::io::Result<InboundTransport<S, D>>;
|
||||
}
|
||||
|
||||
pub type AnyTcpInboundHandler =
|
||||
Arc<dyn TcpInboundHandler<TStream = AnyStream, TDatagram = AnyInboundDatagram>>;
|
||||
pub type AnyTcpInboundHandler = Arc<dyn TcpInboundHandler>;
|
||||
|
||||
/// 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<InboundTransport<Self::UStream, Self::UDatagram>>;
|
||||
pub trait UdpInboundHandler<S = AnyStream, D = AnyInboundDatagram>: Send + Sync + Unpin {
|
||||
async fn handle<'a>(&'a self, socket: D) -> io::Result<InboundTransport<S, D>>;
|
||||
}
|
||||
|
||||
pub type AnyUdpInboundHandler =
|
||||
Arc<dyn UdpInboundHandler<UStream = AnyStream, UDatagram = AnyInboundDatagram>>;
|
||||
pub type AnyUdpInboundHandler = Arc<dyn UdpInboundHandler>;
|
||||
|
||||
/// An unreliable transport for inbound handlers.
|
||||
pub trait InboundDatagram: Send + Sync + Unpin {
|
||||
|
||||
@@ -10,8 +10,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
self.connect.clone()
|
||||
}
|
||||
@@ -19,8 +17,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "null handler"))
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
self.connect.clone()
|
||||
}
|
||||
@@ -25,8 +22,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
_transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
_transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "null handler"))
|
||||
}
|
||||
}
|
||||
@@ -48,8 +48,6 @@ impl Color for Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
self.tcp_handler.connect_addr()
|
||||
}
|
||||
@@ -57,17 +55,14 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
self.tcp_handler.handle(sess, stream).await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
self.udp_handler.connect_addr()
|
||||
}
|
||||
@@ -79,8 +74,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
self.udp_handler.handle(sess, transport).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<InboundTransport<Self::UStream, Self::UDatagram>> {
|
||||
socket: AnyInboundDatagram,
|
||||
) -> io::Result<AnyInboundTransport> {
|
||||
let (cert, key) =
|
||||
fs::read(&self.certificate).and_then(|x| Ok((x, fs::read(&self.certificate_key)?)))?;
|
||||
|
||||
|
||||
@@ -205,8 +205,6 @@ impl UdpConnector for Handler {}
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
Some(OutboundConnect::NoConnect)
|
||||
}
|
||||
@@ -214,8 +212,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
_sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
Ok(Box::new(self.new_stream().await?))
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
let dgram = if let Some(OutboundTransport::Datagram(dgram)) = transport {
|
||||
dgram
|
||||
} else {
|
||||
|
||||
@@ -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<RwLock<OutboundSelector>>,
|
||||
@@ -23,8 +19,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Box<dyn ProxyStream>>,
|
||||
) -> io::Result<Box<dyn ProxyStream>> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
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
|
||||
|
||||
@@ -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<RwLock<OutboundSelector>>,
|
||||
@@ -20,9 +13,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -34,8 +24,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
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
|
||||
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
let mut stream = ShadowedStream::new(stream, &self.cipher, &self.password)?;
|
||||
let destination = SocksAddr::read_from(&mut stream, SocksAddrWireType::PortLast).await?;
|
||||
sess.destination = destination;
|
||||
|
||||
@@ -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<InboundTransport<Self::UStream, Self::UDatagram>> {
|
||||
async fn handle<'a>(&'a self, socket: AnyInboundDatagram) -> io::Result<AnyInboundTransport> {
|
||||
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<dyn InboundDatagram>,
|
||||
socket: AnyInboundDatagram,
|
||||
}
|
||||
|
||||
impl InboundDatagram for Datagram {
|
||||
|
||||
@@ -19,8 +19,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
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();
|
||||
|
||||
@@ -19,9 +19,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
let server_addr = SocksAddr::try_from((&self.address, self.port))?;
|
||||
|
||||
let socket = if let Some(OutboundTransport::Datagram(socket)) = transport {
|
||||
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
mut stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
let mut buf = BytesMut::new();
|
||||
|
||||
// handle auth
|
||||
|
||||
@@ -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<InboundTransport<Self::UStream, Self::UDatagram>> {
|
||||
socket: AnyInboundDatagram,
|
||||
) -> io::Result<AnyInboundTransport> {
|
||||
Ok(InboundTransport::Datagram(
|
||||
Box::new(Datagram { socket }),
|
||||
None,
|
||||
|
||||
@@ -15,8 +15,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
let mut stream =
|
||||
stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))?;
|
||||
match &sess.destination {
|
||||
|
||||
@@ -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<OutboundConnect> {
|
||||
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<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
_transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
// TODO support chaining, this requires implementing our own socks5 client
|
||||
let stream = self
|
||||
.new_tcp_stream(self.dns_client.clone(), &self.address, &self.port)
|
||||
|
||||
@@ -38,8 +38,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -47,8 +45,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
match self.method {
|
||||
Method::Random => {
|
||||
let mut rng = StdRng::from_entropy();
|
||||
|
||||
@@ -38,9 +38,6 @@ impl Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -52,8 +49,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
_transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
match self.method {
|
||||
Method::Random => {
|
||||
let mut rng = StdRng::from_entropy();
|
||||
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
{
|
||||
Ok(InboundTransport::Stream(
|
||||
|
||||
@@ -114,8 +114,6 @@ where
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -123,8 +121,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
// TODO optimize, dont need copy
|
||||
let name = if !&self.server_name.is_empty() {
|
||||
self.server_name.clone()
|
||||
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
mut stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
let mut buf = BytesMut::new();
|
||||
// read key
|
||||
buf.resize(56, 0);
|
||||
|
||||
@@ -18,8 +18,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
let mut stream =
|
||||
stream.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid input"))?;
|
||||
let mut buf = BytesMut::new();
|
||||
|
||||
@@ -21,9 +21,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
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<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
let stream = if let Some(OutboundTransport::Stream(stream)) = transport {
|
||||
stream
|
||||
} else {
|
||||
|
||||
@@ -13,8 +13,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl TcpOutboundHandler for Handler {
|
||||
type Stream = AnyStream;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -22,8 +20,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
_stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
let mut tasks = Vec::new();
|
||||
for (i, a) in self.actors.iter().enumerate() {
|
||||
let t = async move {
|
||||
|
||||
@@ -13,9 +13,6 @@ pub struct Handler {
|
||||
|
||||
#[async_trait]
|
||||
impl UdpOutboundHandler for Handler {
|
||||
type UStream = AnyStream;
|
||||
type Datagram = AnyOutboundDatagram;
|
||||
|
||||
fn connect_addr(&self) -> Option<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -27,8 +24,8 @@ impl UdpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
_transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
|
||||
) -> io::Result<Self::Datagram> {
|
||||
_transport: Option<AnyOutboundTransport>,
|
||||
) -> io::Result<AnyOutboundDatagram> {
|
||||
let mut tasks = Vec::new();
|
||||
for (i, a) in self.actors.iter().enumerate() {
|
||||
let t = async move {
|
||||
|
||||
@@ -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<InboundTransport<Self::TStream, Self::TDatagram>> {
|
||||
stream: AnyStream,
|
||||
) -> std::io::Result<AnyInboundTransport> {
|
||||
Ok(InboundTransport::Stream(
|
||||
Box::new(stream::WebSocketToStream::new(
|
||||
accept_hdr_async(stream, SimpleCallback::new(&mut sess, &self.path))
|
||||
|
||||
@@ -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<OutboundConnect> {
|
||||
None
|
||||
}
|
||||
@@ -49,8 +47,8 @@ impl TcpOutboundHandler for Handler {
|
||||
async fn handle<'a>(
|
||||
&'a self,
|
||||
sess: &'a Session,
|
||||
stream: Option<Self::Stream>,
|
||||
) -> io::Result<Self::Stream> {
|
||||
stream: Option<AnyStream>,
|
||||
) -> io::Result<AnyStream> {
|
||||
if let Some(stream) = stream {
|
||||
let host = if let Some(host) = self.headers.get("Host") {
|
||||
host.to_owned()
|
||||
|
||||
Reference in new issue
Block a user