manage handshake wiip

This commit is contained in:
2026-01-09 01:03:40 +01:00
parent cd2f87cb81
commit 9fc33804d0
6 changed files with 145 additions and 212 deletions

View File

@@ -0,0 +1,68 @@
// this class consists of a thread that will re send pings every time the first element
// of the stack is at the correct unix time
use std::{
collections::{HashMap, VecDeque},
net::SocketAddr,
thread,
time::{self, SystemTime},
};
pub struct PeerInfo {
username: String,
ip: SocketAddr,
}
pub struct HandshakeHistory {
time_k_hash_v: HashMap<u64, u64>,
hash_k_peerinfo_v: HashMap<u64, PeerInfo>,
times_to_check: VecDeque<u64>,
}
impl HandshakeHistory {
pub fn new() -> HandshakeHistory {
HandshakeHistory {
time_k_hash_v: HashMap::new(),
hash_k_peerinfo_v: HashMap::new(),
times_to_check: VecDeque::new(),
}
}
pub fn update_handshake(&self) {
thread::spawn(move || {
// adds 10 seconds in the queue every 10 seconds
self.times_to_check.insert(index, value);
});
}
pub fn add_new_handshake(&mut self, hash: u64, username: String, ip: SocketAddr) {
let current_time: u64 = SystemTime::now()
.duration_since(time::UNIX_EPOCH)
.expect("system time before UNIX EPOCH")
.as_secs();
println!("time:{}", current_time);
self.time_k_hash_v.insert(current_time, hash);
self.hash_k_peerinfo_v
.insert(hash, PeerInfo { username, ip });
}
}
#[cfg(test)]
mod tests {
use std::net::{IpAddr, Ipv4Addr};
use super::*;
///
/// creates a cryptographic signature
///
#[test]
fn creating_cryptographic_signature() {
let mut hh = HandshakeHistory::new();
hh.add_new_handshake(
20,
"putain".to_string(),
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1),
);
}
}