From 55516956ca5fe192ee134b1bcda6209fbc07493d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Thu, 4 Jan 2024 17:28:48 +0100 Subject: [PATCH] udp load test: store peer scrape_hash_indices as boxed slice --- crates/udp_load_test/src/common.rs | 2 +- crates/udp_load_test/src/worker/request_gen.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/udp_load_test/src/common.rs b/crates/udp_load_test/src/common.rs index ade23ac..7cbffbd 100644 --- a/crates/udp_load_test/src/common.rs +++ b/crates/udp_load_test/src/common.rs @@ -7,7 +7,7 @@ use aquatic_udp_protocol::*; #[derive(PartialEq, Eq, Clone)] pub struct TorrentPeer { pub info_hash: InfoHash, - pub scrape_hash_indeces: Vec, + pub scrape_hash_indices: Box<[usize]>, pub connection_id: ConnectionId, pub peer_id: PeerId, pub port: Port, diff --git a/crates/udp_load_test/src/worker/request_gen.rs b/crates/udp_load_test/src/worker/request_gen.rs index 1f311f3..6ce2355 100644 --- a/crates/udp_load_test/src/worker/request_gen.rs +++ b/crates/udp_load_test/src/worker/request_gen.rs @@ -172,11 +172,11 @@ fn create_scrape_request( torrent_peer: &TorrentPeer, transaction_id: TransactionId, ) -> Request { - let indeces = &torrent_peer.scrape_hash_indeces; + let indeces = &torrent_peer.scrape_hash_indices; let mut scape_hashes = Vec::with_capacity(indeces.len()); - for i in indeces { + for i in indeces.iter() { scape_hashes.push(info_hashes[*i].to_owned()) } @@ -195,19 +195,18 @@ fn create_torrent_peer( info_hashes: &Arc<[InfoHash]>, connection_id: ConnectionId, ) -> TorrentPeer { - let num_scape_hashes = rng.gen_range(1..config.requests.scrape_max_torrents); + let num_scrape_hashes = rng.gen_range(1..config.requests.scrape_max_torrents); - let mut scrape_hash_indeces = Vec::new(); - - for _ in 0..num_scape_hashes { - scrape_hash_indeces.push(select_info_hash_index(config, rng, gamma)) - } + let scrape_hash_indices = (0..num_scrape_hashes) + .map(|_| select_info_hash_index(config, rng, gamma)) + .collect::>() + .into_boxed_slice(); let info_hash_index = select_info_hash_index(config, rng, gamma); TorrentPeer { info_hash: info_hashes[info_hash_index], - scrape_hash_indeces, + scrape_hash_indices, connection_id, peer_id: generate_peer_id(), port: Port::new(rng.gen()),