默认使用广播代替组播、精简依赖

This commit is contained in:
lubeilin
2023-06-29 23:14:59 +08:00
parent be3bf82e35
commit 890e5f7391
31 changed files with 493 additions and 412 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "switch-desktop"
version = "1.0.6"
version = "1.0.7"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+1
View File
@@ -11,6 +11,7 @@ switch_tap_help: "Use tap mode, tun mode will be used by default"
switch_in_ip_help: "Use when configuring point-to-network (IP proxy), --in-ip 192.168.10.0/24,10.26.0.3, which means it is allowed to receive data from the network segment 192.168.10.0/24 and forward it to 10.26.0.3"
switch_out_ip_help: "Use when configuring point-to-network, --out-ip 192.168.10.0/24,192.168.1.10, which means that the data with the target of 192.168.10.0/24 is allowed to be forwarded from the network card 192.168.1.10"
switch_password_help: "Client Data Encryption"
switch_simulate_multicast_help: "Simulate multicast. By default, multicast data will be sent as broadcast, which is more compatible, but it will cause traffic waste. After it is turned on, it will simulate real multicast data transmission"
switch_config_help: "Read configuration file"
switch_stop_about: "Stop background service"
switch_route_about: "View route"
+1
View File
@@ -11,6 +11,7 @@ switch_tap_help: "使用tap模式,默认会使用tun模式"
switch_in_ip_help: "配置点对网(IP代理)时使用,--in-ip 192.168.10.0/24,10.26.0.3,表示允许接收网段192.168.10.0/24的数据并转发到10.26.0.3"
switch_out_ip_help: "配置点对网时使用,--out-ip 192.168.10.0/24,192.168.1.10,表示允许目标为192.168.10.0/24的数据从网卡192.168.1.10转发出去"
switch_password_help: "使用该密码生成的密钥对客户端数据进行加密,并且服务端无法解密。使用相同密码的客户端才能通信"
switch_simulate_multicast_help: "模拟组播,默认情况下组播数据会被当作广播发送,兼容性更强,但是会造成流量浪费。开启后会模拟真实组播的数据发送"
switch_config_help: "读取配置文件"
switch_stop_about: "停止后台服务"
switch_route_about: "查看路由"
+8 -1
View File
@@ -50,7 +50,8 @@ fn common() -> Command {
Arg::new("tap")
.long("tap")
.help(switch_tap_help())
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.value_parser(BoolishValueParser::new()),
).arg(
Arg::new("in_ip")
.long("in-ip")
@@ -67,6 +68,12 @@ fn common() -> Command {
.long("password")
.help(switch_password_help())
.action(ArgAction::Set)
).arg(
Arg::new("simulate_multicast")
.long("simulate-multicast")
.help(switch_simulate_multicast_help())
.action(ArgAction::SetTrue)
.value_parser(BoolishValueParser::new()),
).arg(
Arg::new("config")
.long("config")
+7 -1
View File
@@ -39,6 +39,7 @@ pub struct StartConfig {
pub off_command_server: bool,
pub log: bool,
pub password: Option<String>,
pub simulate_multicast:bool,
}
fn ips_parse(ips: &Vec<String>) -> Result<Vec<(u32, u32, Ipv4Addr)>, String> {
@@ -189,6 +190,7 @@ pub fn default_config(start_args: StartArgs) -> Result<StartConfig, String> {
off_command_server: start_args.off_command_server,
log: start_args.log,
password: start_args.password,
simulate_multicast:start_args.simulate_multicast,
};
println!("========参数配置========");
Ok(base_config)
@@ -296,7 +298,8 @@ 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
password:args_config.password,
simulate_multicast:args_config.simulate_multicast
};
println!("========参数配置========");
Ok(base_config)
@@ -335,6 +338,8 @@ pub struct ArgsConfig {
#[serde(default = "default_false")]
pub log: bool,
pub password: Option<String>,
#[serde(default = "default_false")]
pub simulate_multicast:bool,
}
#[cfg(windows)]
@@ -360,6 +365,7 @@ impl ArgsConfig {
#[cfg(any(unix))]
off_command_server: start_config.off_command_server,
password: start_config.password,
simulate_multicast:start_config.simulate_multicast,
}
}
}
+3
View File
@@ -76,6 +76,9 @@ pub fn switch_out_ip_help() -> String {
pub fn switch_password_help() -> String {
rust_i18n::t!("switch_password_help")
}
pub fn switch_simulate_multicast_help() -> String {
rust_i18n::t!("switch_simulate_multicast_help")
}
pub fn switch_config_help() -> String {
rust_i18n::t!("switch_config_help")
+3
View File
@@ -110,6 +110,9 @@ pub struct StartArgs {
/// 客户端数据加密
#[arg(long)]
password:Option<String>,
/// 模拟组播,默认情况下组播数据会被当作广播发送,兼容性更强,但是会造成流量浪费,开启后会模拟真实组播的数据发送
#[arg(long)]
simulate_multicast:bool,
/// 读取配置文件 --config config_file_path
/// Read configuration file
#[arg(long)]
+1
View File
@@ -46,6 +46,7 @@ pub async fn main0(base_args: BaseArgs) {
start_config.in_ips.clone(),
start_config.out_ips.clone(),
start_config.password.clone(),
start_config.simulate_multicast,
);
let lock = match config::lock_file() {
Ok(lock) => {
+1
View File
@@ -119,6 +119,7 @@ pub fn main0(base_args: BaseArgs) {
start_config.in_ips,
start_config.out_ips,
start_config.password,
start_config.simulate_multicast,
);
let lock = match config::lock_file() {
Ok(lock) => {
+1
View File
@@ -171,6 +171,7 @@ async fn start_switch(arguments: Vec<OsString>) -> switch::Result<()> {
start_config.in_ips,
start_config.out_ips,
start_config.password,
start_config.simulate_multicast,
);
log::info!("switch-service服务启动");