outbound/retry: removed

This commit is contained in:
eric committed 2022-04-08 18:53:01 +08:00
1 parent 1e74deee80
commit cbef2f9fc6
10 files changed
-260

No files matched your search

-2
View File
@@ -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 = []
-42
View File
@@ -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)
-28
View File
@@ -113,9 +113,6 @@ pub struct ProxyGroup {
// tryall
pub delay_base: Option<i32>,
// retry
pub attempts: Option<i32>,
}
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<io::Result<String>>) -> Result<Config> {
};
group.delay_base = i;
}
"attempts" => {
let i = if let Ok(i) = v.parse::<i32>() {
Some(i)
} else {
None
};
group.attempts = i;
}
_ => {}
}
}
@@ -1074,22 +1062,6 @@ pub fn to_internal(conf: &mut Config) -> Result<internal::Config> {
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 {
-5
View File
@@ -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;
-22
View File
@@ -810,28 +810,6 @@ pub fn to_internal(json: &mut Config) -> Result<internal::Config> {
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"));
-2
View File
@@ -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")]
-5
View File
@@ -1,5 +0,0 @@
pub mod tcp;
pub mod udp;
pub use tcp::Handler as TcpHandler;
pub use udp::Handler as UdpHandler;
-40
View File
@@ -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<AnyOutboundHandler>,
pub attempts: usize,
pub dns_client: SyncDnsClient,
}
#[async_trait]
impl TcpOutboundHandler for Handler {
type Stream = AnyStream;
fn connect_addr(&self) -> Option<OutboundConnect> {
None
}
async fn handle<'a>(
&'a self,
sess: &'a Session,
_stream: Option<Self::Stream>,
) -> io::Result<Self::Stream> {
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"))
}
}
-45
View File
@@ -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<AnyOutboundHandler>,
pub attempts: usize,
pub dns_client: SyncDnsClient,
}
#[async_trait]
impl UdpOutboundHandler for Handler {
type UStream = AnyStream;
type Datagram = AnyOutboundDatagram;
fn connect_addr(&self) -> Option<OutboundConnect> {
None
}
fn transport_type(&self) -> DatagramTransportType {
DatagramTransportType::Undefined
}
async fn handle<'a>(
&'a self,
sess: &'a Session,
_transport: Option<OutboundTransport<Self::UStream, Self::Datagram>>,
) -> io::Result<Self::Datagram> {
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"))
}
}
-69
View File
@@ -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);
}