guess port at -10 to 10
This commit is contained in:
parent
966f054a63
commit
b51c78bdfb
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[target.x86_64-unknown-linux-musl]
|
||||
linker = "x86_64-linux-musl-gcc"
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,4 +4,7 @@
|
||||
.client
|
||||
.output
|
||||
sdlan
|
||||
sdlan.exe
|
||||
sdlan.exe
|
||||
*.bak
|
||||
*.a
|
||||
*.o
|
||||
|
||||
10
Makefile
10
Makefile
@ -1,6 +1,9 @@
|
||||
linux:
|
||||
self:
|
||||
RUSTFLAGS="-L ." cargo build --features "tap" --release
|
||||
|
||||
linux:
|
||||
RUSTFLAGS="-L ." cargo build --features "tap" --release --target x86_64-unknown-linux-musl
|
||||
|
||||
linux-tun:
|
||||
RUSTFLAGS="-L ." cargo build --release
|
||||
|
||||
@ -12,4 +15,7 @@ pb:
|
||||
mv src/pb/_.rs src/pb/message.rs
|
||||
|
||||
libtun-so:
|
||||
cd src/network && gcc -fPIC -shared -o libtuntap.so tuntap.c && cd -
|
||||
cd src/network && gcc -fPIC -shared -o libtuntap.so tuntap.c && cd -
|
||||
|
||||
libtun-a:
|
||||
cd src/network && gcc -c tuntap.c && ar rcs libtuntap.a tuntap.o && cd -
|
||||
@ -189,7 +189,7 @@ async fn handle_tcp_message(msg: SdlanTcp) {
|
||||
|
||||
async fn handle_tcp_command(_edge: &Node, _cmdtype: u8, _cmdprotobuf: &[u8]) {}
|
||||
|
||||
async fn handle_tcp_event(edge: &Node, eventtype: EventType, eventprotobuf: &[u8]) {
|
||||
async fn handle_tcp_event(edge: &'static Node, eventtype: EventType, eventprotobuf: &[u8]) {
|
||||
match eventtype {
|
||||
EventType::SendRegister => {
|
||||
let Ok(reg) = SdlSendRegisterEvent::decode(eventprotobuf) else {
|
||||
@ -459,7 +459,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: &'static Node, socket: Arc<Socket>, cancel: CancellationToken) {
|
||||
debug!("loop sock v6");
|
||||
loop {
|
||||
tokio::select! {
|
||||
@ -487,7 +487,7 @@ pub async fn loop_socket_v6(eee: &Node, socket: Arc<Socket>, cancel: Cancellatio
|
||||
}
|
||||
|
||||
pub async fn loop_socket_v4(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
socket: &Socket,
|
||||
cancel: CancellationToken,
|
||||
is_multicast_sock: bool,
|
||||
@ -603,7 +603,7 @@ async fn edge_send_packet_to_net(eee: &Node, data: Vec<u8>) {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send_packet_to_net(eee: &Node, dst_mac: Mac, pkt: &[u8], size: u64) {
|
||||
pub async fn send_packet_to_net(eee: &'static Node, dst_mac: Mac, pkt: &[u8], size: u64) {
|
||||
let (dest_sock, is_p2p) = find_peer_destination(eee, dst_mac).await;
|
||||
if is_p2p {
|
||||
eee.stats.tx_p2p.fetch_add(size, Ordering::Relaxed);
|
||||
@ -619,7 +619,7 @@ pub async fn send_packet_to_net(eee: &Node, dst_mac: Mac, pkt: &[u8], size: u64)
|
||||
}
|
||||
}
|
||||
|
||||
async fn find_peer_destination(eee: &Node, dst_mac: Mac) -> (SdlanSock, bool) {
|
||||
async fn find_peer_destination(eee: &'static Node, dst_mac: Mac) -> (SdlanSock, bool) {
|
||||
if is_multi_broadcast(&dst_mac) {
|
||||
return (
|
||||
eee.config.super_nodes[eee.config.super_node_index.load(Ordering::Relaxed) as usize]
|
||||
|
||||
@ -29,7 +29,7 @@ use tracing::{debug, error, info};
|
||||
use super::{EdgePeer, Node};
|
||||
|
||||
pub async fn read_and_parse_packet(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
sock: &Socket,
|
||||
timeout: Option<Duration>,
|
||||
_is_multicast_sock: bool,
|
||||
@ -86,7 +86,7 @@ pub async fn read_and_parse_packet(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn handle_packet(eee: &Node, addr: SocketAddr, buf: &[u8]) -> Result<()> {
|
||||
pub async fn handle_packet(eee: &'static Node, addr: SocketAddr, buf: &[u8]) -> Result<()> {
|
||||
if buf.len() < 1 {
|
||||
return Err(SDLanError::NormalError("buf length error"));
|
||||
}
|
||||
@ -228,7 +228,7 @@ pub async fn handle_packet(eee: &Node, addr: SocketAddr, buf: &[u8]) -> Result<(
|
||||
}
|
||||
|
||||
pub async fn handle_packet_peer_info(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
// cmn: Common<'_>,
|
||||
body: &[u8],
|
||||
//sender_sock: &SdlanSock,
|
||||
@ -254,6 +254,7 @@ pub async fn handle_packet_peer_info(
|
||||
error!("failed to convert v4");
|
||||
return Ok(());
|
||||
};
|
||||
let remote_nat = v4.nat_type;
|
||||
|
||||
let mut v6: [u8; 16] = [0; 16];
|
||||
let mut v6_port = 0;
|
||||
@ -411,7 +412,7 @@ async fn handle_packet_register_ack(
|
||||
}
|
||||
|
||||
async fn handle_packet_register(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
// cmn: Common<'_>,
|
||||
body: &[u8],
|
||||
from_sn: bool,
|
||||
@ -513,7 +514,7 @@ async fn handle_packet_packet(
|
||||
*/
|
||||
|
||||
pub async fn check_peer_registration_needed(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
from_sn: bool,
|
||||
src_mac: Mac,
|
||||
_v6_info: &Option<V6Info>,
|
||||
@ -555,7 +556,7 @@ pub async fn check_peer_registration_needed(
|
||||
}
|
||||
|
||||
async fn check_known_peer_sock_change(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
from_sn: bool,
|
||||
mac: Mac,
|
||||
// v6_info: &Option<V6Info>,
|
||||
@ -592,7 +593,7 @@ async fn check_known_peer_sock_change(
|
||||
}
|
||||
|
||||
async fn register_with_new_peer(
|
||||
eee: &Node,
|
||||
eee: &'static Node,
|
||||
from_sn: bool,
|
||||
mac: Mac,
|
||||
v6_info: &Option<V6Info>,
|
||||
@ -667,11 +668,11 @@ async fn register_with_new_peer(
|
||||
}
|
||||
}
|
||||
|
||||
async fn register_with_local_peers(eee: &Node) {
|
||||
async fn register_with_local_peers(eee: &'static Node) {
|
||||
send_register(eee, &eee.multicast_sock, BROADCAST_MAC, &None).await;
|
||||
}
|
||||
|
||||
async fn send_register(eee: &Node, sock: &SdlanSock, mac: Mac, _v6_info: &Option<V6Info>) {
|
||||
async fn send_register(eee: &'static Node, sock: &SdlanSock, mac: Mac, _v6_info: &Option<V6Info>) {
|
||||
if !eee.config.allow_p2p {
|
||||
debug!("skipping register as p2p is disabled");
|
||||
return;
|
||||
@ -706,6 +707,19 @@ async fn send_register(eee: &Node, sock: &SdlanSock, mac: Mac, _v6_info: &Option
|
||||
)
|
||||
.await;
|
||||
}
|
||||
let mut target_sock_v4 = sock.deepcopy();
|
||||
tokio::spawn(async move {
|
||||
for i in 1..=10 {
|
||||
target_sock_v4.port += i;
|
||||
let _ = send_to_sock(eee, &msg, &target_sock_v4).await;
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
for i in 1..=10 {
|
||||
target_sock_v4.port -= i;
|
||||
let _ = send_to_sock(eee, &msg, &target_sock_v4).await;
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
});
|
||||
/*
|
||||
let key = eee.get_header_key();
|
||||
if key.len() > 0 {
|
||||
@ -985,7 +999,7 @@ fn peer_set_p2p_confirmed(eee: &Node, src_mac: Mac, sender_sock: &SdlanSock) {
|
||||
eee.known_peers.insert_peer(src_mac, scan);
|
||||
}
|
||||
|
||||
pub async fn check_query_peer_info(eee: &Node, mac: Mac) {
|
||||
pub async fn check_query_peer_info(eee: &'static Node, mac: Mac) {
|
||||
let scan: Arc<EdgePeer>;
|
||||
let now = get_current_timestamp();
|
||||
match eee.pending_peers.get_peer(&mac) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user