Turn off domain sniffing

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

No files matched your search

+33 -31
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;
+4
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)