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
T: 'static + AsyncRead + AsyncWrite + Unpin + Send + Sync,
{
let mut lhs: Box<dyn ProxyStream> =
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<dyn ProxyStream> = 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;

View File

@@ -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)