wip messages creation & handling

This commit is contained in:
TIBERGHIEN corentin
2026-01-09 20:09:39 +01:00
parent 9fc33804d0
commit 489669b93d
7 changed files with 114 additions and 77 deletions

View File

@@ -3,9 +3,12 @@
use std::{
collections::{HashMap, VecDeque},
net::SocketAddr,
net::{AddrParseError, SocketAddr},
ops::Add,
process::Command,
sync::{Arc, Mutex},
thread,
time::{self, SystemTime},
time::{self, Duration, SystemTime},
};
pub struct PeerInfo {
@@ -14,24 +17,36 @@ pub struct PeerInfo {
}
pub struct HandshakeHistory {
time_k_hash_v: HashMap<u64, u64>,
hash_k_peerinfo_v: HashMap<u64, PeerInfo>,
times_to_check: VecDeque<u64>,
time_k_ip_v: HashMap<u64, u64>,
ip_k_peerinfo_v: HashMap<u64, PeerInfo>,
}
impl HandshakeHistory {
pub fn new() -> HandshakeHistory {
HandshakeHistory {
time_k_hash_v: HashMap::new(),
hash_k_peerinfo_v: HashMap::new(),
times_to_check: VecDeque::new(),
time_k_ip_v: HashMap::new(),
ip_k_peerinfo_v: HashMap::new(),
}
}
pub fn update_handshake(&self) {
pub fn update_handshake(&mut self) {
thread::spawn(move || {
let mut times_to_check = VecDeque::new();
let current_time: u64 = SystemTime::now()
.duration_since(time::UNIX_EPOCH)
.expect("system time before UNIX EPOCH")
.add(Duration::from_secs(10))
.as_secs();
// adds 10 seconds in the queue every 10 seconds
self.times_to_check.insert(index, value);
loop {
let mut child = Command::new("sleep").arg("9").spawn().unwrap();
let _result = child.wait().unwrap();
for n in 0..9 {
// push 9 successive seconds
times_to_check.push_back(current_time + n);
// gestion d'erreur si verrou mort
}
}
});
}
@@ -41,9 +56,9 @@ impl HandshakeHistory {
.expect("system time before UNIX EPOCH")
.as_secs();
println!("time:{}", current_time);
self.time_k_hash_v.insert(current_time, hash);
/*self.time_k_hash_v.insert(current_time, hash);
self.hash_k_peerinfo_v
.insert(hash, PeerInfo { username, ip });
.insert(hash, PeerInfo { username, ip });*/
}
}