exp backoff and theads handling
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user