feat(core): Refactor IDN and URL handling logic (#1533)

* feat(core): Refactor IDN and URL handling logic

* feat(tests): add dual_convert option for URL serialization in IDN tests
This commit is contained in:
Mg Pig
2025-11-03 22:15:40 +08:00
committed by GitHub
parent 8ab98bba8f
commit 6bb2fd9a15
5 changed files with 80 additions and 222 deletions
+12 -21
View File
@@ -10,7 +10,6 @@ use crate::{
},
constants::EASYTIER_VERSION,
global_ctx::{EventBusSubscriber, GlobalCtxEvent},
idn::safe_convert_idn_to_ascii,
},
instance::instance::Instance,
proto::api::instance::list_peer_route_pair,
@@ -525,13 +524,9 @@ impl NetworkConfig {
{
NetworkingMethod::PublicServer => {
let public_server_url = self.public_server_url.clone().unwrap_or_default();
let converted_public_server_url = safe_convert_idn_to_ascii(&public_server_url);
cfg.set_peers(vec![PeerConfig {
uri: converted_public_server_url.parse().with_context(|| {
format!(
"failed to parse public server uri: {}",
converted_public_server_url
)
uri: public_server_url.parse().with_context(|| {
format!("failed to parse public server uri: {}", public_server_url)
})?,
}]);
}
@@ -541,11 +536,10 @@ impl NetworkConfig {
if peer_url.is_empty() {
continue;
}
let converted_peer_url = safe_convert_idn_to_ascii(peer_url);
peers.push(PeerConfig {
uri: converted_peer_url.parse().with_context(|| {
format!("failed to parse peer uri: {}", converted_peer_url)
})?,
uri: peer_url
.parse()
.with_context(|| format!("failed to parse peer uri: {}", peer_url))?,
});
}
@@ -559,10 +553,11 @@ impl NetworkConfig {
if listener_url.is_empty() {
continue;
}
let converted_listener_url = safe_convert_idn_to_ascii(listener_url);
listener_urls.push(converted_listener_url.parse().with_context(|| {
format!("failed to parse listener uri: {}", converted_listener_url)
})?);
listener_urls.push(
listener_url
.parse()
.with_context(|| format!("failed to parse listener uri: {}", listener_url))?,
);
}
cfg.set_listeners(listener_urls);
@@ -656,12 +651,8 @@ impl NetworkConfig {
self.mapped_listeners
.iter()
.map(|s| {
let converted_s = safe_convert_idn_to_ascii(s);
converted_s
.parse()
.with_context(|| {
format!("mapped listener is not a valid url: {}", converted_s)
})
s.parse()
.with_context(|| format!("mapped listener is not a valid url: {}", s))
.unwrap()
})
.map(|s: url::Url| {