changed the message's proto, added nat_type for send_register event
This commit is contained in:
parent
b51c78bdfb
commit
c098a3c421
@ -71,7 +71,8 @@ message SDLSendRegisterEvent {
|
|||||||
bytes dst_mac = 1;
|
bytes dst_mac = 1;
|
||||||
uint32 nat_ip = 2;
|
uint32 nat_ip = 2;
|
||||||
uint32 nat_port = 3;
|
uint32 nat_port = 3;
|
||||||
optional SDLV6Info v6_info = 4;
|
uint32 nat_type = 4;
|
||||||
|
optional SDLV6Info v6_info = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SDLNetworkShutdownEvent {
|
message SDLNetworkShutdownEvent {
|
||||||
|
|||||||
@ -595,6 +595,8 @@ pub struct EdgePeer {
|
|||||||
// pub mac: Mac,
|
// pub mac: Mac,
|
||||||
pub dev_addr: IpSubnet,
|
pub dev_addr: IpSubnet,
|
||||||
|
|
||||||
|
pub nat_type: RwLock<NatType>,
|
||||||
|
|
||||||
// 对端对外开放的ip和端口信息
|
// 对端对外开放的ip和端口信息
|
||||||
pub sock: RwLock<SdlanSock>,
|
pub sock: RwLock<SdlanSock>,
|
||||||
// peer's ipv6 info
|
// peer's ipv6 info
|
||||||
@ -644,6 +646,11 @@ impl EdgePeer {
|
|||||||
last_seen: AtomicU64::new(0),
|
last_seen: AtomicU64::new(0),
|
||||||
_last_valid_timestamp: AtomicU64::new(now),
|
_last_valid_timestamp: AtomicU64::new(now),
|
||||||
last_sent_query: AtomicU64::new(0),
|
last_sent_query: AtomicU64::new(0),
|
||||||
|
nat_type: RwLock::new(NatType::Invalid),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_nat_type(&self) -> NatType {
|
||||||
|
*self.nat_type.read().unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use std::{net::SocketAddr, sync::atomic::Ordering, time::Duration};
|
use std::{net::SocketAddr, sync::atomic::Ordering, time::Duration};
|
||||||
|
|
||||||
|
use crate::tcp::NatType;
|
||||||
use crate::{network::TunTapPacketHandler, utils::mac_to_string};
|
use crate::{network::TunTapPacketHandler, utils::mac_to_string};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -254,7 +255,11 @@ pub async fn handle_packet_peer_info(
|
|||||||
error!("failed to convert v4");
|
error!("failed to convert v4");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
let remote_nat = v4.nat_type;
|
let remote_nat_byte = v4.nat_type as u8;
|
||||||
|
let remote_nat = match NatType::try_from(remote_nat_byte) {
|
||||||
|
Ok(nat) => nat,
|
||||||
|
Err(_) => NatType::Invalid,
|
||||||
|
};
|
||||||
|
|
||||||
let mut v6: [u8; 16] = [0; 16];
|
let mut v6: [u8; 16] = [0; 16];
|
||||||
let mut v6_port = 0;
|
let mut v6_port = 0;
|
||||||
@ -277,6 +282,7 @@ pub async fn handle_packet_peer_info(
|
|||||||
v4: v4_u32,
|
v4: v4_u32,
|
||||||
v6: [0; 16],
|
v6: [0; 16],
|
||||||
};
|
};
|
||||||
|
*(edgeinfo.nat_type.write().unwrap()) = remote_nat;
|
||||||
*(edgeinfo.sock.write().unwrap()) = sock.deepcopy();
|
*(edgeinfo.sock.write().unwrap()) = sock.deepcopy();
|
||||||
info!(
|
info!(
|
||||||
"Rx PEERINFO for {}: is at {}",
|
"Rx PEERINFO for {}: is at {}",
|
||||||
@ -683,6 +689,8 @@ async fn send_register(eee: &'static Node, sock: &SdlanSock, mac: Mac, _v6_info:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let self_nat = eee.get_nat_type();
|
||||||
|
|
||||||
let register = SdlRegister {
|
let register = SdlRegister {
|
||||||
network_id: network_id,
|
network_id: network_id,
|
||||||
src_mac: Vec::from(eee.device_config.get_mac()),
|
src_mac: Vec::from(eee.device_config.get_mac()),
|
||||||
@ -707,6 +715,7 @@ async fn send_register(eee: &'static Node, sock: &SdlanSock, mac: Mac, _v6_info:
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
let mut target_sock_v4 = sock.deepcopy();
|
let mut target_sock_v4 = sock.deepcopy();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
for i in 1..=10 {
|
for i in 1..=10 {
|
||||||
@ -720,6 +729,7 @@ async fn send_register(eee: &'static Node, sock: &SdlanSock, mac: Mac, _v6_info:
|
|||||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
let key = eee.get_header_key();
|
let key = eee.get_header_key();
|
||||||
if key.len() > 0 {
|
if key.len() > 0 {
|
||||||
|
|||||||
@ -105,7 +105,9 @@ pub struct SdlSendRegisterEvent {
|
|||||||
pub nat_ip: u32,
|
pub nat_ip: u32,
|
||||||
#[prost(uint32, tag = "3")]
|
#[prost(uint32, tag = "3")]
|
||||||
pub nat_port: u32,
|
pub nat_port: u32,
|
||||||
#[prost(message, optional, tag = "4")]
|
#[prost(uint32, tag = "4")]
|
||||||
|
pub nat_type: u32,
|
||||||
|
#[prost(message, optional, tag = "5")]
|
||||||
pub v6_info: ::core::option::Option<Sdlv6Info>,
|
pub v6_info: ::core::option::Option<Sdlv6Info>,
|
||||||
}
|
}
|
||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
|
|||||||
@ -44,6 +44,7 @@ pub enum NatType {
|
|||||||
PortRestricted = 3,
|
PortRestricted = 3,
|
||||||
ConeRestricted = 4,
|
ConeRestricted = 4,
|
||||||
Symmetric = 5,
|
Symmetric = 5,
|
||||||
|
Invalid = 0xff,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, TryFromPrimitive)]
|
#[derive(Debug, Copy, Clone, TryFromPrimitive)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user