修改默认版本设置
This commit is contained in:
@@ -211,6 +211,7 @@ impl Vnt {
|
||||
config.punch_model,
|
||||
config.tcp,
|
||||
tcp_socket_sender.clone(),
|
||||
external_route.clone(),
|
||||
);
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
|
||||
@@ -94,10 +94,6 @@ impl Config {
|
||||
if name.is_empty() || name.len() > 128 {
|
||||
return Err(anyhow!("name too long"));
|
||||
}
|
||||
if name_servers.is_empty() {
|
||||
name_servers.push("114.114.114.114:53".to_string());
|
||||
name_servers.push("8.8.8.8:53".to_string());
|
||||
}
|
||||
let server_address =
|
||||
address_choose(dns_query_all(&server_address_str, name_servers.clone())?)?;
|
||||
Ok(Self {
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::proto::message::HandshakeRequest;
|
||||
use crate::proto::message::SecretHandshakeRequest;
|
||||
#[cfg(feature = "server_encrypt")]
|
||||
use crate::protocol::body::RSA_ENCRYPTION_RESERVED;
|
||||
use crate::protocol::{service_packet, NetPacket, Protocol, Version, MAX_TTL};
|
||||
use crate::protocol::{service_packet, NetPacket, Protocol, MAX_TTL};
|
||||
|
||||
pub enum HandshakeEnum {
|
||||
NotSecret,
|
||||
@@ -65,7 +65,7 @@ impl Handshake {
|
||||
})?;
|
||||
let buf = vec![0u8; 12 + bytes.len()];
|
||||
let mut net_packet = NetPacket::new(buf)?;
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_gateway_flag(true);
|
||||
net_packet.set_destination(GATEWAY_IP);
|
||||
net_packet.set_source(SELF_IP);
|
||||
@@ -97,7 +97,7 @@ pub fn secret_handshake_request_packet(
|
||||
12 + bytes.len(),
|
||||
vec![0u8; 12 + bytes.len() + RSA_ENCRYPTION_RESERVED],
|
||||
)?;
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_gateway_flag(true);
|
||||
net_packet.set_destination(GATEWAY_IP);
|
||||
net_packet.set_source(SELF_IP);
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::channel::context::Context;
|
||||
use crate::cipher::Cipher;
|
||||
use crate::handle::{BaseConfigInfo, CurrentDeviceInfo};
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::{control_packet, NetPacket, Protocol, Version, MAX_TTL};
|
||||
use crate::protocol::{control_packet, NetPacket, Protocol, MAX_TTL};
|
||||
use crate::util::Scheduler;
|
||||
|
||||
pub fn addr_request(
|
||||
@@ -51,7 +51,7 @@ pub fn addr_request0(
|
||||
let gateway_ip = current_dev.virtual_gateway;
|
||||
let src_ip = current_dev.virtual_ip;
|
||||
let mut packet = NetPacket::new_encrypt([0; 12 + ENCRYPTION_RESERVED]).unwrap();
|
||||
packet.set_version(Version::V1);
|
||||
packet.set_default_version();
|
||||
packet.set_gateway_flag(true);
|
||||
packet.set_protocol(Protocol::Control);
|
||||
packet.set_transport_protocol(control_packet::Protocol::AddrRequest.into());
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::cipher::Cipher;
|
||||
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::control_packet::PingPacket;
|
||||
use crate::protocol::{control_packet, NetPacket, Protocol, Version};
|
||||
use crate::protocol::{control_packet, NetPacket, Protocol};
|
||||
use crate::util::Scheduler;
|
||||
|
||||
/// 定时发送心跳包
|
||||
@@ -213,7 +213,7 @@ fn heartbeat_packet(
|
||||
dest: Ipv4Addr,
|
||||
) -> io::Result<NetPacket<[u8; 12 + 4 + ENCRYPTION_RESERVED]>> {
|
||||
let mut net_packet = NetPacket::new_encrypt([0u8; 12 + 4 + ENCRYPTION_RESERVED])?;
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_protocol(Protocol::Control);
|
||||
net_packet.set_transport_protocol(control_packet::Protocol::Ping.into());
|
||||
net_packet.first_set_ttl(5);
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
||||
use crate::nat::NatTest;
|
||||
use crate::proto::message::{PunchInfo, PunchNatType};
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::{control_packet, other_turn_packet, NetPacket, Protocol, Version, MAX_TTL};
|
||||
use crate::protocol::{control_packet, other_turn_packet, NetPacket, Protocol, MAX_TTL};
|
||||
use crate::util::Scheduler;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -135,7 +135,7 @@ fn punch_start(
|
||||
) {
|
||||
while let Ok((peer_ip, nat_info)) = receiver.recv() {
|
||||
let mut packet = NetPacket::new_encrypt([0u8; 12 + ENCRYPTION_RESERVED]).unwrap();
|
||||
packet.set_version(Version::V1);
|
||||
packet.set_default_version();
|
||||
packet.first_set_ttl(1);
|
||||
packet.set_protocol(Protocol::Control);
|
||||
packet.set_transport_protocol(control_packet::Protocol::PunchRequest.into());
|
||||
@@ -322,7 +322,7 @@ fn punch_packet(
|
||||
.write_to_bytes()
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("punch_packet {:?}", e)))?;
|
||||
let mut net_packet = NetPacket::new_encrypt(vec![0u8; 12 + bytes.len() + ENCRYPTION_RESERVED])?;
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_protocol(Protocol::OtherTurn);
|
||||
net_packet.set_transport_protocol(other_turn_packet::Protocol::Punch.into());
|
||||
net_packet.first_set_ttl(MAX_TTL);
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::channel::context::Context;
|
||||
use crate::handle::CurrentDeviceInfo;
|
||||
use crate::proto::message::{ClientStatusInfo, PunchNatType, RouteItem};
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::{service_packet, NetPacket, Protocol, Version, HEAD_LEN, MAX_TTL};
|
||||
use crate::protocol::{service_packet, NetPacket, Protocol, HEAD_LEN, MAX_TTL};
|
||||
use crate::util::{Scheduler, WatchSingleU64Adder, WatchU64Adder};
|
||||
use crossbeam_utils::atomic::AtomicCell;
|
||||
use protobuf::Message;
|
||||
@@ -91,7 +91,7 @@ fn send_up_status_packet(
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("up_status_packet {:?}", e)))?;
|
||||
let mut net_packet =
|
||||
NetPacket::new_encrypt(vec![0; HEAD_LEN + buf.len() + ENCRYPTION_RESERVED])?;
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_gateway_flag(true);
|
||||
net_packet.set_protocol(Protocol::Service);
|
||||
net_packet.set_transport_protocol_into(service_packet::Protocol::ClientStatusInfo);
|
||||
|
||||
@@ -78,7 +78,7 @@ impl<Call: VntCallback> RecvDataHandler<Call> {
|
||||
config_info,
|
||||
nat_test.clone(),
|
||||
callback,
|
||||
external_route,
|
||||
external_route.clone(),
|
||||
handshake,
|
||||
);
|
||||
let client = ClientPacketHandler::new(
|
||||
@@ -88,6 +88,7 @@ impl<Call: VntCallback> RecvDataHandler<Call> {
|
||||
peer_nat_info_map,
|
||||
nat_test,
|
||||
route,
|
||||
external_route.clone(),
|
||||
#[cfg(feature = "ip_proxy")]
|
||||
ip_proxy_map,
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ use crate::proto::message::{DeviceList, HandshakeResponse, RegistrationResponse}
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::control_packet::ControlPacket;
|
||||
use crate::protocol::error_packet::InErrorPacket;
|
||||
use crate::protocol::{ip_turn_packet, service_packet, NetPacket, Protocol, Version, MAX_TTL};
|
||||
use crate::protocol::{ip_turn_packet, service_packet, NetPacket, Protocol, MAX_TTL};
|
||||
use crate::tun_tap_device::tun_create_helper::DeviceAdapter;
|
||||
use crate::{proto, PeerClientInfo};
|
||||
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
|
||||
@@ -539,7 +539,7 @@ impl<Call: VntCallback> ServerPacketHandler<Call> {
|
||||
let mut poll_device = NetPacket::new_encrypt([0; 12 + ENCRYPTION_RESERVED])?;
|
||||
poll_device.set_source(current_device.virtual_ip);
|
||||
poll_device.set_destination(GATEWAY_IP);
|
||||
poll_device.set_version(Version::V1);
|
||||
poll_device.set_default_version();
|
||||
poll_device.set_gateway_flag(true);
|
||||
poll_device.first_set_ttl(MAX_TTL);
|
||||
poll_device.set_protocol(Protocol::Service);
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::cipher::Cipher;
|
||||
use crate::handle::{GATEWAY_IP, SELF_IP};
|
||||
use crate::proto::message::RegistrationRequest;
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::{service_packet, NetPacket, Protocol, Version, MAX_TTL};
|
||||
use crate::protocol::{service_packet, NetPacket, Protocol, MAX_TTL};
|
||||
|
||||
/// 注册数据
|
||||
pub fn registration_request_packet(
|
||||
@@ -43,7 +43,7 @@ pub fn registration_request_packet(
|
||||
let mut net_packet = NetPacket::new_encrypt(buf)?;
|
||||
net_packet.set_destination(GATEWAY_IP);
|
||||
net_packet.set_source(SELF_IP);
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_gateway_flag(true);
|
||||
net_packet.set_protocol(Protocol::Service);
|
||||
net_packet.set_transport_protocol(service_packet::Protocol::RegistrationRequest.into());
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::ip_proxy::{IpProxyMap, ProxyHandler};
|
||||
use crate::protocol;
|
||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||
use crate::protocol::ip_turn_packet::BroadcastPacket;
|
||||
use crate::protocol::{ip_turn_packet, NetPacket, Version, MAX_TTL};
|
||||
use crate::protocol::{ip_turn_packet, NetPacket, MAX_TTL};
|
||||
|
||||
mod channel_group;
|
||||
pub mod tun_handler;
|
||||
@@ -87,7 +87,7 @@ fn broadcast(
|
||||
let buf = vec![0u8; 12 + 1 + p2p_ips.len() * 4 + net_packet.data_len() + ENCRYPTION_RESERVED];
|
||||
//剩余的发送到服务端,需要告知哪些已发送过
|
||||
let mut server_packet = NetPacket::new_encrypt(buf)?;
|
||||
server_packet.set_version(Version::V1);
|
||||
server_packet.set_default_version();
|
||||
server_packet.set_gateway_flag(true);
|
||||
server_packet.first_set_ttl(MAX_TTL);
|
||||
server_packet.set_source(net_packet.source());
|
||||
@@ -123,7 +123,7 @@ pub fn base_handle(
|
||||
let src_ip = ipv4_packet.source_ip();
|
||||
let mut dest_ip = ipv4_packet.destination_ip();
|
||||
let mut net_packet = NetPacket::new0(data_len, buf)?;
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_protocol(protocol::Protocol::IpTurn);
|
||||
net_packet.set_transport_protocol(ip_turn_packet::Protocol::Ipv4.into());
|
||||
net_packet.first_set_ttl(6);
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::cipher::Cipher;
|
||||
use crate::handle::CurrentDeviceInfo;
|
||||
use crate::ip_proxy::ProxyHandler;
|
||||
use crate::protocol;
|
||||
use crate::protocol::{NetPacket, Version, MAX_TTL};
|
||||
use crate::protocol::{NetPacket, MAX_TTL};
|
||||
use crate::util::StopManager;
|
||||
#[derive(Clone)]
|
||||
pub struct IcmpProxy {
|
||||
@@ -172,7 +172,7 @@ fn recv_handle(
|
||||
let virtual_ip = current_device.virtual_ip();
|
||||
|
||||
let mut net_packet = NetPacket::new0(data_len, buf).unwrap();
|
||||
net_packet.set_version(Version::V1);
|
||||
net_packet.set_default_version();
|
||||
net_packet.set_protocol(protocol::Protocol::IpTurn);
|
||||
net_packet.set_transport_protocol(
|
||||
protocol::ip_turn_packet::Protocol::Ipv4.into(),
|
||||
|
||||
@@ -27,14 +27,15 @@ pub mod service_packet;
|
||||
|
||||
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum Version {
|
||||
V1,
|
||||
V2,
|
||||
Unknown(u8),
|
||||
}
|
||||
|
||||
impl From<u8> for Version {
|
||||
fn from(value: u8) -> Self {
|
||||
match value {
|
||||
1 => Version::V1,
|
||||
// 版本从2开始,用于和stun协议的binging响应区分开
|
||||
2 => Version::V2,
|
||||
val => Version::Unknown(val),
|
||||
}
|
||||
}
|
||||
@@ -43,7 +44,7 @@ impl From<u8> for Version {
|
||||
impl Into<u8> for Version {
|
||||
fn into(self) -> u8 {
|
||||
match self {
|
||||
Version::V1 => 1,
|
||||
Version::V2 => 2,
|
||||
Version::Unknown(val) => val,
|
||||
}
|
||||
}
|
||||
@@ -207,8 +208,8 @@ impl<B: AsRef<[u8]> + AsMut<[u8]>> NetPacket<B> {
|
||||
self.buffer.as_mut()[0] = self.buffer.as_ref()[0] & 0xBF
|
||||
};
|
||||
}
|
||||
pub fn set_version(&mut self, version: Version) {
|
||||
let v: u8 = version.into();
|
||||
pub fn set_default_version(&mut self) {
|
||||
let v: u8 = Version::V2.into();
|
||||
self.buffer.as_mut()[0] = (self.buffer.as_ref()[0] & 0xF0) | (0x0F & v);
|
||||
}
|
||||
pub fn set_protocol(&mut self, protocol: Protocol) {
|
||||
|
||||
Reference in New Issue
Block a user