added outer_ip probe
This commit is contained in:
parent
95a43c4651
commit
a680c1ece8
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1422,7 +1422,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sdlan-sn-rs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.asxalex.pw/sdlan-v2/sdlan-rs.git#f320526f2dc1f6c3154b9ade81c556af0d068378"
|
||||
source = "git+ssh://git@git.asxalex.pw/sdlan-v2/sdlan-rs.git#f320526f2dc1f6c3154b9ade81c556af0d068378"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"byteorder",
|
||||
|
||||
@ -13,8 +13,8 @@ once_cell = "1.19.0"
|
||||
prost = "0.12.6"
|
||||
prost-build = "0.12.6"
|
||||
rsa = "0.9.6"
|
||||
# sdlan-sn-rs = { git = "ssh://git@git.asxalex.pw/sdlan-v2/sdlan-rs.git" }
|
||||
sdlan-sn-rs = { git = "https://git.asxalex.pw/sdlan-v2/sdlan-rs.git" }
|
||||
sdlan-sn-rs = { git = "ssh://git@git.asxalex.pw/sdlan-v2/sdlan-rs.git" }
|
||||
# sdlan-sn-rs = { git = "https://git.asxalex.pw/sdlan-v2/sdlan-rs.git" }
|
||||
structopt = "0.3.26"
|
||||
tokio = { version = "1.38.0", futures = ["full"] }
|
||||
tokio-util = "0.7.11"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -14,8 +14,7 @@ use etherparse::IpHeaders;
|
||||
use sdlan_sn_rs::config::{AF_INET, SDLAN_DEFAULT_TTL};
|
||||
use sdlan_sn_rs::peer::SdlanSock;
|
||||
use sdlan_sn_rs::utils::{
|
||||
self, aes_encrypt, create_or_load_uuid, get_current_timestamp, ip_to_string,
|
||||
is_multi_broadcast, rsa_decrypt,
|
||||
self, aes_encrypt, create_or_load_uuid, get_current_timestamp, get_sdlan_sock_from_socketaddr, ip_to_string, is_multi_broadcast, rsa_decrypt
|
||||
};
|
||||
use sdlan_sn_rs::utils::{Result, SDLanError};
|
||||
use tokio::io::AsyncWriteExt;
|
||||
@ -188,6 +187,18 @@ pub async fn async_main(
|
||||
// let edge = get_edge();
|
||||
// let edge = get_edge();
|
||||
// let token = args.token.clone();
|
||||
if let Ok(ipaddr) = stream.local_addr() {
|
||||
match ipaddr.ip() {
|
||||
IpAddr::V4(v4) => {
|
||||
let ip = v4.into();
|
||||
println!("outer ip is {} => {}", v4, ip);
|
||||
edge.outer_ip_v4.store(ip, Ordering::Relaxed);
|
||||
}
|
||||
_other => {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
let register_super = SdlRegisterSuper {
|
||||
version: 1,
|
||||
installed_channel,
|
||||
|
||||
@ -120,6 +120,7 @@ pub struct Node {
|
||||
|
||||
// pub tcp_sock_v4: TCPSocket,
|
||||
pub udp_sock_v4: Socket,
|
||||
pub outer_ip_v4: AtomicU32,
|
||||
pub udp_sock_v6: RwLock<Arc<Option<Socket>>>,
|
||||
|
||||
pub multicast_sock: SdlanSock,
|
||||
@ -190,7 +191,9 @@ impl Node {
|
||||
|
||||
// tcp_sock_v4: tcpsock,
|
||||
udp_sock_v4: sock,
|
||||
outer_ip_v4: AtomicU32::new(0),
|
||||
udp_sock_v6: RwLock::new(Arc::new(None)),
|
||||
|
||||
multicast_sock: SdlanSock {
|
||||
family: AF_INET,
|
||||
port: config::MULTICAST_PORT,
|
||||
@ -309,6 +312,11 @@ impl Node {
|
||||
return NatType::Blocked;
|
||||
};
|
||||
|
||||
if reply1.ip == self.outer_ip_v4.load(Ordering::Relaxed) {
|
||||
*self.nat_type.lock().unwrap() = NatType::NoNat;
|
||||
return NatType::NoNat;
|
||||
}
|
||||
|
||||
if reply1.ip != reply2.ip || reply1.port != reply2.port {
|
||||
*self.nat_type.lock().unwrap() = NatType::Symmetric;
|
||||
return NatType::Symmetric;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user