将ipv4转换成ipv6
This commit is contained in:
+23
-17
@@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::TcpStream;
|
use std::net::{SocketAddrV6, TcpStream};
|
||||||
use std::net::UdpSocket;
|
|
||||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
|
use std::net::UdpSocket;
|
||||||
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,
|
||||||
@@ -581,7 +581,7 @@ impl Config {
|
|||||||
token: String,
|
token: String,
|
||||||
device_id: String,
|
device_id: String,
|
||||||
name: String,
|
name: String,
|
||||||
server_address: SocketAddr,
|
mut server_address: SocketAddr,
|
||||||
server_address_str: String,
|
server_address_str: String,
|
||||||
mut stun_server: Vec<String>,
|
mut stun_server: Vec<String>,
|
||||||
in_ips: Vec<(u32, u32, Ipv4Addr)>,
|
in_ips: Vec<(u32, u32, Ipv4Addr)>,
|
||||||
@@ -606,6 +606,12 @@ impl Config {
|
|||||||
x.push_str(":3478");
|
x.push_str(":3478");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match server_address {
|
||||||
|
SocketAddr::V4(ipv4) => {
|
||||||
|
server_address = SocketAddr::V6(SocketAddrV6::new(ipv4.ip().to_ipv6_mapped(), ipv4.port(), 0, 0))
|
||||||
|
}
|
||||||
|
SocketAddr::V6(_) => {}
|
||||||
|
}
|
||||||
Self {
|
Self {
|
||||||
tap,
|
tap,
|
||||||
token,
|
token,
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::net::{Ipv4Addr, ToSocketAddrs};
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV6, ToSocketAddrs};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::channel::idle::Idle;
|
|
||||||
use crate::channel::sender::ChannelSender;
|
|
||||||
use crate::channel::Route;
|
|
||||||
use crate::cipher::Cipher;
|
|
||||||
use crate::core::status::VntWorker;
|
|
||||||
use crossbeam_utils::atomic::AtomicCell;
|
use crossbeam_utils::atomic::AtomicCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rand::prelude::SliceRandom;
|
use rand::prelude::SliceRandom;
|
||||||
|
|
||||||
|
use crate::channel::idle::Idle;
|
||||||
|
use crate::channel::Route;
|
||||||
|
use crate::channel::sender::ChannelSender;
|
||||||
|
use crate::cipher::Cipher;
|
||||||
|
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 {
|
||||||
@@ -64,6 +64,7 @@ pub fn start_heartbeat(
|
|||||||
worker.stop_all();
|
worker.stop_all();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_heartbeat_main(
|
pub fn start_heartbeat_main(
|
||||||
mut worker: VntWorker,
|
mut worker: VntWorker,
|
||||||
sender: ChannelSender,
|
sender: ChannelSender,
|
||||||
@@ -137,9 +138,12 @@ async fn start_heartbeat_main_(
|
|||||||
let src = current_dev.virtual_ip();
|
let src = current_dev.virtual_ip();
|
||||||
if count % 40 == 19 {
|
if count % 40 == 19 {
|
||||||
if let Ok(mut addr) = server_address_str.to_socket_addrs() {
|
if let Ok(mut addr) = server_address_str.to_socket_addrs() {
|
||||||
if let Some(addr) = addr.next() {
|
if let Some(mut addr) = addr.next() {
|
||||||
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 {
|
||||||
|
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!(
|
||||||
"服务端地址变化,旧地址:{},新地址:{}",
|
"服务端地址变化,旧地址:{},新地址:{}",
|
||||||
|
|||||||
Reference in New Issue
Block a user