mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
Address review comments
This commit is contained in:
@@ -194,8 +194,8 @@ core_clap:
|
|||||||
en: "the url of the ipv6 listener, e.g.: tcp://[::]:11010, if not set, will listen on random udp port"
|
en: "the url of the ipv6 listener, e.g.: tcp://[::]:11010, if not set, will listen on random udp port"
|
||||||
zh-CN: "IPv6 监听器的URL,例如:tcp://[::]:11010,如果未设置,将在随机UDP端口上监听"
|
zh-CN: "IPv6 监听器的URL,例如:tcp://[::]:11010,如果未设置,将在随机UDP端口上监听"
|
||||||
compression:
|
compression:
|
||||||
en: "compression algorithm to use, support none, zstd, lzo. default is none"
|
en: "compression algorithm to use, supported: %{algorithms}. default is none"
|
||||||
zh-CN: "要使用的压缩算法,支持 none、zstd、lzo。默认为 none"
|
zh-CN: "要使用的压缩算法,支持:%{algorithms}。默认为 none"
|
||||||
mapped_listeners:
|
mapped_listeners:
|
||||||
en: "manually specify the public address of the listener, other nodes can use this address to connect to this node. e.g.: tcp://123.123.123.123:11223, can specify multiple."
|
en: "manually specify the public address of the listener, other nodes can use this address to connect to this node. e.g.: tcp://123.123.123.123:11223, can specify multiple."
|
||||||
zh-CN: "手动指定监听器的公网地址,其他节点可以使用该地址连接到本节点。例如:tcp://123.123.123.123:11223,可以指定多个。"
|
zh-CN: "手动指定监听器的公网地址,其他节点可以使用该地址连接到本节点。例如:tcp://123.123.123.123:11223,可以指定多个。"
|
||||||
|
|||||||
+40
-14
@@ -46,6 +46,29 @@ fn supported_compression_algorithms() -> &'static str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compression_help() -> String {
|
||||||
|
t!(
|
||||||
|
"core_clap.compression",
|
||||||
|
algorithms = supported_compression_algorithms()
|
||||||
|
)
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_compression_algorithm(compression: &str) -> anyhow::Result<CompressionAlgoPb> {
|
||||||
|
match compression {
|
||||||
|
"none" => Ok(CompressionAlgoPb::None),
|
||||||
|
#[cfg(feature = "zstd")]
|
||||||
|
"zstd" => Ok(CompressionAlgoPb::Zstd),
|
||||||
|
#[cfg(feature = "lzo")]
|
||||||
|
"lzo" => Ok(CompressionAlgoPb::Lzo),
|
||||||
|
_ => anyhow::bail!(
|
||||||
|
"unknown compression algorithm: {}, supported: {}",
|
||||||
|
compression,
|
||||||
|
supported_compression_algorithms()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
windows_service::define_windows_service!(ffi_service_main, win_service_main);
|
windows_service::define_windows_service!(ffi_service_main, win_service_main);
|
||||||
|
|
||||||
@@ -522,7 +545,7 @@ struct NetworkOptions {
|
|||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
env = "ET_COMPRESSION",
|
env = "ET_COMPRESSION",
|
||||||
help = t!("core_clap.compression").to_string(),
|
help = compression_help(),
|
||||||
)]
|
)]
|
||||||
compression: Option<String>,
|
compression: Option<String>,
|
||||||
|
|
||||||
@@ -1115,19 +1138,7 @@ impl NetworkOptions {
|
|||||||
f.need_p2p = self.need_p2p.unwrap_or(f.need_p2p);
|
f.need_p2p = self.need_p2p.unwrap_or(f.need_p2p);
|
||||||
f.multi_thread = self.multi_thread.unwrap_or(f.multi_thread);
|
f.multi_thread = self.multi_thread.unwrap_or(f.multi_thread);
|
||||||
if let Some(compression) = &self.compression {
|
if let Some(compression) = &self.compression {
|
||||||
f.data_compress_algo = match compression.as_str() {
|
f.data_compress_algo = parse_compression_algorithm(compression)?.into();
|
||||||
"none" => CompressionAlgoPb::None,
|
|
||||||
#[cfg(feature = "zstd")]
|
|
||||||
"zstd" => CompressionAlgoPb::Zstd,
|
|
||||||
#[cfg(feature = "lzo")]
|
|
||||||
"lzo" => CompressionAlgoPb::Lzo,
|
|
||||||
_ => panic!(
|
|
||||||
"unknown compression algorithm: {}, supported: {}",
|
|
||||||
compression,
|
|
||||||
supported_compression_algorithms()
|
|
||||||
),
|
|
||||||
}
|
|
||||||
.into();
|
|
||||||
}
|
}
|
||||||
f.bind_device = self.bind_device.unwrap_or(f.bind_device);
|
f.bind_device = self.bind_device.unwrap_or(f.bind_device);
|
||||||
f.enable_kcp_proxy = self.enable_kcp_proxy.unwrap_or(f.enable_kcp_proxy);
|
f.enable_kcp_proxy = self.enable_kcp_proxy.unwrap_or(f.enable_kcp_proxy);
|
||||||
@@ -1640,6 +1651,21 @@ async fn validate_config(cli: &Cli) -> anyhow::Result<()> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_compression_help_uses_supported_algorithms() {
|
||||||
|
assert!(compression_help().contains(supported_compression_algorithms()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_compression_algorithm_rejects_unknown() {
|
||||||
|
let err = parse_compression_algorithm("snappy")
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
assert!(err.contains("snappy"));
|
||||||
|
assert!(err.contains(supported_compression_algorithms()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_listeners() {
|
fn test_parse_listeners() {
|
||||||
type IpSchemeMap = fn(&IpScheme) -> String;
|
type IpSchemeMap = fn(&IpScheme) -> String;
|
||||||
|
|||||||
Reference in New Issue
Block a user