diff --git a/src/main.rs b/src/main.rs index 9753e4c..bcd562a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,7 +95,7 @@ fn mopp(speed: u8, data: &[u8]) -> Vec { ); let mut res = Vec::::new(); - + for i in (0..m.len()).step_by(8) { let value = u8::from_str_radix(&m[i..i + 8], 2).unwrap(); res.push(value); @@ -149,6 +149,8 @@ fn main() -> std::io::Result<()> { let mut subscribers: HashMap> = HashMap::new(); loop { + thread::sleep(core::time::Duration::from_millis(200)); // Anti flood (?) + let mut buf = [0; 64]; // Waiting for incoming pakets. Otherwise, after timeout, send keepalive paket @@ -157,7 +159,7 @@ fn main() -> std::io::Result<()> { Ok((num, s)) => (num, s), Err(_) => { remove_old_clients(&socket, &mut subscribers); - // debug!("Sending keepalive pakets …"); + for rec in &subscribers { debug!("Sending keepalive paket to {}", rec.0); socket.send_to(b"", rec.0).unwrap(); @@ -170,11 +172,9 @@ fn main() -> std::io::Result<()> { let speed = buf[1] >> 2; let data = &buf[0..number_of_bytes]; - thread::sleep(core::time::Duration::from_millis(200)); // Anti flood (?) - if subscribers.contains_key(&client_addr) { debug!("Client known: {client_addr}"); - + if strip_header(data) == strip_header(mopp(speed, b":bye").as_slice()) { debug!("Removing client {client_addr} as requested."); socket