changed p2p registration

This commit is contained in:
asxalex 2024-07-16 22:31:34 +08:00
parent 8f365e32db
commit 23a12e66f6
3 changed files with 10 additions and 8 deletions

View File

@ -522,19 +522,17 @@ async fn send_packet_to_net(eee: &Node, dst_ip: u32, pkt: &[u8], size: u64) {
async fn find_peer_destination(eee: &Node, dst_ip: u32) -> (SdlanSock, bool) {
if is_multi_broadcast(dst_ip) {
println!("find peer destination: is multi_broadcast");
return (
eee.config.super_nodes[eee.config.super_node_index.load(Ordering::Relaxed) as usize]
.deepcopy(),
false,
);
}
println!("find peer destination 1");
let mut is_p2p = false;
let result: SdlanSock;
if let Some(dst) = eee.known_peers.get_peer(&dst_ip) {
let now = get_current_timestamp();
if now - dst.last_seen.load(Ordering::Relaxed) >= ((dst.timeout / 2) as u64) {
if now - dst.last_p2p.load(Ordering::Relaxed) >= ((dst.timeout / 2) as u64) {
// too much time elapsed since we saw the peer, need to register again
eee.known_peers.delete_peer_with_ip(&dst_ip);
result = eee.config.super_nodes

View File

@ -528,6 +528,9 @@ pub struct EdgePeer {
// 最近一次合法时间
pub _last_valid_timestamp: AtomicU64,
// 当时间超过重新注册的时间之后,
// pub has_sent_last_p2p: AtomicBool,
// 最近一次发送query
pub last_sent_query: AtomicU64,
}

View File

@ -466,7 +466,6 @@ pub async fn check_peer_registration_needed(
peer_sock: &SdlanSock,
) {
let mut p = eee.known_peers.get_peer(&src_ip);
println!("check peer registration needed");
if let None = p {
p = eee.known_peers.get_peer_by_sock(peer_sock);
if let Some(ref k) = p {
@ -475,20 +474,18 @@ pub async fn check_peer_registration_needed(
}
match p {
None => {
println!("need register_with_new_peer");
let _ = register_with_new_peer(eee, from_sn, src_ip, v6_info, peer_sock).await;
// unimplemented!();
}
Some(k) => {
println!("peer is known");
let now = get_current_timestamp();
if !from_sn {
k.last_p2p.store(now, Ordering::Relaxed);
}
let last_seen = k.last_seen.load(Ordering::Relaxed);
// more than 3 seconds
if now - last_seen > 3 {
check_known_peer_sock_change(eee, from_sn, src_ip, v6_info, peer_sock).await;
if now - last_seen > 1 {
check_known_peer_sock_change(eee, from_sn, src_ip, v6_info, peer_sock, now).await;
}
}
}
@ -501,6 +498,7 @@ async fn check_known_peer_sock_change(
v6_info: &Option<V6Info>,
// dev_addr: &IpSubnet,
peersock: &SdlanSock,
when: u64,
) {
if is_multi_broadcast(ip) {
return;
@ -517,8 +515,11 @@ async fn check_known_peer_sock_change(
);
eee.known_peers.delete_peer_with_ip(&ip);
register_with_new_peer(eee, from_sn, ip, v6_info, peersock).await;
} else {
// from sn, sn could see a different sock with us, just ignore it
}
} else {
p.last_seen.store(when, Ordering::Relaxed);
// from sn, sn could see a different sock with us, just ignore it
}
}