diff --git a/leaf/src/app/dispatcher.rs b/leaf/src/app/dispatcher.rs index 979ba1d..d8cdf83 100644 --- a/leaf/src/app/dispatcher.rs +++ b/leaf/src/app/dispatcher.rs @@ -80,41 +80,43 @@ impl Dispatcher { where T: 'static + AsyncRead + AsyncWrite + Unpin + Send + Sync, { - let mut lhs: Box = - if !sess.destination.is_domain() && sess.destination.port() == 443 { - let mut lhs = sniff::SniffingStream::new(lhs); - match lhs.sniff().await { - Ok(res) => { - if let Some(domain) = res { - debug!( - "sniffed domain {} for tcp link {} <-> {}", - &domain, &sess.source, &sess.destination, - ); - sess.destination = - match SocksAddr::try_from((&domain, sess.destination.port())) { - Ok(a) => a, - Err(e) => { - warn!( - "convert sniffed domain {} to destination failed: {}", - &domain, e, - ); - return; - } - }; - } - } - Err(e) => { + let mut lhs: Box = if *option::DOMAIN_SNIFFING + && !sess.destination.is_domain() + && sess.destination.port() == 443 + { + let mut lhs = sniff::SniffingStream::new(lhs); + match lhs.sniff().await { + Ok(res) => { + if let Some(domain) = res { debug!( - "sniff tcp uplink {} -> {} failed: {}", - &sess.source, &sess.destination, e, + "sniffed domain {} for tcp link {} <-> {}", + &domain, &sess.source, &sess.destination, ); - return; + sess.destination = + match SocksAddr::try_from((&domain, sess.destination.port())) { + Ok(a) => a, + Err(e) => { + warn!( + "convert sniffed domain {} to destination failed: {}", + &domain, e, + ); + return; + } + }; } } - Box::new(lhs) - } else { - Box::new(lhs) - }; + Err(e) => { + debug!( + "sniff tcp uplink {} -> {} failed: {}", + &sess.source, &sess.destination, e, + ); + return; + } + } + Box::new(lhs) + } else { + Box::new(lhs) + }; let outbound = { let router = self.router.read().await; diff --git a/leaf/src/option/mod.rs b/leaf/src/option/mod.rs index b6839a4..d51d875 100644 --- a/leaf/src/option/mod.rs +++ b/leaf/src/option/mod.rs @@ -97,6 +97,10 @@ lazy_static! { get_env_var_or("LOG_NO_COLOR", false) }; + pub static ref DOMAIN_SNIFFING: bool = { + get_env_var_or("DOMAIN_SNIFFING", false) + }; + /// Uplink timeout after downlink EOF. pub static ref TCP_UPLINK_TIMEOUT: u64 = { get_env_var_or("TCP_UPLINK_TIMEOUT", 10)