refactor: update custom STUN server settings (#1310)

* refactor: update global context STUN server initialization

Modified global context initialization to use a single StunInfoCollector
instance with properly configured IPv4 and IPv6 servers instead of
creating separate instances.

feat: add IPv6 STUN server configuration support

Added interface methods and config struct fields to support both IPv4
and IPv6 STUN server configuration. Modified getter and setter methods
to handle Option<Vec<String>> type for both server types.

feat: enhance StunInfoCollector with IPv6 support

Updated StunInfoCollector to support both IPv4 and IPv6 STUN servers.
Added new constructor that accepts both server types and methods to set
them independently.

feat: add CLI argument for IPv6 STUN servers

Added command line argument support for configuring IPv6 STUN servers.
Updated configuration setup to handle both IPv4 and IPv6 STUN server
settings.

docs: add localization for STUN server configuration

Added English and Chinese localization strings for the new STUN server
configuration options, including both IPv4 and IPv6 variants.
This commit is contained in:
fanyang
2025-09-02 21:46:37 +08:00
committed by GitHub
parent 754439f03c
commit b87a05b457
10 changed files with 95 additions and 50 deletions
+13 -3
View File
@@ -718,10 +718,10 @@ impl StunInfoCollectorTrait for StunInfoCollector {
}
impl StunInfoCollector {
pub fn new(stun_servers: Vec<String>) -> Self {
pub fn new(stun_servers: Vec<String>, stun_servers_v6: Vec<String>) -> Self {
Self {
stun_servers: Arc::new(RwLock::new(stun_servers)),
stun_servers_v6: Arc::new(RwLock::new(Self::get_default_servers_v6())),
stun_servers_v6: Arc::new(RwLock::new(stun_servers_v6)),
udp_nat_test_result: Arc::new(RwLock::new(None)),
public_ipv6: Arc::new(AtomicCell::new(None)),
nat_test_result_time: Arc::new(AtomicCell::new(Local::now())),
@@ -732,7 +732,17 @@ impl StunInfoCollector {
}
pub fn new_with_default_servers() -> Self {
Self::new(Self::get_default_servers())
Self::new(Self::get_default_servers(), Self::get_default_servers_v6())
}
pub fn set_stun_servers(&self, stun_servers: Vec<String>) {
let mut g = self.stun_servers.write().unwrap();
*g = stun_servers;
}
pub fn set_stun_servers_v6(&self, stun_servers_v6: Vec<String>) {
let mut g = self.stun_servers_v6.write().unwrap();
*g = stun_servers_v6;
}
pub fn get_default_servers() -> Vec<String> {