From 0c5153bbd6fab1dcaf62e2bd923e8df66ca8029c Mon Sep 17 00:00:00 2001 From: Jacob Kiers Date: Wed, 16 Aug 2023 09:31:20 +0200 Subject: [PATCH] Rename Proxy::default to ::default_action Signed-off-by: Jacob Kiers --- src/servers/mod.rs | 4 ++-- src/servers/protocol/tcp.rs | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/servers/mod.rs b/src/servers/mod.rs index ea54ef8..01ffb18 100644 --- a/src/servers/mod.rs +++ b/src/servers/mod.rs @@ -21,7 +21,7 @@ pub struct Proxy { pub protocol: String, pub tls: bool, pub sni: Option>, - pub default: String, + pub default_action: String, pub upstream: HashMap, } @@ -60,7 +60,7 @@ impl Server { protocol: protocol.clone(), tls, sni: sni.clone(), - default: default.clone(), + default_action: default.clone(), upstream: upstream.clone(), }; new_server.proxies.push(Arc::new(proxy)); diff --git a/src/servers/protocol/tcp.rs b/src/servers/protocol/tcp.rs index c415d29..13533f0 100644 --- a/src/servers/protocol/tcp.rs +++ b/src/servers/protocol/tcp.rs @@ -37,17 +37,17 @@ async fn accept(inbound: TcpStream, proxy: Arc) -> Result<(), Box proxy.default.clone(), + false => proxy.default_action.clone(), true => { let mut hello_buf = [0u8; 1024]; inbound.peek(&mut hello_buf).await?; let snis = get_sni(&hello_buf); if snis.is_empty() { - proxy.default.clone() + proxy.default_action.clone() } else { match proxy.sni.clone() { Some(sni_map) => { - let mut upstream = proxy.default.clone(); + let mut upstream = proxy.default_action.clone(); for sni in snis { let m = sni_map.get(&sni); if m.is_some() { @@ -57,7 +57,7 @@ async fn accept(inbound: TcpStream, proxy: Arc) -> Result<(), Box proxy.default.clone(), + None => proxy.default_action.clone(), } } } @@ -70,9 +70,13 @@ async fn accept(inbound: TcpStream, proxy: Arc) -> Result<(), Box { warn!( "No upstream named {:?} on server {:?}", - proxy.default, proxy.name + proxy.default_action, proxy.name ); - return process(inbound, proxy.upstream.get(&proxy.default).unwrap().clone()).await; + return process( + inbound, + proxy.upstream.get(&proxy.default_action).unwrap().clone(), + ) + .await; // ToDo: Remove unwrap and check default option } };