Require a full config server URL (#2459)

Co-authored-by: 刚刚 <239500008+225284228a-droid@users.noreply.github.com>
This commit is contained in:
刚刚
2026-07-31 16:47:40 +08:00
committed by GitHub
co-authored by 刚刚
parent 4923a13c5d
commit fc3914baf5
2 changed files with 19 additions and 17 deletions
+15 -11
View File
@@ -39,12 +39,8 @@ pub struct ConfigServerEndpoint {
impl ConfigServerEndpoint { impl ConfigServerEndpoint {
pub fn parse(input: &str, supports_scheme: impl FnOnce(&Url) -> bool) -> anyhow::Result<Self> { pub fn parse(input: &str, supports_scheme: impl FnOnce(&Url) -> bool) -> anyhow::Result<Self> {
let endpoint = match Url::parse(input) { let endpoint = Url::parse(input)
Ok(endpoint) => endpoint, .map_err(|error| anyhow::anyhow!("failed to parse config server URL: {error}"))?;
Err(_) => format!("udp://config-server.easytier.cn:22020/{input}")
.parse()
.map_err(|error| anyhow::anyhow!("failed to parse config server URL: {error}"))?,
};
if !supports_scheme(&endpoint) { if !supports_scheme(&endpoint) {
anyhow::bail!("unsupported config server scheme: {}", endpoint.scheme()); anyhow::bail!("unsupported config server scheme: {}", endpoint.scheme());
} }
@@ -371,12 +367,20 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn endpoint_normalizes_shorthand_and_non_websocket_paths() { fn endpoint_normalizes_non_websocket_paths() {
let endpoint = ConfigServerEndpoint::parse("team%2Ftoken", |_| true).unwrap(); let endpoint =
ConfigServerEndpoint::parse("udp://example.com/team%2Ftoken", |_| true).unwrap();
assert_eq!(endpoint.token(), "team/token"); assert_eq!(endpoint.token(), "team/token");
assert_eq!( assert_eq!(endpoint.connect_url().as_str(), "udp://example.com");
endpoint.connect_url().as_str(), }
"udp://config-server.easytier.cn:22020"
#[test]
fn endpoint_rejects_token_shorthand() {
let error = ConfigServerEndpoint::parse("team%2Ftoken", |_| true).unwrap_err();
assert!(
error
.to_string()
.contains("failed to parse config server URL")
); );
} }
+4 -6
View File
@@ -3,13 +3,11 @@ _version: 2
core_clap: core_clap:
config_server: config_server:
en: |+ en: |+
config server address, allow format: config server address, must be a full URL:
full url: --config-server udp://127.0.0.1:22020/admin, 'udp' can be replaced with tcp, ws, wss (when config server ws is proxied to wss) --config-server udp://127.0.0.1:22020/admin, 'udp' can be replaced with tcp, ws, wss (when config server ws is proxied to wss)
only user name: --config-server admin, will use official server
zh-CN: |+ zh-CN: |+
配置服务器地址。允许格式 配置服务器地址,必须使用完整 URL
完整URL--config-server udp://127.0.0.1:22020/adminudp可以根据配置服务器替换为 tcpwswss(配置服务器ws被代理为wss时) --config-server udp://127.0.0.1:22020/adminudp 可以根据配置服务器替换为 tcpwswss配置服务器 ws 被代理为 wss 时)
仅用户名:--config-server admin,将使用官方的服务器
machine_id: machine_id:
en: |+ en: |+
the machine id to identify this machine, used for config recovery after disconnection, must be unique and fixed. by default it is loaded from persisted local state; on first start it may be migrated from system information or generated, then remains fixed. the machine id to identify this machine, used for config recovery after disconnection, must be unique and fixed. by default it is loaded from persisted local state; on first start it may be migrated from system information or generated, then remains fixed.