mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-11 15:01:02 +03:00
bump hbb_common: one STUN list, and drop the dead IPv4 half
`test_ipv6` kept its own hand-written copy of the STUN servers. It now reads `WebRTCStream::stun_servers()`, so an operator who points OPTION_ICE_SERVERS at their own server gets it on both paths instead of one. `test_bind_ipv6` sends nothing - `connect` only makes the kernel pick a route and a source address - so the whole cost is DNS. It races the lookups rather than betting this host's IPv6 support on whether the first entry happens to publish a AAAA where the user resolves from; google's does not, from a Chinese resolver, and it was the entry being bet on. `stun_ipv4_test`, `STUNS_V4` and `test_nat_ipv4` have had no callers since the punch stopped taking its port from a second socket, and go. `get_kcp_cc_enabled` reads the renamed option through `option2bool`, like every other one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019UzcMTdYTEv2QbMHcTSUy3
This commit is contained in:
Submodule libs/hbb_common updated: e2aa3832b2...96933d6230
100
src/common.rs
100
src/common.rs
@@ -2466,16 +2466,17 @@ pub fn is_udp_disabled() -> bool {
|
|||||||
/// without a shaped link, so keep what users run today.
|
/// without a shaped link, so keep what users run today.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_kcp_cc_enabled() -> bool {
|
pub fn get_kcp_cc_enabled() -> bool {
|
||||||
Config::get_option(keys::OPTION_ENABLE_KCP_CC) == "Y"
|
let k = keys::OPTION_ALLOW_KCP_CC;
|
||||||
|
config::option2bool(k, &Config::get_option(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
// this crate https://github.com/yoshd/stun-client supports nat type
|
// this crate https://github.com/yoshd/stun-client supports nat type
|
||||||
async fn stun_ipv6_test(stun_server: &str) -> ResultType<(SocketAddr, String)> {
|
async fn stun_ipv6_test(stun_server: String) -> ResultType<(SocketAddr, String)> {
|
||||||
use stunclient::StunClient;
|
use stunclient::StunClient;
|
||||||
let local_addr = SocketAddr::from(([0u16; 8], 0)); // [::]:0
|
let local_addr = SocketAddr::from(([0u16; 8], 0)); // [::]:0
|
||||||
let socket = UdpSocket::bind(&local_addr).await?;
|
let socket = UdpSocket::bind(&local_addr).await?;
|
||||||
// Resolve via tokio so DNS never blocks the async runtime worker.
|
// Resolve via tokio so DNS never blocks the async runtime worker.
|
||||||
let Some(stun_addr) = tokio::net::lookup_host(stun_server)
|
let Some(stun_addr) = tokio::net::lookup_host(&stun_server)
|
||||||
.await?
|
.await?
|
||||||
.find(|x| x.is_ipv6())
|
.find(|x| x.is_ipv6())
|
||||||
else {
|
else {
|
||||||
@@ -2487,79 +2488,36 @@ async fn stun_ipv6_test(stun_server: &str) -> ResultType<(SocketAddr, String)> {
|
|||||||
let client = StunClient::new(stun_addr);
|
let client = StunClient::new(stun_addr);
|
||||||
let addr = client.query_external_address_async(&socket).await?;
|
let addr = client.query_external_address_async(&socket).await?;
|
||||||
Ok(if addr.ip().is_ipv6() {
|
Ok(if addr.ip().is_ipv6() {
|
||||||
(addr, stun_server.to_owned())
|
(addr, stun_server)
|
||||||
} else {
|
} else {
|
||||||
bail!("STUN server returned non-IPv6 address: {}", addr)
|
bail!("STUN server returned non-IPv6 address: {}", addr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn stun_ipv4_test(stun_server: &str) -> ResultType<(SocketAddr, String)> {
|
|
||||||
use stunclient::StunClient;
|
|
||||||
let local_addr = SocketAddr::from(([0u8; 4], 0));
|
|
||||||
let socket = UdpSocket::bind(&local_addr).await?;
|
|
||||||
// Resolve via tokio so DNS never blocks the async runtime worker.
|
|
||||||
let Some(stun_addr) = tokio::net::lookup_host(stun_server)
|
|
||||||
.await?
|
|
||||||
.find(|x| x.is_ipv4())
|
|
||||||
else {
|
|
||||||
bail!(
|
|
||||||
"Failed to resolve STUN ipv4 server address: {}",
|
|
||||||
stun_server
|
|
||||||
);
|
|
||||||
};
|
|
||||||
let client = StunClient::new(stun_addr);
|
|
||||||
let addr = client.query_external_address_async(&socket).await?;
|
|
||||||
Ok(if addr.ip().is_ipv4() {
|
|
||||||
(addr, stun_server.to_owned())
|
|
||||||
} else {
|
|
||||||
bail!("STUN server returned non-IPv4 address: {}", addr)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static STUNS_V4: [&str; 3] = [
|
|
||||||
"stun.l.google.com:19302",
|
|
||||||
"stun.cloudflare.com:3478",
|
|
||||||
"stun.nextcloud.com:3478",
|
|
||||||
];
|
|
||||||
|
|
||||||
static STUNS_V6: [&str; 3] = [
|
|
||||||
"stun.l.google.com:19302",
|
|
||||||
"stun.cloudflare.com:3478",
|
|
||||||
"stun.nextcloud.com:3478",
|
|
||||||
];
|
|
||||||
|
|
||||||
pub async fn test_nat_ipv4() -> ResultType<(SocketAddr, String)> {
|
|
||||||
use hbb_common::futures::future::{select_ok, FutureExt};
|
|
||||||
let tests = STUNS_V4
|
|
||||||
.iter()
|
|
||||||
.map(|&stun| stun_ipv4_test(stun).boxed())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
match select_ok(tests).await {
|
|
||||||
Ok(res) => {
|
|
||||||
return Ok(res.0);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
bail!(
|
|
||||||
"Failed to get public IPv4 address via public STUN servers: {}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn test_bind_ipv6() -> ResultType<SocketAddr> {
|
async fn test_bind_ipv6() -> ResultType<SocketAddr> {
|
||||||
|
use hbb_common::futures::future::FutureExt;
|
||||||
let local_addr = SocketAddr::from(([0u16; 8], 0)); // [::]:0
|
let local_addr = SocketAddr::from(([0u16; 8], 0)); // [::]:0
|
||||||
let socket = UdpSocket::bind(local_addr).await?;
|
let socket = UdpSocket::bind(local_addr).await?;
|
||||||
let addr = tokio::net::lookup_host(STUNS_V6[0])
|
// Nothing is sent - `connect` only makes the kernel pick a route and a source address - so any
|
||||||
.await?
|
// resolvable target answers equally and the whole cost is DNS. Race the lookups rather than
|
||||||
.find(|x| x.is_ipv6())
|
// walk them: this is awaited inline on the connection path, not every STUN host publishes a
|
||||||
.ok_or_else(|| {
|
// AAAA, and one resolver that hangs must not decide whether this host has v6.
|
||||||
anyhow!(
|
let lookups = hbb_common::webrtc::WebRTCStream::default_stun_servers()
|
||||||
"Failed to resolve STUN ipv6 server address: {}",
|
.into_iter()
|
||||||
STUNS_V6[0]
|
.map(|stun| {
|
||||||
)
|
(async move {
|
||||||
})?;
|
let addr = tokio::net::lookup_host(&stun)
|
||||||
|
.await?
|
||||||
|
.find(|x| x.is_ipv6())
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow!("Failed to resolve STUN ipv6 server address: {}", stun)
|
||||||
|
})?;
|
||||||
|
Ok::<SocketAddr, hbb_common::anyhow::Error>(addr)
|
||||||
|
})
|
||||||
|
.boxed()
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let (addr, _) = hbb_common::futures::future::select_ok(lookups).await?;
|
||||||
socket.connect(addr).await?;
|
socket.connect(addr).await?;
|
||||||
Ok(socket.local_addr()?)
|
Ok(socket.local_addr()?)
|
||||||
}
|
}
|
||||||
@@ -2626,9 +2584,9 @@ pub async fn test_ipv6() -> Option<tokio::task::JoinHandle<()>> {
|
|||||||
|
|
||||||
Some(tokio::spawn(async {
|
Some(tokio::spawn(async {
|
||||||
use hbb_common::futures::future::{select_ok, FutureExt};
|
use hbb_common::futures::future::{select_ok, FutureExt};
|
||||||
let tests = STUNS_V6
|
let tests = hbb_common::webrtc::WebRTCStream::default_stun_servers()
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|&stun| stun_ipv6_test(stun).boxed())
|
.map(|stun| stun_ipv6_test(stun).boxed())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
match select_ok(tests).await {
|
match select_ok(tests).await {
|
||||||
|
|||||||
Reference in New Issue
Block a user