支持websocket协议
This commit is contained in:
+3
-5
@@ -56,7 +56,6 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
opts.optopt("w", "", "客户端加密", "<password>");
|
||||
opts.optflag("W", "", "服务端加密");
|
||||
opts.optopt("u", "", "自定义mtu(默认为1430)", "<mtu>");
|
||||
opts.optflag("", "tcp", "tcp");
|
||||
opts.optopt("", "ip", "指定虚拟ip", "<ip>");
|
||||
opts.optflag("", "relay", "仅使用服务器转发");
|
||||
opts.optopt("", "par", "任务并行度(必须为正整数)", "<parallel>");
|
||||
@@ -213,7 +212,6 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
return Err(anyhow::anyhow!("'--ip {}' invalid", virtual_ip));
|
||||
}
|
||||
}
|
||||
let tcp_channel = matches.opt_present("tcp");
|
||||
let relay = matches.opt_present("relay");
|
||||
|
||||
let cipher_model = match matches.opt_get::<CipherModel>("model") {
|
||||
@@ -290,7 +288,6 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
out_ip,
|
||||
password,
|
||||
mtu,
|
||||
tcp_channel,
|
||||
virtual_ip,
|
||||
#[cfg(feature = "integrated_tun")]
|
||||
#[cfg(feature = "ip_proxy")]
|
||||
@@ -339,7 +336,9 @@ fn print_usage(program: &str, _opts: Options) {
|
||||
);
|
||||
println!(" -n <name> 给设备一个名字,便于区分不同设备,默认使用系统版本");
|
||||
println!(" -d <id> 设备唯一标识符,不使用--ip参数时,服务端凭此参数分配虚拟ip,注意不能重复");
|
||||
println!(" -s <server> 注册和中继服务器地址,以'TXT:'开头表示解析TXT记录");
|
||||
println!(
|
||||
" -s <server> 注册和中继服务器地址,协议支持使用tcp://和ws://和wss://,默认为udp://"
|
||||
);
|
||||
println!(" -e <stun-server> stun服务器,用于探测NAT类型,可使用多个地址,如-e stun.miwifi.com -e turn.cloudflare.com");
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(feature = "integrated_tun")]
|
||||
@@ -357,7 +356,6 @@ fn print_usage(program: &str, _opts: Options) {
|
||||
#[cfg(feature = "file_config")]
|
||||
println!(" -f <conf_file> 读取配置文件中的配置");
|
||||
|
||||
println!(" --tcp 和服务端使用tcp通信,默认使用udp,遇到udp qos时可指定使用tcp");
|
||||
println!(" --ip <ip> 指定虚拟ip,指定的ip不能和其他设备重复,必须有效并且在服务端所属网段下,默认情况由服务端分配");
|
||||
let mut enums = String::new();
|
||||
#[cfg(any(feature = "aes_gcm", feature = "server_encrypt"))]
|
||||
|
||||
@@ -17,6 +17,8 @@ pub struct Info {
|
||||
pub port_mapping_list: Vec<(bool, SocketAddr, String)>,
|
||||
pub in_ips: Vec<(u32, u32, Ipv4Addr)>,
|
||||
pub out_ips: Vec<(u32, u32)>,
|
||||
pub udp_listen_addr: Vec<String>,
|
||||
pub tcp_listen_addr: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::io;
|
||||
use vnt::channel::ConnectProtocol;
|
||||
use vnt::core::Vnt;
|
||||
|
||||
use crate::command::entity::{DeviceItem, Info, RouteItem};
|
||||
@@ -81,6 +82,7 @@ fn command_(cmd: CommandEnum) -> io::Result<()> {
|
||||
|
||||
pub fn command_route(vnt: &Vnt) -> Vec<RouteItem> {
|
||||
let route_table = vnt.route_table();
|
||||
let server_addr = vnt.config().server_address_str.clone();
|
||||
let mut route_list = Vec::with_capacity(route_table.len());
|
||||
for (destination, routes) in route_table {
|
||||
for route in routes {
|
||||
@@ -93,11 +95,14 @@ pub fn command_route(vnt: &Vnt) -> Vec<RouteItem> {
|
||||
} else {
|
||||
route.rt.to_string()
|
||||
};
|
||||
let interface = if route.is_tcp {
|
||||
format!("tcp@{}", route.addr)
|
||||
} else {
|
||||
route.addr.to_string()
|
||||
let interface = match route.protocol {
|
||||
ConnectProtocol::UDP => route.addr.to_string(),
|
||||
ConnectProtocol::TCP => {
|
||||
format!("tcp@{}", route.addr)
|
||||
}
|
||||
ConnectProtocol::WS | ConnectProtocol::WSS => server_addr.clone(),
|
||||
};
|
||||
|
||||
let item = RouteItem {
|
||||
destination: destination.to_string(),
|
||||
next_hop,
|
||||
@@ -145,7 +150,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
|
||||
};
|
||||
let (nat_traversal_type, rt) = if let Some(route) = vnt.route(&peer.virtual_ip) {
|
||||
let nat_traversal_type = if route.metric == 1 {
|
||||
if route.is_tcp {
|
||||
if route.protocol.is_base_tcp() {
|
||||
"tcp-p2p"
|
||||
} else {
|
||||
"p2p"
|
||||
@@ -195,6 +200,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
|
||||
}
|
||||
|
||||
pub fn command_info(vnt: &Vnt) -> Info {
|
||||
let config = vnt.config();
|
||||
let current_device = vnt.current_device();
|
||||
let nat_info = vnt.nat_info();
|
||||
let name = vnt.name().to_string();
|
||||
@@ -202,7 +208,11 @@ pub fn command_info(vnt: &Vnt) -> Info {
|
||||
let virtual_gateway = current_device.virtual_gateway().to_string();
|
||||
let virtual_netmask = current_device.virtual_netmask.to_string();
|
||||
let connect_status = format!("{:?}", vnt.connection_status());
|
||||
let relay_server = current_device.connect_server.to_string();
|
||||
let relay_server = if current_device.connect_server.port() == 0 {
|
||||
config.server_address_str.clone()
|
||||
} else {
|
||||
current_device.connect_server.to_string()
|
||||
};
|
||||
let nat_type = format!("{:?}", nat_info.nat_type);
|
||||
let public_ips: Vec<String> = nat_info.public_ips.iter().map(|v| v.to_string()).collect();
|
||||
let public_ips = public_ips.join(",");
|
||||
@@ -222,6 +232,12 @@ pub fn command_info(vnt: &Vnt) -> Info {
|
||||
let port_mapping_list = vec![];
|
||||
let in_ips = vnt.config().in_ips.clone();
|
||||
let out_ips = vnt.config().out_ips.clone();
|
||||
let udp_listen_addr = nat_info
|
||||
.udp_ports
|
||||
.iter()
|
||||
.map(|port| format!("0.0.0.0:{}", port))
|
||||
.collect();
|
||||
let tcp_listen_addr = format!("0.0.0.0:{}", nat_info.tcp_port);
|
||||
Info {
|
||||
name,
|
||||
virtual_ip,
|
||||
@@ -238,5 +254,7 @@ pub fn command_info(vnt: &Vnt) -> Info {
|
||||
port_mapping_list,
|
||||
in_ips,
|
||||
out_ips,
|
||||
udp_listen_addr,
|
||||
tcp_listen_addr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,6 @@ pub fn read_config(file_path: &str) -> anyhow::Result<(Config, Vec<String>, bool
|
||||
out_ips,
|
||||
file_conf.password,
|
||||
file_conf.mtu,
|
||||
file_conf.tcp,
|
||||
virtual_ip,
|
||||
#[cfg(feature = "integrated_tun")]
|
||||
#[cfg(feature = "ip_proxy")]
|
||||
|
||||
@@ -21,6 +21,11 @@ pub fn console_info(status: Info) {
|
||||
|
||||
println!("NAT type: {}", style(status.nat_type).green());
|
||||
println!("Relay server: {}", style(status.relay_server).green());
|
||||
println!(
|
||||
"Udp listen: {}",
|
||||
style(status.udp_listen_addr.join(", ")).green()
|
||||
);
|
||||
println!("Tcp listen: {}", style(status.tcp_listen_addr).green());
|
||||
println!("Public ips: {}", style(status.public_ips).green());
|
||||
println!("Local addr: {}", style(status.local_addr).green());
|
||||
println!("IPv6: {}", style(status.ipv6_addr).green());
|
||||
|
||||
Reference in New Issue
Block a user