Turn off domain sniffing
Some checks failed
ci / test (macos-latest) (push) Has been cancelled
ci / test (ubuntu-latest) (push) Has been cancelled
ci / test (windows-latest) (push) Has been cancelled
ci / build-bin-cross (aarch64-unknown-linux-musl) (push) Has been cancelled
ci / build-bin-cross (mips-unknown-linux-musl) (push) Has been cancelled
ci / build-bin-cross (x86_64-pc-windows-gnu) (push) Has been cancelled
ci / build-bin-cross (x86_64-unknown-linux-musl) (push) Has been cancelled
ci / build-bin-local (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
releases / build-bin-cross (aarch64-unknown-linux-musl) (push) Has been cancelled
releases / build-bin-cross (mips-unknown-linux-musl) (push) Has been cancelled
releases / build-bin-cross (x86_64-pc-windows-gnu) (push) Has been cancelled
releases / build-bin-cross (x86_64-unknown-linux-musl) (push) Has been cancelled
releases / build-bin-local (macos-latest, x86_64-apple-darwin) (push) Has been cancelled
releases / create-release (push) Has been cancelled
releases / release-bin (aarch64-unknown-linux-musl) (push) Has been cancelled
releases / release-bin (mips-unknown-linux-musl) (push) Has been cancelled
releases / release-bin (x86_64-apple-darwin) (push) Has been cancelled
releases / release-bin (x86_64-pc-windows-gnu) (push) Has been cancelled
releases / release-bin (x86_64-unknown-linux-musl) (push) Has been cancelled

This commit is contained in:
eric
2023-02-18 22:56:11 +08:00
parent 4aa7ecbc6d
commit cd009cc7f2
2 changed files with 37 additions and 31 deletions

View File

@@ -80,41 +80,43 @@ impl Dispatcher {
where where
T: 'static + AsyncRead + AsyncWrite + Unpin + Send + Sync, T: 'static + AsyncRead + AsyncWrite + Unpin + Send + Sync,
{ {
let mut lhs: Box<dyn ProxyStream> = let mut lhs: Box<dyn ProxyStream> = if *option::DOMAIN_SNIFFING
if !sess.destination.is_domain() && sess.destination.port() == 443 { && !sess.destination.is_domain()
let mut lhs = sniff::SniffingStream::new(lhs); && sess.destination.port() == 443
match lhs.sniff().await { {
Ok(res) => { let mut lhs = sniff::SniffingStream::new(lhs);
if let Some(domain) = res { match lhs.sniff().await {
debug!( Ok(res) => {
"sniffed domain {} for tcp link {} <-> {}", if let Some(domain) = res {
&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) => {
debug!( debug!(
"sniff tcp uplink {} -> {} failed: {}", "sniffed domain {} for tcp link {} <-> {}",
&sess.source, &sess.destination, e, &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) Err(e) => {
} else { debug!(
Box::new(lhs) "sniff tcp uplink {} -> {} failed: {}",
}; &sess.source, &sess.destination, e,
);
return;
}
}
Box::new(lhs)
} else {
Box::new(lhs)
};
let outbound = { let outbound = {
let router = self.router.read().await; let router = self.router.read().await;

View File

@@ -97,6 +97,10 @@ lazy_static! {
get_env_var_or("LOG_NO_COLOR", false) 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. /// Uplink timeout after downlink EOF.
pub static ref TCP_UPLINK_TIMEOUT: u64 = { pub static ref TCP_UPLINK_TIMEOUT: u64 = {
get_env_var_or("TCP_UPLINK_TIMEOUT", 10) get_env_var_or("TCP_UPLINK_TIMEOUT", 10)