exp backoff and theads handling

This commit is contained in:
TIBERGHIEN corentin
2026-01-20 01:10:09 +01:00
parent 08518892f2
commit dacedd1ceb
9 changed files with 469 additions and 331 deletions

View File

@@ -7,11 +7,11 @@ use std::{
ops::Add,
process::Command,
sync::{Arc, Mutex},
thread,
thread::{self, JoinHandle},
time::{self, Duration, SystemTime},
};
use crate::NetworkEvent;
use crate::{NetworkEvent, threads_handling::Worker};
use crate::{
P2PSharedData, construct_message, generate_id, messages_structure,
registration::perform_handshake,
@@ -65,21 +65,17 @@ impl HandshakeHistory {
self.ip_k_peerinfo_v.get(&ip).clone()
}
pub fn update_handshake(&self) {
// clone the map so we own it (cheap if PeerInfo is Clone)
pub fn update_handshake(&self) -> Worker {
let map_clone: Arc<HashMap<String, PeerInfo>> =
Arc::new(self.username_k_peerinfo_v.clone());
//let map_ip_clone: Arc<HashMap<String, PeerInfo>> = Arc::new(self.ip_k_peerinfo_v.clone());
let map_for_thread = Arc::clone(&map_clone);
thread::spawn(move || {
let handle = thread::spawn(move || {
loop {
// Arc<HashMap<..>> derefs to &HashMap so these reads work
for (peer, peerinfo) in map_for_thread.iter() {
// send ping to peerinfo
}
for (peer, peerinfo) in map_for_thread.iter() {}
thread::sleep(Duration::from_secs(10));
}
});
Worker::spawn(handle, crate::threads_handling::WorkerType::PING)
}
pub fn update_peer_info(&mut self, ip: String, username: String) {