@@ -219,9 +219,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
219
219
let mut result = None ;
220
220
221
221
loop {
222
+ if let Phase :: ConfirmingParticipants = phase {
223
+ if swarm. behaviour ( ) . gossipsub . all_peers ( ) . count ( ) == 0 {
224
+ if result. is_none ( ) {
225
+ eprintln ! ( "Not everyone agreed to participate, exiting without running the benchmark." ) ;
226
+ }
227
+ std:: process:: exit ( 1 ) ;
228
+ }
229
+ }
222
230
if let Phase :: SendingShares = phase {
223
231
if swarm. behaviour ( ) . gossipsub . all_peers ( ) . count ( ) == 0 {
224
- std:: process:: exit ( 0 ) ;
232
+ if result. is_none ( ) {
233
+ eprintln ! ( "The benchmark was cancelled by one of the participants, exiting." ) ;
234
+ }
235
+ std:: process:: exit ( 1 ) ;
225
236
}
226
237
if sent_shares. is_empty ( ) {
227
238
for public_key in participants. keys ( ) {
@@ -451,21 +462,18 @@ async fn main() -> Result<(), Box<dyn Error>> {
451
462
( _, Event :: Upnp ( ev) ) => info ! ( "{ev:?}" ) ,
452
463
( Phase :: WaitingForParticipants , Event :: ConnectionClosed ( peer_id) ) => {
453
464
if result. is_none ( ) {
454
- let Some ( disconnected) =
465
+ let Some ( ( _ , ( disconnected, _ ) ) ) =
455
466
participants. iter ( ) . find ( |( _, ( _, id) ) | * id == peer_id)
456
467
else {
457
- println ! ( "Connection error, please try again." ) ;
458
- std:: process:: exit ( 1 ) ;
468
+ continue ;
459
469
} ;
460
470
461
- let disconnected = disconnected. 1 . 0 . clone ( ) ;
462
-
463
471
println ! ( "\n Participant {disconnected} disconnected" ) ;
464
472
465
473
if swarm. connected_peers ( ) . count ( ) == 0 && is_leader {
466
474
participants. retain ( |_, ( _, id) | * id != peer_id) ;
467
475
} else if is_leader {
468
- let msg = Msg :: Quit ( peer_id, disconnected) . serialize ( ) ?;
476
+ let msg = Msg :: Quit ( peer_id, disconnected. clone ( ) ) . serialize ( ) ?;
469
477
swarm
470
478
. behaviour_mut ( )
471
479
. gossipsub
@@ -539,7 +547,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
539
547
) ;
540
548
continue ;
541
549
}
542
- Msg :: Quit ( ..) | Msg :: Share { .. } => { } ,
550
+ Msg :: Quit ( ..) | Msg :: Share { .. } => { }
543
551
Msg :: Sum ( public_key, sum) => {
544
552
if is_leader {
545
553
sums. insert ( public_key, sum) ;
@@ -551,6 +559,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
551
559
}
552
560
} ,
553
561
( Phase :: SendingShares , Event :: ConnectionClosed ( peer_id) ) => {
562
+ if result. is_some ( ) {
563
+ continue ;
564
+ }
554
565
if is_leader {
555
566
let Some ( ( _, ( disconnected, _) ) ) =
556
567
participants. iter ( ) . find ( |( _, ( _, id) ) | * id == peer_id)
@@ -559,11 +570,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
559
570
std:: process:: exit ( 1 ) ;
560
571
} ;
561
572
562
- println ! (
563
- "Aborting benchmark: participant {disconnected} left the while waiting for shares"
564
- ) ;
573
+ println ! ( "Participant {disconnected} left, aborting the benchmark." ) ;
565
574
} else {
566
- println ! ( "Aborting benchmark: a participant left while waiting for shares " ) ;
575
+ println ! ( "A participant left, aborting the benchmark. " ) ;
567
576
}
568
577
std:: process:: exit ( 1 ) ;
569
578
}
0 commit comments