From 6a038e8a8871585d8826594ba96de95e42ec9e56 Mon Sep 17 00:00:00 2001 From: L-Trump <37738631+L-Trump@users.noreply.github.com> Date: Sun, 13 Apr 2025 09:38:45 +0800 Subject: [PATCH] fix default listeners for config file (#777) --- easytier/locales/app.yml | 4 ++-- easytier/src/common/config.rs | 11 +++-------- easytier/src/easytier-core.rs | 8 +++++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/easytier/locales/app.yml b/easytier/locales/app.yml index dd32282..c27d021 100644 --- a/easytier/locales/app.yml +++ b/easytier/locales/app.yml @@ -11,8 +11,8 @@ core_clap: 完整URL:--config-server udp://127.0.0.1:22020/admin 仅用户名:--config-server admin,将使用官方的服务器 config_file: - en: "path to the config file, NOTE: if this is set, all other options will be ignored" - zh-CN: "配置文件路径,注意:如果设置了这个选项,其他所有选项都将被忽略" + en: "path to the config file, NOTE: the options set by cmdline args will override options in config file" + zh-CN: "配置文件路径,注意:命令行中的配置的选项会覆盖配置文件中的选项" network_name: en: "network name to identify this vpn network" zh-CN: "用于标识此VPN网络的网络名称" diff --git a/easytier/src/common/config.rs b/easytier/src/common/config.rs index c782fec..b4e8e53 100644 --- a/easytier/src/common/config.rs +++ b/easytier/src/common/config.rs @@ -76,7 +76,7 @@ pub trait ConfigLoader: Send + Sync { fn get_peers(&self) -> Vec; fn set_peers(&self, peers: Vec); - fn get_listeners(&self) -> Vec; + fn get_listeners(&self) -> Option>; fn set_listeners(&self, listeners: Vec); fn get_mapped_listeners(&self) -> Vec; @@ -510,13 +510,8 @@ impl ConfigLoader for TomlConfigLoader { self.config.lock().unwrap().peer = Some(peers); } - fn get_listeners(&self) -> Vec { - self.config - .lock() - .unwrap() - .listeners - .clone() - .unwrap_or_default() + fn get_listeners(&self) -> Option> { + self.config.lock().unwrap().listeners.clone() } fn set_listeners(&self, listeners: Vec) { diff --git a/easytier/src/easytier-core.rs b/easytier/src/easytier-core.rs index 986b1a8..1d6fa84 100644 --- a/easytier/src/easytier-core.rs +++ b/easytier/src/easytier-core.rs @@ -182,7 +182,6 @@ struct Cli { env = "ET_LISTENERS", value_delimiter = ',', help = t!("core_clap.listeners").to_string(), - default_values_t = ["11010".to_string()], num_args = 0.. )] listeners: Vec, @@ -558,6 +557,13 @@ impl TryFrom<&Cli> for TomlConfigLoader { .map(|s| s.parse().unwrap()) .collect(), ); + } else if cfg.get_listeners() == None { + cfg.set_listeners( + Cli::parse_listeners(false, vec!["11010".to_string()])? + .into_iter() + .map(|s| s.parse().unwrap()) + .collect(), + ); } if !cli.mapped_listeners.is_empty() {