This commit is contained in:
asxalex 2024-08-30 16:07:06 +08:00
parent 5fa882ec16
commit 375a0671f8
3 changed files with 33 additions and 36 deletions

View File

@ -1,7 +1,7 @@
use std::net::IpAddr; use std::net::IpAddr;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::time::Duration;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration;
use crate::config::TCP_PING_TIME; use crate::config::TCP_PING_TIME;
use crate::network::ipv6::run_ipv6; use crate::network::ipv6::run_ipv6;
@ -418,15 +418,11 @@ async fn run_edge_loop(eee: &'static Node, cancel: CancellationToken) {
async fn send_stun_request(eee: &Node) { async fn send_stun_request(eee: &Node) {
let sdl_v6_info = match *eee.ipv6.read().unwrap() { let sdl_v6_info = match *eee.ipv6.read().unwrap() {
Some(ref l) => { Some(ref l) => Some(Sdlv6Info {
Some(Sdlv6Info {
port: l.port as u32, port: l.port as u32,
v6: Vec::from(l.v6), v6: Vec::from(l.v6),
}) }),
} None => None,
None => {
None
}
}; };
let req = SdlStunRequest { let req = SdlStunRequest {
cookie: 0, cookie: 0,
@ -449,11 +445,7 @@ async fn send_stun_request(eee: &Node) {
} }
} }
pub async fn loop_socket_v6( pub async fn loop_socket_v6(eee: &Node, socket: Arc<Socket>, cancel: CancellationToken) {
eee: &Node,
socket: Arc<Socket>,
cancel: CancellationToken,
) {
debug!("loop sock v6"); debug!("loop sock v6");
loop { loop {
tokio::select! { tokio::select! {
@ -478,7 +470,6 @@ pub async fn loop_socket_v6(
} }
} }
debug!("loop_socket_v4 exited"); debug!("loop_socket_v4 exited");
} }
pub async fn loop_socket_v4( pub async fn loop_socket_v4(
@ -564,10 +555,12 @@ async fn get_tun_flow(eee: &'static Node, tx: Sender<Vec<u8>>) {
} }
async fn read_and_parse_tun_packet(eee: &'static Node, buf: Vec<u8>) { async fn read_and_parse_tun_packet(eee: &'static Node, buf: Vec<u8>) {
/*
if !eee.is_authorized() { if !eee.is_authorized() {
debug!("drop packet before authorized"); debug!("drop packet before authorized");
return; return;
} }
*/
/* /*
if eee.stats.last_sup.load(Ordering::Relaxed) == 0 { if eee.stats.last_sup.load(Ordering::Relaxed) == 0 {
debug!("drop packet before first registration"); debug!("drop packet before first registration");

View File

@ -1,6 +1,7 @@
use dashmap::DashMap; use dashmap::DashMap;
use rsa::RsaPrivateKey; use rsa::RsaPrivateKey;
use sdlan_sn_rs::config::{AF_INET, AF_INET6}; use sdlan_sn_rs::config::{AF_INET, AF_INET6};
use std::collections::HashMap;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering}; use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering};
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};

View File

@ -1,4 +1,8 @@
use std::{net::SocketAddr, sync::{atomic::Ordering, RwLock}, time::Duration}; use std::{
net::SocketAddr,
sync::{atomic::Ordering, RwLock},
time::Duration,
};
use crate::{ use crate::{
config::REGISTER_INTERVAL, config::REGISTER_INTERVAL,
@ -269,10 +273,7 @@ pub async fn handle_packet_peer_info(
); );
let mut v6_info = None; let mut v6_info = None;
if v6_port != 0 { if v6_port != 0 {
v6_info = Some(V6Info { v6_info = Some(V6Info { port: v6_port, v6 })
port: v6_port,
v6,
})
} }
send_register(eee, &sock, &v6_info).await; send_register(eee, &sock, &v6_info).await;
@ -512,7 +513,8 @@ pub async fn check_peer_registration_needed(
let last_seen = k.last_seen.load(Ordering::Relaxed); let last_seen = k.last_seen.load(Ordering::Relaxed);
// more than 3 seconds // more than 3 seconds
if now - last_seen > 1 { if now - last_seen > 1 {
check_known_peer_sock_change(eee, from_sn, src_ip, peer_sock, now, ipv4_to_ipv6).await; check_known_peer_sock_change(eee, from_sn, src_ip, peer_sock, now, ipv4_to_ipv6)
.await;
} }
} }
} }
@ -636,11 +638,7 @@ async fn register_with_local_peers(eee: &Node) {
} }
} }
async fn send_register( async fn send_register(eee: &Node, sock: &SdlanSock, _v6_info: &Option<V6Info>) {
eee: &Node,
sock: &SdlanSock,
_v6_info: &Option<V6Info>
) {
if !eee.config.allow_p2p { if !eee.config.allow_p2p {
debug!("skipping register as p2p is disabled"); debug!("skipping register as p2p is disabled");
return; return;
@ -661,12 +659,17 @@ async fn send_register(
let _ = send_to_sock(eee, &msg, sock).await; let _ = send_to_sock(eee, &msg, sock).await;
if let Some(ref v6_info) = _v6_info { if let Some(ref v6_info) = _v6_info {
let _ = send_to_sock(eee, &msg, &SdlanSock { let _ = send_to_sock(
eee,
&msg,
&SdlanSock {
family: AF_INET6, family: AF_INET6,
port: v6_info.port, port: v6_info.port,
v4: [0; 4], v4: [0; 4],
v6: v6_info.v6, v6: v6_info.v6,
}).await; },
)
.await;
} }
/* /*
let key = eee.get_header_key(); let key = eee.get_header_key();
@ -727,7 +730,7 @@ async fn handle_tun_packet(
return; return;
} }
// packet should be sent to dev // packet should be sent to dev
debug!("writing {} bytes to tun", data.len()); debug!("writing {} bytes to tun: {:?}", data.len(), data);
if let Err(e) = eee.device.send(&data) { if let Err(e) = eee.device.send(&data) {
error!("failed to write to tun: {}", e.to_string()); error!("failed to write to tun: {}", e.to_string());
} }