fmt
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::{SocketAddrV6, TcpStream};
|
|
||||||
use std::net::UdpSocket as StdUdpSocket;
|
use std::net::UdpSocket as StdUdpSocket;
|
||||||
use std::net::{Ipv4Addr, Shutdown, SocketAddr};
|
use std::net::{Ipv4Addr, Shutdown, SocketAddr};
|
||||||
|
use std::net::{SocketAddrV6, TcpStream};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use std::{io, thread};
|
use std::{io, thread};
|
||||||
@@ -113,8 +113,13 @@ impl Context {
|
|||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn send_main_udp(&self, buf: &[u8], mut addr: SocketAddr) -> io::Result<usize> {
|
pub fn send_main_udp(&self, buf: &[u8], mut addr: SocketAddr) -> io::Result<usize> {
|
||||||
if let SocketAddr::V4(ipv4) = addr{
|
if let SocketAddr::V4(ipv4) = addr {
|
||||||
addr = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(),0,0));
|
addr = SocketAddr::V6(SocketAddrV6::new(
|
||||||
|
ipv4.ip().to_ipv6_mapped(),
|
||||||
|
ipv4.port(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
self.inner.main_channel.send_to(buf, addr)
|
self.inner.main_channel.send_to(buf, addr)
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-17
@@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::{SocketAddrV6, TcpStream};
|
|
||||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
|
use std::net::{SocketAddrV6, TcpStream};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -11,25 +11,25 @@ use parking_lot::{Mutex, RwLock};
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tokio::sync::mpsc::channel;
|
use tokio::sync::mpsc::channel;
|
||||||
|
|
||||||
use crate::channel::{Route, RouteKey};
|
|
||||||
use crate::channel::channel::{Channel, Context};
|
use crate::channel::channel::{Channel, Context};
|
||||||
use crate::channel::idle::Idle;
|
use crate::channel::idle::Idle;
|
||||||
use crate::channel::punch::{NatInfo, Punch, PunchModel};
|
use crate::channel::punch::{NatInfo, Punch, PunchModel};
|
||||||
use crate::channel::sender::ChannelSender;
|
use crate::channel::sender::ChannelSender;
|
||||||
|
use crate::channel::{Route, RouteKey};
|
||||||
use crate::cipher::{Cipher, CipherModel, RsaCipher};
|
use crate::cipher::{Cipher, CipherModel, RsaCipher};
|
||||||
use crate::core::status::VntStatusManger;
|
use crate::core::status::VntStatusManger;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::external_route::{AllowExternalRoute, ExternalRoute};
|
use crate::external_route::{AllowExternalRoute, ExternalRoute};
|
||||||
use crate::handle::{
|
|
||||||
ConnectStatus, CurrentDeviceInfo, handshake_handler, heartbeat_handler, PeerDeviceInfo,
|
|
||||||
punch_handler, registration_handler,
|
|
||||||
};
|
|
||||||
use crate::handle::handshake_handler::HandshakeEnum;
|
use crate::handle::handshake_handler::HandshakeEnum;
|
||||||
use crate::handle::recv_handler::ChannelDataHandler;
|
use crate::handle::recv_handler::ChannelDataHandler;
|
||||||
use crate::handle::registration_handler::{RegResponse, ReqEnum};
|
use crate::handle::registration_handler::{RegResponse, ReqEnum};
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
|
||||||
use crate::handle::tun_tap::tap_handler;
|
use crate::handle::tun_tap::tap_handler;
|
||||||
use crate::handle::tun_tap::tun_handler;
|
use crate::handle::tun_tap::tun_handler;
|
||||||
|
use crate::handle::{
|
||||||
|
handshake_handler, heartbeat_handler, punch_handler, registration_handler, ConnectStatus,
|
||||||
|
CurrentDeviceInfo, PeerDeviceInfo,
|
||||||
|
};
|
||||||
use crate::igmp_server::IgmpServer;
|
use crate::igmp_server::IgmpServer;
|
||||||
use crate::nat::NatTest;
|
use crate::nat::NatTest;
|
||||||
use crate::tun_tap_device;
|
use crate::tun_tap_device;
|
||||||
@@ -287,18 +287,18 @@ impl VntUtil {
|
|||||||
Some(ExternalRoute::new(config.in_ips))
|
Some(ExternalRoute::new(config.in_ips))
|
||||||
};
|
};
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
let (tcp_proxy, udp_proxy, ip_proxy_map) = if config.out_ips.is_empty() || config.no_proxy {
|
let (tcp_proxy, udp_proxy, ip_proxy_map) = if config.out_ips.is_empty() || config.no_proxy {
|
||||||
(None, None, None)
|
(None, None, None)
|
||||||
} else {
|
} else {
|
||||||
let (tcp_proxy, udp_proxy, ip_proxy_map) = crate::ip_proxy::init_proxy(
|
let (tcp_proxy, udp_proxy, ip_proxy_map) = crate::ip_proxy::init_proxy(
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
channel_sender.clone(),
|
channel_sender.clone(),
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
current_device.clone(),
|
current_device.clone(),
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
client_cipher.clone(),
|
client_cipher.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
(Some(tcp_proxy), Some(udp_proxy), Some(ip_proxy_map))
|
(Some(tcp_proxy), Some(udp_proxy), Some(ip_proxy_map))
|
||||||
};
|
};
|
||||||
let out_external_route = AllowExternalRoute::new(config.out_ips);
|
let out_external_route = AllowExternalRoute::new(config.out_ips);
|
||||||
@@ -319,7 +319,7 @@ impl VntUtil {
|
|||||||
current_device.clone(),
|
current_device.clone(),
|
||||||
in_external_route,
|
in_external_route,
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
ip_proxy_map.clone(),
|
ip_proxy_map.clone(),
|
||||||
client_cipher.clone(),
|
client_cipher.clone(),
|
||||||
self.server_cipher.clone(),
|
self.server_cipher.clone(),
|
||||||
config.parallel,
|
config.parallel,
|
||||||
@@ -334,7 +334,7 @@ impl VntUtil {
|
|||||||
current_device.clone(),
|
current_device.clone(),
|
||||||
in_external_route,
|
in_external_route,
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
ip_proxy_map.clone(),
|
ip_proxy_map.clone(),
|
||||||
client_cipher.clone(),
|
client_cipher.clone(),
|
||||||
self.server_cipher.clone(),
|
self.server_cipher.clone(),
|
||||||
config.parallel,
|
config.parallel,
|
||||||
@@ -350,7 +350,7 @@ impl VntUtil {
|
|||||||
current_device.clone(),
|
current_device.clone(),
|
||||||
in_external_route,
|
in_external_route,
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
ip_proxy_map.clone(),
|
ip_proxy_map.clone(),
|
||||||
client_cipher.clone(),
|
client_cipher.clone(),
|
||||||
self.server_cipher.clone(),
|
self.server_cipher.clone(),
|
||||||
config.parallel,
|
config.parallel,
|
||||||
@@ -367,7 +367,7 @@ impl VntUtil {
|
|||||||
connect_status.clone(),
|
connect_status.clone(),
|
||||||
peer_nat_info_map.clone(),
|
peer_nat_info_map.clone(),
|
||||||
#[cfg(feature = "ip_proxy")]
|
#[cfg(feature = "ip_proxy")]
|
||||||
ip_proxy_map,
|
ip_proxy_map,
|
||||||
out_external_route,
|
out_external_route,
|
||||||
cone_sender,
|
cone_sender,
|
||||||
symmetric_sender,
|
symmetric_sender,
|
||||||
@@ -608,7 +608,12 @@ impl Config {
|
|||||||
}
|
}
|
||||||
match server_address {
|
match server_address {
|
||||||
SocketAddr::V4(ipv4) => {
|
SocketAddr::V4(ipv4) => {
|
||||||
server_address = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(), 0, 0))
|
server_address = SocketAddr::V6(SocketAddrV6::new(
|
||||||
|
ipv4.ip().to_ipv6_mapped(),
|
||||||
|
ipv4.port(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
SocketAddr::V6(_) => {}
|
SocketAddr::V6(_) => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ fn send_recv(
|
|||||||
match main_channel.recv_from(recv_buf) {
|
match main_channel.recv_from(recv_buf) {
|
||||||
Ok((len, addr)) => {
|
Ok((len, addr)) => {
|
||||||
if server_address != addr {
|
if server_address != addr {
|
||||||
log::warn!("请求{:?}和响应{:?}地址不一致",server_address,addr);
|
log::warn!("请求{:?}和响应{:?}地址不一致", server_address, addr);
|
||||||
}
|
}
|
||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ pub fn secret_handshake(
|
|||||||
if net_packet.is_gateway()
|
if net_packet.is_gateway()
|
||||||
&& net_packet.protocol() == Protocol::Service
|
&& net_packet.protocol() == Protocol::Service
|
||||||
&& service_packet::Protocol::from(net_packet.transport_protocol())
|
&& service_packet::Protocol::from(net_packet.transport_protocol())
|
||||||
== service_packet::Protocol::SecretHandshakeResponse
|
== service_packet::Protocol::SecretHandshakeResponse
|
||||||
{
|
{
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ use parking_lot::Mutex;
|
|||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
use crate::channel::idle::Idle;
|
use crate::channel::idle::Idle;
|
||||||
use crate::channel::Route;
|
|
||||||
use crate::channel::sender::ChannelSender;
|
use crate::channel::sender::ChannelSender;
|
||||||
|
use crate::channel::Route;
|
||||||
use crate::cipher::Cipher;
|
use crate::cipher::Cipher;
|
||||||
use crate::core::status::VntWorker;
|
use crate::core::status::VntWorker;
|
||||||
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
use crate::handle::{CurrentDeviceInfo, PeerDeviceInfo};
|
||||||
use crate::protocol::{control_packet, MAX_TTL, NetPacket, Protocol, Version};
|
|
||||||
use crate::protocol::body::ENCRYPTION_RESERVED;
|
use crate::protocol::body::ENCRYPTION_RESERVED;
|
||||||
use crate::protocol::control_packet::PingPacket;
|
use crate::protocol::control_packet::PingPacket;
|
||||||
|
use crate::protocol::{control_packet, NetPacket, Protocol, Version, MAX_TTL};
|
||||||
|
|
||||||
pub fn start_idle(mut worker: VntWorker, idle: Idle, sender: ChannelSender) {
|
pub fn start_idle(mut worker: VntWorker, idle: Idle, sender: ChannelSender) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
@@ -142,7 +142,12 @@ async fn start_heartbeat_main_(
|
|||||||
if addr != current_dev.connect_server {
|
if addr != current_dev.connect_server {
|
||||||
let mut tmp = current_dev.clone();
|
let mut tmp = current_dev.clone();
|
||||||
if let SocketAddr::V4(ipv4) = addr {
|
if let SocketAddr::V4(ipv4) = addr {
|
||||||
addr = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(), 0, 0))
|
addr = SocketAddr::V6(SocketAddrV6::new(
|
||||||
|
ipv4.ip().to_ipv6_mapped(),
|
||||||
|
ipv4.port(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
tmp.connect_server = addr;
|
tmp.connect_server = addr;
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub fn registration(
|
|||||||
match main_channel.recv_from(&mut recv_buf) {
|
match main_channel.recv_from(&mut recv_buf) {
|
||||||
Ok((len, addr)) => {
|
Ok((len, addr)) => {
|
||||||
if server_address != addr {
|
if server_address != addr {
|
||||||
log::warn!("请求{:?}和响应{:?}地址不一致",server_address,addr);
|
log::warn!("请求{:?}和响应{:?}地址不一致", server_address, addr);
|
||||||
}
|
}
|
||||||
&mut recv_buf[..len]
|
&mut recv_buf[..len]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user