From b35e009698ba6b6d8631d089b7e812521971439e Mon Sep 17 00:00:00 2001 From: Raimundo Henriques Date: Tue, 14 Nov 2023 17:14:53 +0000 Subject: [PATCH] feat: cancel the session if leader disconnects --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7c429b7..681cacb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -384,11 +384,18 @@ async fn main() -> Result<(), Box> { if result.is_none() { let Some(disconnected) = participants.iter().find(|(_, (_, id))| *id == peer_id) else { println!("Connection error, please try again."); - continue; + std::process::exit(1); }; let disconnected = disconnected.1.0.clone(); + + if swarm.connected_peers().count() == 0 { + println!("The benchmark leader cancelled the session."); + std::process::exit(1); + } + println!("\nParticipant {disconnected} disconnected"); + let msg = Msg::Quit(peer_id, disconnected).serialize()?; swarm .behaviour_mut()