[mio] 支持仅使用p2p模式

This commit is contained in:
lubeilin
2024-03-01 21:48:07 +08:00
parent 9673eaab05
commit 119f719a9f
10 changed files with 119 additions and 38 deletions
+7 -4
View File
@@ -5,6 +5,7 @@ use std::str::FromStr;
use serde::{Deserialize, Serialize};
use vnt::channel::punch::PunchModel;
use vnt::channel::UseChannelType;
use vnt::cipher::CipherModel;
use vnt::core::Config;
@@ -24,7 +25,7 @@ pub struct FileConfig {
pub mtu: Option<u32>,
pub tcp: bool,
pub ip: Option<String>,
pub relay: bool,
pub use_channel: String,
#[cfg(feature = "ip_proxy")]
pub no_proxy: bool,
pub server_encrypt: bool,
@@ -58,14 +59,14 @@ impl Default for FileConfig {
mtu: None,
tcp: false,
ip: None,
relay: false,
use_channel: "all".to_string(),
#[cfg(feature = "ip_proxy")]
no_proxy: false,
server_encrypt: false,
parallel: 1,
cipher_model: "aes_gcm".to_string(),
finger: false,
punch_model: "".to_string(),
punch_model: "all".to_string(),
ports: None,
cmd: false,
first_latency: false,
@@ -137,6 +138,8 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> {
let punch_model = PunchModel::from_str(&file_conf.punch_model)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let use_channel_type = UseChannelType::from_str(&file_conf.use_channel)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let config = Config::new(
#[cfg(any(target_os = "windows", target_os = "linux"))]
file_conf.tap,
@@ -152,7 +155,6 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> {
file_conf.mtu,
file_conf.tcp,
virtual_ip,
file_conf.relay,
#[cfg(feature = "ip_proxy")]
file_conf.no_proxy,
file_conf.server_encrypt,
@@ -163,6 +165,7 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> {
file_conf.ports,
file_conf.first_latency,
file_conf.device_name,
use_channel_type,
)
.unwrap();
Ok((config, file_conf.cmd))
+17 -3
View File
@@ -8,6 +8,7 @@ use getopts::Options;
use common::args_parse::{ips_parse, out_ips_parse};
use vnt::channel::punch::PunchModel;
use vnt::channel::UseChannelType;
use vnt::cipher::CipherModel;
use vnt::core::{Config, Vnt};
@@ -57,6 +58,7 @@ fn main() {
opts.optflag("", "cmd", "开启窗口输入");
opts.optflag("", "no-proxy", "关闭内置代理");
opts.optflag("", "first-latency", "优先延迟");
opts.optflag("", "use-channel", "使用通道 relay/p2p,默认两者都使用");
opts.optopt("f", "", "配置文件", "<conf>");
//"后台运行时,查看其他设备列表"
opts.optflag("", "list", "后台运行时,查看其他设备列表");
@@ -213,6 +215,7 @@ fn main() {
}
let tcp_channel = matches.opt_present("tcp");
let relay = matches.opt_present("relay");
let parallel = matches.opt_get::<usize>("par").unwrap().unwrap_or(1);
if parallel == 0 {
println!("'--par {}' invalid", parallel);
@@ -256,6 +259,17 @@ fn main() {
.opt_get::<PunchModel>("punch")
.unwrap()
.unwrap_or(PunchModel::All);
let use_channel_type = matches
.opt_get::<UseChannelType>("use-channel")
.unwrap()
.unwrap_or_else(||{
if relay{
UseChannelType::Relay
}else{
UseChannelType::All
}
});
let ports = matches
.opt_get::<String>("ports")
.unwrap_or(None)
@@ -280,7 +294,6 @@ fn main() {
mtu,
tcp_channel,
virtual_ip,
relay,
#[cfg(feature = "ip_proxy")]
no_proxy,
server_encrypt,
@@ -291,6 +304,7 @@ fn main() {
ports,
first_latency,
device_name,
use_channel_type,
)
.unwrap();
(config, cmd)
@@ -414,7 +428,6 @@ fn print_usage(program: &str, _opts: Options) {
println!(" --tcp 和服务端使用tcp通信,默认使用udp,遇到udp qos时可指定使用tcp");
println!(" --ip <ip> 指定虚拟ip,指定的ip不能和其他设备重复,必须有效并且在服务端所属网段下,默认情况由服务端分配");
println!(" --relay 仅使用服务器转发,不使用p2p,默认情况允许使用p2p");
println!(" --par <parallel> 任务并行度(必须为正整数),默认值为1");
if !enums.is_empty() {
println!(
@@ -425,12 +438,13 @@ fn print_usage(program: &str, _opts: Options) {
if !enums.is_empty() {
println!(" --finger 增加数据指纹校验,可增加安全性,如果服务端开启指纹校验,则客户端也必须开启");
}
println!(" --punch <punch> 取值ipv4/ipv6,ipv4表示仅使用ipv4打洞");
println!(" --punch <punch> 取值ipv4/ipv6/all,ipv4表示仅使用ipv4打洞");
println!(" --ports <port,port> 取值0~65535,指定本地监听的一组端口,默认监听两个随机端口,使用过多端口会增加网络负担");
println!(" --cmd 开启交互式命令,使用此参数开启控制台输入");
#[cfg(feature = "ip_proxy")]
println!(" --no-proxy 关闭内置代理,如需点对网则需要配置网卡NAT转发");
println!(" --first-latency 优先低延迟的通道,默认情况优先使用p2p通道");
println!(" --use-channel <p2p> 使用通道 relay/p2p/all,默认两者都使用");
println!(" --nic <tun0> 虚拟网卡名称,windows下使用tap模式则必须指定此参数");
println!();