支持客户端加密

This commit is contained in:
lubeilin
2023-06-26 22:38:15 +08:00
parent e8af503130
commit be3bf82e35
22 changed files with 309 additions and 106 deletions
+5
View File
@@ -62,6 +62,11 @@ fn common() -> Command {
.long("out-ip")
.help(switch_out_ip_help())
.action(ArgAction::Append)
).arg(
Arg::new("password")
.long("password")
.help(switch_password_help())
.action(ArgAction::Set)
).arg(
Arg::new("config")
.long("config")
+7 -2
View File
@@ -38,6 +38,7 @@ pub struct StartConfig {
#[cfg(any(unix))]
pub off_command_server: bool,
pub log: bool,
pub password: Option<String>,
}
fn ips_parse(ips: &Vec<String>) -> Result<Vec<(u32, u32, Ipv4Addr)>, String> {
@@ -163,7 +164,7 @@ pub fn default_config(start_args: StartArgs) -> Result<StartConfig, String> {
}
}
Err(e) => {
return Err(format!("{} :{:?}",i18n::switch_relay_server_address_error(), e));
return Err(format!("{} :{:?}", i18n::switch_relay_server_address_error(), e));
}
};
println!("中继服务器:{:?}", server);
@@ -187,6 +188,7 @@ pub fn default_config(start_args: StartArgs) -> Result<StartConfig, String> {
#[cfg(any(unix))]
off_command_server: start_args.off_command_server,
log: start_args.log,
password: start_args.password,
};
println!("========参数配置========");
Ok(base_config)
@@ -268,7 +270,7 @@ pub fn read_config_file(config_path: PathBuf) -> Result<StartConfig, String> {
}
}
Err(e) => {
return Err(format!("{}:{:?}",i18n::switch_relay_server_address_error(), e));
return Err(format!("{}:{:?}", i18n::switch_relay_server_address_error(), e));
}
};
println!("中继服务器:{:?}", server);
@@ -294,6 +296,7 @@ pub fn read_config_file(config_path: PathBuf) -> Result<StartConfig, String> {
#[cfg(any(unix))]
off_command_server: args_config.off_command_server,
log,
password:args_config.password
};
println!("========参数配置========");
Ok(base_config)
@@ -331,6 +334,7 @@ pub struct ArgsConfig {
pub off_command_server: bool,
#[serde(default = "default_false")]
pub log: bool,
pub password: Option<String>,
}
#[cfg(windows)]
@@ -355,6 +359,7 @@ impl ArgsConfig {
log: start_config.log,
#[cfg(any(unix))]
off_command_server: start_config.off_command_server,
password: start_config.password,
}
}
}
+3
View File
@@ -73,6 +73,9 @@ pub fn switch_in_ip_help() -> String {
pub fn switch_out_ip_help() -> String {
rust_i18n::t!("switch_out_ip_help")
}
pub fn switch_password_help() -> String {
rust_i18n::t!("switch_password_help")
}
pub fn switch_config_help() -> String {
rust_i18n::t!("switch_config_help")
+3
View File
@@ -107,6 +107,9 @@ pub struct StartArgs {
/// Use when configuring peer-to-peer networks
#[arg(long)]
out_ip: Option<Vec<String>>,
/// 客户端数据加密
#[arg(long)]
password:Option<String>,
/// 读取配置文件 --config config_file_path
/// Read configuration file
#[arg(long)]
+1
View File
@@ -45,6 +45,7 @@ pub async fn main0(base_args: BaseArgs) {
start_config.nat_test_server.clone(),
start_config.in_ips.clone(),
start_config.out_ips.clone(),
start_config.password.clone(),
);
let lock = match config::lock_file() {
Ok(lock) => {
+4 -3
View File
@@ -42,7 +42,7 @@ fn not_started() -> bool {
if state == ServiceState::Running {
return false;
} else {
println!("{}",i18n::switch_service_not_start_print())
println!("{}", i18n::switch_service_not_start_print())
}
}
Err(e) => {
@@ -100,7 +100,7 @@ pub fn main0(base_args: BaseArgs) {
}
}
} else {
println!("{}",i18n::switch_service_not_stopped_print());
println!("{}", i18n::switch_service_not_stopped_print());
}
}
Err(e) => {
@@ -118,6 +118,7 @@ pub fn main0(base_args: BaseArgs) {
start_config.nat_test_server,
start_config.in_ips,
start_config.out_ips,
start_config.password,
);
let lock = match config::lock_file() {
Ok(lock) => {
@@ -179,7 +180,7 @@ pub fn main0(base_args: BaseArgs) {
return;
}
if service_state().is_ok() {
println!("{}",i18n::switch_server_already_installed_print());
println!("{}", i18n::switch_server_already_installed_print());
return;
}
let path: PathBuf = args.path.into();
+3 -4
View File
@@ -73,7 +73,6 @@ async fn service_main(arguments: Vec<OsString>) -> windows_service::Result<()> {
match start_switch(arguments).await {
Ok(_) => {
parker.park();
}
Err(e) => {
log::error!("服务启动失败 {:?}",e);
@@ -171,12 +170,13 @@ async fn start_switch(arguments: Vec<OsString>) -> switch::Result<()> {
start_config.nat_test_server,
start_config.in_ips,
start_config.out_ips,
start_config.password,
);
log::info!("switch-service服务启动");
tokio::spawn(async move {
match Switch::start(config).await {
tokio::spawn(async move {
match Switch::start(config).await {
Ok(switch) => {
let switch = Arc::new(switch);
let command_server = crate::command::server::CommandServer::new();
@@ -191,7 +191,6 @@ async fn start_switch(arguments: Vec<OsString>) -> switch::Result<()> {
log::error!("{:?}", e);
}
};
});
Ok(())
}