完善日志输出等
This commit is contained in:
@@ -81,7 +81,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
|
||||
for peer in device_list {
|
||||
let name = peer.name;
|
||||
let virtual_ip = peer.virtual_ip.to_string();
|
||||
let (nat_type, public_ips, local_ip,ipv6) =
|
||||
let (nat_type, public_ips, local_ip, ipv6) =
|
||||
if let Some(nat_info) = vnt.peer_nat_info(&peer.virtual_ip) {
|
||||
let nat_type = format!("{:?}", nat_info.nat_type);
|
||||
let public_ips: Vec<String> =
|
||||
@@ -89,9 +89,14 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
|
||||
let public_ips = public_ips.join(",");
|
||||
let local_ip = nat_info.local_ipv4_addr.ip().to_string();
|
||||
let ipv6 = nat_info.ipv6_addr.ip().to_string();
|
||||
(nat_type, public_ips, local_ip,ipv6)
|
||||
(nat_type, public_ips, local_ip, ipv6)
|
||||
} else {
|
||||
("".to_string(), "".to_string(), "".to_string(), "".to_string())
|
||||
(
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
"".to_string(),
|
||||
)
|
||||
};
|
||||
let (nat_traversal_type, rt) = if let Some(route) = vnt.route(&peer.virtual_ip) {
|
||||
let nat_traversal_type = if route.metric == 1 {
|
||||
|
||||
@@ -21,7 +21,7 @@ impl FromStr for CipherModel {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
match s.to_lowercase().trim() {
|
||||
"aes_gcm" => Ok(CipherModel::AesGcm),
|
||||
"aes_cbc" => Ok(CipherModel::AesCbc),
|
||||
"aes_ecb" => Ok(CipherModel::AesEcb),
|
||||
|
||||
@@ -37,7 +37,7 @@ async fn start_idle_(idle: Idle, sender: ChannelSender) -> io::Result<()> {
|
||||
log::info!("启动空闲检查任务");
|
||||
loop {
|
||||
let (peer_ip, route) = idle.next_idle().await?;
|
||||
log::info!("peer_ip:{:?},route:{:?}", peer_ip, route);
|
||||
log::info!("路由空闲 peer_ip:{:?},route:{:?}", peer_ip, route);
|
||||
sender.remove_route(&peer_ip, route);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,20 +668,26 @@ impl ChannelDataHandler {
|
||||
service_packet::Protocol::RegistrationRequest => {}
|
||||
service_packet::Protocol::RegistrationResponse => {
|
||||
let response = RegistrationResponse::parse_from_bytes(net_packet.payload())?;
|
||||
let local_port = context.main_local_ipv4_port().unwrap_or(0);
|
||||
let local_ipv4_addr = nat::local_ipv4_addr(local_port);
|
||||
let local_port = context.main_local_ipv6_port().unwrap_or(0);
|
||||
let ipv6_addr = nat::local_ipv6_addr(local_port);
|
||||
let nat_info = self
|
||||
.nat_test
|
||||
.re_test(
|
||||
Ipv4Addr::from(response.public_ip),
|
||||
response.public_port as u16,
|
||||
local_ipv4_addr,
|
||||
ipv6_addr,
|
||||
)
|
||||
.await;
|
||||
context.switch(nat_info.nat_type);
|
||||
|
||||
{
|
||||
let context = context.clone();
|
||||
let nat_test = self.nat_test.clone();
|
||||
tokio::spawn(async move {
|
||||
let local_port = context.main_local_ipv4_port().unwrap_or(0);
|
||||
let local_ipv4_addr = nat::local_ipv4_addr(local_port);
|
||||
let local_port = context.main_local_ipv6_port().unwrap_or(0);
|
||||
let ipv6_addr = nat::local_ipv6_addr(local_port);
|
||||
let nat_info = nat_test
|
||||
.re_test(
|
||||
Ipv4Addr::from(response.public_ip),
|
||||
response.public_port as u16,
|
||||
local_ipv4_addr,
|
||||
ipv6_addr,
|
||||
)
|
||||
.await;
|
||||
context.switch(nat_info.nat_type);
|
||||
});
|
||||
}
|
||||
let new_ip = Ipv4Addr::from(response.virtual_ip);
|
||||
let current_ip = current_device.virtual_ip();
|
||||
if current_ip != new_ip {
|
||||
@@ -732,7 +738,7 @@ impl ChannelDataHandler {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let route = Route::from(*route_key, 2, 99);
|
||||
let route = Route::from(*route_key, 2, 199);
|
||||
for x in &ip_list {
|
||||
if x.status == PeerDeviceStatus::Online {
|
||||
context.add_route_if_absent(x.virtual_ip, route);
|
||||
|
||||
+6
-15
@@ -84,25 +84,16 @@ impl NatTest {
|
||||
) -> NatTest {
|
||||
let server = stun_server[0].clone();
|
||||
stun_server.resize(3, server);
|
||||
let nat_info = NatInfo::new(
|
||||
vec![public_ip],
|
||||
let nat_info = Self::re_test_(
|
||||
&stun_server,
|
||||
public_ip,
|
||||
public_port,
|
||||
0,
|
||||
local_ipv4_addr,
|
||||
ipv6_addr,
|
||||
NatType::Cone,
|
||||
);
|
||||
)
|
||||
.await;
|
||||
let info = Arc::new(Mutex::new(nat_info));
|
||||
let nat_test = NatTest { stun_server, info };
|
||||
{
|
||||
let nat_test = nat_test.clone();
|
||||
tokio::spawn(async move {
|
||||
let _ = nat_test
|
||||
.re_test(public_ip, public_port, local_ipv4_addr, ipv6_addr)
|
||||
.await;
|
||||
});
|
||||
}
|
||||
nat_test
|
||||
NatTest { stun_server, info }
|
||||
}
|
||||
pub fn nat_info(&self) -> NatInfo {
|
||||
self.info.lock().clone()
|
||||
|
||||
Reference in New Issue
Block a user