tun
This commit is contained in:
parent
5fa882ec16
commit
375a0671f8
@ -1,7 +1,7 @@
|
||||
use std::net::IpAddr;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::config::TCP_PING_TIME;
|
||||
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) {
|
||||
let sdl_v6_info = match *eee.ipv6.read().unwrap() {
|
||||
Some(ref l) => {
|
||||
Some(Sdlv6Info {
|
||||
Some(ref l) => Some(Sdlv6Info {
|
||||
port: l.port as u32,
|
||||
v6: Vec::from(l.v6),
|
||||
})
|
||||
}
|
||||
None => {
|
||||
None
|
||||
}
|
||||
}),
|
||||
None => None,
|
||||
};
|
||||
let req = SdlStunRequest {
|
||||
cookie: 0,
|
||||
@ -449,11 +445,7 @@ async fn send_stun_request(eee: &Node) {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn loop_socket_v6(
|
||||
eee: &Node,
|
||||
socket: Arc<Socket>,
|
||||
cancel: CancellationToken,
|
||||
) {
|
||||
pub async fn loop_socket_v6(eee: &Node, socket: Arc<Socket>, cancel: CancellationToken) {
|
||||
debug!("loop sock v6");
|
||||
loop {
|
||||
tokio::select! {
|
||||
@ -478,7 +470,6 @@ pub async fn loop_socket_v6(
|
||||
}
|
||||
}
|
||||
debug!("loop_socket_v4 exited");
|
||||
|
||||
}
|
||||
|
||||
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>) {
|
||||
/*
|
||||
if !eee.is_authorized() {
|
||||
debug!("drop packet before authorized");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if eee.stats.last_sup.load(Ordering::Relaxed) == 0 {
|
||||
debug!("drop packet before first registration");
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use dashmap::DashMap;
|
||||
use rsa::RsaPrivateKey;
|
||||
use sdlan_sn_rs::config::{AF_INET, AF_INET6};
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
@ -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::{
|
||||
config::REGISTER_INTERVAL,
|
||||
@ -269,10 +273,7 @@ pub async fn handle_packet_peer_info(
|
||||
);
|
||||
let mut v6_info = None;
|
||||
if v6_port != 0 {
|
||||
v6_info = Some(V6Info {
|
||||
port: v6_port,
|
||||
v6,
|
||||
})
|
||||
v6_info = Some(V6Info { port: v6_port, v6 })
|
||||
}
|
||||
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);
|
||||
// more than 3 seconds
|
||||
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(
|
||||
eee: &Node,
|
||||
sock: &SdlanSock,
|
||||
_v6_info: &Option<V6Info>
|
||||
) {
|
||||
async fn send_register(eee: &Node, sock: &SdlanSock, _v6_info: &Option<V6Info>) {
|
||||
if !eee.config.allow_p2p {
|
||||
debug!("skipping register as p2p is disabled");
|
||||
return;
|
||||
@ -661,12 +659,17 @@ async fn send_register(
|
||||
|
||||
let _ = send_to_sock(eee, &msg, sock).await;
|
||||
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,
|
||||
port: v6_info.port,
|
||||
v4: [0; 4],
|
||||
v6: v6_info.v6,
|
||||
}).await;
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
/*
|
||||
let key = eee.get_header_key();
|
||||
@ -727,7 +730,7 @@ async fn handle_tun_packet(
|
||||
return;
|
||||
}
|
||||
// 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) {
|
||||
error!("failed to write to tun: {}", e.to_string());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user