From dd945f59408c806129d907f57ffb46992339f252 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Wed, 27 Mar 2024 16:38:08 -0300 Subject: [PATCH] fix: send certs in batch to each connection --- crates/topos-certificate-spammer/src/lib.rs | 50 ++++++++++++--------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/crates/topos-certificate-spammer/src/lib.rs b/crates/topos-certificate-spammer/src/lib.rs index db6569c1b..5c642578e 100644 --- a/crates/topos-certificate-spammer/src/lib.rs +++ b/crates/topos-certificate-spammer/src/lib.rs @@ -315,22 +315,22 @@ pub async fn run( let source_subnet = &mut source_subnets[rand::random::() % args.nb_subnets as usize]; // Randomize number of target subnets if target subnet list cli argument is provided - // let target_subnets: Vec = if target_subnet_ids.is_empty() { - // // Empty list of target subnets in certificate - // Vec::new() - // } else { - // // Generate random list in size of 0..len(target_subnet_ids) as target subnets - // let number_of_target_subnets = - // rand::random::() % (target_subnet_ids.len() + 1); - // let mut target_subnets = Vec::new(); - // for _ in 0..number_of_target_subnets { - // target_subnets.push( - // target_subnet_ids - // [rand::random::() % target_subnet_ids.len()], - // ); - // } - // target_subnets - // }; + let target_subnets: Vec = if target_subnet_ids.is_empty() { + // Empty list of target subnets in certificate + Vec::new() + } else { + // Generate random list in size of 0..len(target_subnet_ids) as target subnets + let number_of_target_subnets = + rand::random::() % (target_subnet_ids.len() + 1); + let mut target_subnets = Vec::new(); + for _ in 0..number_of_target_subnets { + target_subnets.push( + target_subnet_ids + [rand::random::() % target_subnet_ids.len()], + ); + } + target_subnets + }; let new_cert = match generate_test_certificate( source_subnet, @@ -346,15 +346,21 @@ pub async fn run( batch.push(new_cert); } + // Dispatch certs in this batch // Dispatch certs in this batch for cert in batch { // Randomly choose target tce node for every certificate from related source_subnet_id connection list - let target_node_connection = &target_node_connections[&cert.source_subnet_id] - [rand::random::() % target_nodes.len()]; - dispatch(cert, target_node_connection) - .instrument(Span::current()) - .with_current_context() - .await; + // let target_node_connection = &target_node_connections[&cert.source_subnet_id] + // [rand::random::() % target_nodes.len()]; + + for connection in &target_node_connections[&cert.source_subnet_id] { + if !connection.address.is_empty() { + dispatch(cert.clone(), connection) + .instrument(Span::current()) + .with_current_context() + .await; + } + } } } .instrument(span)