fix: server allowing sending ready while hands not shaken

This commit is contained in:
2026-08-19 11:09:46 +02:00
parent 6b565e4f0e
commit bcb757b904
3 changed files with 18 additions and 4 deletions

View File

@@ -32,8 +32,11 @@ pub struct Client {
} }
impl Client { impl Client {
pub async fn new() -> Option<Client> { pub async fn new(settings: Option<ClientSettings>) -> Option<Client> {
let settings = ClientSettings::new(); let Some(settings) = settings.or(Some(ClientSettings::new())) else {
error!("Could not load client settings");
return None;
};
let (conn_sender, conn_reciever) = let (conn_sender, conn_reciever) =
mpsc::channel::<(SocketAddr, Message<ServerMessage>)>(1024); mpsc::channel::<(SocketAddr, Message<ServerMessage>)>(1024);

View File

@@ -33,6 +33,7 @@ pub struct NetworkServerIdentity {
// writing this since 10 a.m. and it's 9 p.m. already) // writing this since 10 a.m. and it's 9 p.m. already)
pub identity: NetworkIdentity, pub identity: NetworkIdentity,
pub sender: Sender<Message<ServerMessage>>, pub sender: Sender<Message<ServerMessage>>,
pub is_handshaken: bool,
} }
impl NetworkServerIdentity { impl NetworkServerIdentity {
@@ -40,6 +41,7 @@ impl NetworkServerIdentity {
Self { Self {
identity: NetworkIdentity::default(), identity: NetworkIdentity::default(),
sender, sender,
is_handshaken: false,
} }
} }
} }

View File

@@ -186,7 +186,7 @@ impl Server {
ClientMessage::SignalReadiness => { ClientMessage::SignalReadiness => {
self.handle_readiness(addr).await self.handle_readiness(addr).await
}, }
ClientMessage::RequestCapture { capture_path } => { ClientMessage::RequestCapture { capture_path } => {
self.process_capture(capture_path).await; self.process_capture(capture_path).await;
@@ -282,7 +282,8 @@ impl Server {
return; return;
}; };
identity.identity.name = fixed_name identity.identity.name = fixed_name;
identity.is_handshaken = true;
} }
async fn process_capture(&mut self, capture_path: CapturePath) { async fn process_capture(&mut self, capture_path: CapturePath) {
@@ -313,6 +314,14 @@ impl Server {
} }
async fn handle_readiness(&mut self, addr: SocketAddr) { async fn handle_readiness(&mut self, addr: SocketAddr) {
if !self.connections[&addr].is_handshaken {
warn!(
"Connection: {} tried sending readiness, but it have not shaken hands. Ignoring...",
addr
);
return;
}
self.state.ready_count += 1; self.state.ready_count += 1;
info!( info!(
"{} signaled readiness. Currently ready: {}/{}", "{} signaled readiness. Currently ready: {}/{}",