From cbef2f9fc67b349f274f03130c0fcb1e6dbd86ec Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 8 Apr 2022 18:53:01 +0800 Subject: [PATCH] outbound/retry: removed --- leaf/Cargo.toml | 2 - leaf/src/app/outbound/manager.rs | 42 ---------------- leaf/src/config/conf/config.rs | 28 ----------- leaf/src/config/internal/config.proto | 5 -- leaf/src/config/json/config.rs | 22 --------- leaf/src/proxy/mod.rs | 2 - leaf/src/proxy/retry/mod.rs | 5 -- leaf/src/proxy/retry/tcp.rs | 40 ---------------- leaf/src/proxy/retry/udp.rs | 45 ----------------- leaf/tests/test_retry.rs | 69 --------------------------- 10 files changed, 260 deletions(-) delete mode 100644 leaf/src/proxy/retry/mod.rs delete mode 100644 leaf/src/proxy/retry/tcp.rs delete mode 100644 leaf/src/proxy/retry/udp.rs delete mode 100644 leaf/tests/test_retry.rs diff --git a/leaf/Cargo.toml b/leaf/Cargo.toml index 9c02ae3..bde2f24 100644 --- a/leaf/Cargo.toml +++ b/leaf/Cargo.toml @@ -66,7 +66,6 @@ all-endpoints = [ "outbound-rr", "outbound-tryall", "outbound-chain", - "outbound-retry", # "outbound-select", ] @@ -96,7 +95,6 @@ outbound-random = [] outbound-rr= [] outbound-tryall = [] outbound-chain = [] -outbound-retry = [] outbound-amux= ["tokio-util"] outbound-quic = ["quinn", "rustls", "webpki-roots"] outbound-select = [] diff --git a/leaf/src/app/outbound/manager.rs b/leaf/src/app/outbound/manager.rs index 1e09018..85a5d3a 100644 --- a/leaf/src/app/outbound/manager.rs +++ b/leaf/src/app/outbound/manager.rs @@ -19,8 +19,6 @@ use crate::proxy::chain; use crate::proxy::failover; #[cfg(feature = "outbound-random")] use crate::proxy::random; -#[cfg(feature = "outbound-retry")] -use crate::proxy::retry; #[cfg(feature = "outbound-rr")] use crate::proxy::rr; #[cfg(feature = "outbound-select")] @@ -607,46 +605,6 @@ impl OutboundManager { settings.actors.join(",") ); } - #[cfg(feature = "outbound-retry")] - "retry" => { - let settings = - config::RetryOutboundSettings::parse_from_bytes(&outbound.settings) - .map_err(|e| { - anyhow!("invalid [{}] outbound settings: {}", &tag, e) - })?; - let mut actors = Vec::new(); - for actor in settings.actors.iter() { - if let Some(a) = handlers.get(actor) { - actors.push(a.clone()); - } else { - continue 'outbounds; - } - } - if actors.is_empty() { - continue; - } - let tcp = Box::new(retry::TcpHandler { - actors: actors.clone(), - attempts: settings.attempts as usize, - dns_client: dns_client.clone(), - }); - let udp = Box::new(retry::UdpHandler { - actors, - attempts: settings.attempts as usize, - dns_client: dns_client.clone(), - }); - let handler = HandlerBuilder::default() - .tag(tag.clone()) - .tcp_handler(tcp) - .udp_handler(udp) - .build(); - handlers.insert(tag.clone(), handler); - trace!( - "added handler [{}] with actors: {}", - &tag, - settings.actors.join(",") - ); - } "plugin" => { let settings = config::PluginOutboundSettings::parse_from_bytes(&outbound.settings) diff --git a/leaf/src/config/conf/config.rs b/leaf/src/config/conf/config.rs index 3d099d4..5756b01 100644 --- a/leaf/src/config/conf/config.rs +++ b/leaf/src/config/conf/config.rs @@ -113,9 +113,6 @@ pub struct ProxyGroup { // tryall pub delay_base: Option, - - // retry - pub attempts: Option, } impl Default for ProxyGroup { @@ -134,7 +131,6 @@ impl Default for ProxyGroup { last_resort: None, health_check_timeout: Some(5), delay_base: Some(0), - attempts: Some(2), } } } @@ -552,14 +548,6 @@ pub fn from_lines(lines: Vec>) -> Result { }; group.delay_base = i; } - "attempts" => { - let i = if let Ok(i) = v.parse::() { - Some(i) - } else { - None - }; - group.attempts = i; - } _ => {} } } @@ -1074,22 +1062,6 @@ pub fn to_internal(conf: &mut Config) -> Result { outbound.settings = settings; outbounds.push(outbound); } - "retry" => { - let mut settings = internal::RetryOutboundSettings::new(); - if let Some(ext_actors) = &ext_proxy_group.actors { - for ext_actor in ext_actors { - settings.actors.push(ext_actor.to_string()); - } - } - if let Some(ext_attempts) = ext_proxy_group.attempts { - settings.attempts = ext_attempts as u32; - } else { - settings.attempts = 2; - } - let settings = settings.write_to_bytes().unwrap(); - outbound.settings = settings; - outbounds.push(outbound); - } "select" => { let mut settings = internal::SelectOutboundSettings::new(); if let Some(ext_actors) = &ext_proxy_group.actors { diff --git a/leaf/src/config/internal/config.proto b/leaf/src/config/internal/config.proto index e18407c..4fed8a4 100644 --- a/leaf/src/config/internal/config.proto +++ b/leaf/src/config/internal/config.proto @@ -150,11 +150,6 @@ message ChainOutboundSettings { repeated string actors = 1; } -message RetryOutboundSettings { - repeated string actors = 1; - uint32 attempts = 2; -} - message FailOverOutboundSettings { repeated string actors = 1; uint32 fail_timeout = 2; diff --git a/leaf/src/config/json/config.rs b/leaf/src/config/json/config.rs index 9cc8903..37fe519 100644 --- a/leaf/src/config/json/config.rs +++ b/leaf/src/config/json/config.rs @@ -810,28 +810,6 @@ pub fn to_internal(json: &mut Config) -> Result { outbound.settings = settings; outbounds.push(outbound); } - "retry" => { - if ext_outbound.settings.is_none() { - return Err(anyhow!("invalid retry outbound settings")); - } - let mut settings = internal::RetryOutboundSettings::new(); - let ext_settings: RetryOutboundSettings = - serde_json::from_str(ext_outbound.settings.as_ref().unwrap().get()) - .unwrap(); - if let Some(ext_actors) = ext_settings.actors { - for ext_actor in ext_actors { - settings.actors.push(ext_actor); - } - } - if let Some(ext_attempts) = ext_settings.attempts { - settings.attempts = ext_attempts; - } else { - settings.attempts = 2; - } - let settings = settings.write_to_bytes().unwrap(); - outbound.settings = settings; - outbounds.push(outbound); - } "select" => { if ext_outbound.settings.is_none() { return Err(anyhow!("invalid select outbound settings")); diff --git a/leaf/src/proxy/mod.rs b/leaf/src/proxy/mod.rs index da85d65..b570a3f 100644 --- a/leaf/src/proxy/mod.rs +++ b/leaf/src/proxy/mod.rs @@ -56,8 +56,6 @@ pub mod quic; pub mod random; #[cfg(feature = "outbound-redirect")] pub mod redirect; -#[cfg(feature = "outbound-retry")] -pub mod retry; #[cfg(feature = "outbound-rr")] pub mod rr; #[cfg(feature = "outbound-select")] diff --git a/leaf/src/proxy/retry/mod.rs b/leaf/src/proxy/retry/mod.rs deleted file mode 100644 index 7aaef1b..0000000 --- a/leaf/src/proxy/retry/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod tcp; -pub mod udp; - -pub use tcp::Handler as TcpHandler; -pub use udp::Handler as UdpHandler; diff --git a/leaf/src/proxy/retry/tcp.rs b/leaf/src/proxy/retry/tcp.rs deleted file mode 100644 index 527672c..0000000 --- a/leaf/src/proxy/retry/tcp.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::io; - -use async_trait::async_trait; -use log::*; - -use crate::{app::SyncDnsClient, proxy::*, session::Session}; - -pub struct Handler { - pub actors: Vec, - pub attempts: usize, - pub dns_client: SyncDnsClient, -} - -#[async_trait] -impl TcpOutboundHandler for Handler { - type Stream = AnyStream; - - fn connect_addr(&self) -> Option { - None - } - - async fn handle<'a>( - &'a self, - sess: &'a Session, - _stream: Option, - ) -> io::Result { - for _ in 0..self.attempts { - for a in self.actors.iter() { - debug!("retry handles tcp [{}] to [{}]", sess.destination, a.tag()); - let stream = - crate::proxy::connect_tcp_outbound(sess, self.dns_client.clone(), a).await?; - match TcpOutboundHandler::handle(a.as_ref(), sess, stream).await { - Ok(s) => return Ok(s), - Err(_) => continue, - } - } - } - Err(io::Error::new(io::ErrorKind::Other, "all attempts failed")) - } -} diff --git a/leaf/src/proxy/retry/udp.rs b/leaf/src/proxy/retry/udp.rs deleted file mode 100644 index d3a46b6..0000000 --- a/leaf/src/proxy/retry/udp.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::io; - -use async_trait::async_trait; -use log::*; - -use crate::{app::SyncDnsClient, proxy::*, session::Session}; - -pub struct Handler { - pub actors: Vec, - pub attempts: usize, - pub dns_client: SyncDnsClient, -} - -#[async_trait] -impl UdpOutboundHandler for Handler { - type UStream = AnyStream; - type Datagram = AnyOutboundDatagram; - - fn connect_addr(&self) -> Option { - None - } - - fn transport_type(&self) -> DatagramTransportType { - DatagramTransportType::Undefined - } - - async fn handle<'a>( - &'a self, - sess: &'a Session, - _transport: Option>, - ) -> io::Result { - for _ in 0..self.attempts { - for a in self.actors.iter() { - debug!("retry handles tcp [{}] to [{}]", sess.destination, a.tag()); - let transport = - crate::proxy::connect_udp_outbound(sess, self.dns_client.clone(), a).await?; - match UdpOutboundHandler::handle(a.as_ref(), sess, transport).await { - Ok(s) => return Ok(s), - Err(_) => continue, - } - } - } - Err(io::Error::new(io::ErrorKind::Other, "all attempts failed")) - } -} diff --git a/leaf/tests/test_retry.rs b/leaf/tests/test_retry.rs deleted file mode 100644 index 51df8d5..0000000 --- a/leaf/tests/test_retry.rs +++ /dev/null @@ -1,69 +0,0 @@ -mod common; - -// app(socks) -> (socks)client(retry(shadowsocks)) -> (shadowsocks)server(direct) -> echo -#[cfg(all( - feature = "outbound-socks", - feature = "inbound-socks", - feature = "outbound-shadowsocks", - feature = "inbound-shadowsocks", - feature = "outbound-direct", - feature = "outbound-retry", -))] -#[test] -fn test_retry() { - let config1 = r#" - { - "inbounds": [ - { - "protocol": "socks", - "address": "127.0.0.1", - "port": 1086 - } - ], - "outbounds": [ - { - "protocol": "retry", - "settings": { - "actors": [ - "ss_out" - ] - } - }, - { - "protocol": "shadowsocks", - "tag": "ss_out", - "settings": { - "address": "127.0.0.1", - "port": 3001, - "method": "chacha20-ietf-poly1305", - "password": "password" - } - } - ] - } - "#; - - let config2 = r#" - { - "inbounds": [ - { - "protocol": "shadowsocks", - "address": "127.0.0.1", - "port": 3001, - "settings": { - "method": "chacha20-ietf-poly1305", - "password": "password" - } - } - ], - "outbounds": [ - { - "protocol": "direct" - } - ] - } - "#; - - let configs = vec![config1.to_string(), config2.to_string()]; - common::test_configs(configs, "127.0.0.1", 1086); -}