udp load test: store peer scrape_hash_indices as boxed slice

This commit is contained in:
Joakim Frostegård 2024-01-04 17:28:48 +01:00
parent 99791c7154
commit 55516956ca
2 changed files with 9 additions and 10 deletions

View file

@ -7,7 +7,7 @@ use aquatic_udp_protocol::*;
#[derive(PartialEq, Eq, Clone)] #[derive(PartialEq, Eq, Clone)]
pub struct TorrentPeer { pub struct TorrentPeer {
pub info_hash: InfoHash, pub info_hash: InfoHash,
pub scrape_hash_indeces: Vec<usize>, pub scrape_hash_indices: Box<[usize]>,
pub connection_id: ConnectionId, pub connection_id: ConnectionId,
pub peer_id: PeerId, pub peer_id: PeerId,
pub port: Port, pub port: Port,

View file

@ -172,11 +172,11 @@ fn create_scrape_request(
torrent_peer: &TorrentPeer, torrent_peer: &TorrentPeer,
transaction_id: TransactionId, transaction_id: TransactionId,
) -> Request { ) -> Request {
let indeces = &torrent_peer.scrape_hash_indeces; let indeces = &torrent_peer.scrape_hash_indices;
let mut scape_hashes = Vec::with_capacity(indeces.len()); 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()) scape_hashes.push(info_hashes[*i].to_owned())
} }
@ -195,19 +195,18 @@ fn create_torrent_peer(
info_hashes: &Arc<[InfoHash]>, info_hashes: &Arc<[InfoHash]>,
connection_id: ConnectionId, connection_id: ConnectionId,
) -> TorrentPeer { ) -> 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(); let scrape_hash_indices = (0..num_scrape_hashes)
.map(|_| select_info_hash_index(config, rng, gamma))
for _ in 0..num_scape_hashes { .collect::<Vec<_>>()
scrape_hash_indeces.push(select_info_hash_index(config, rng, gamma)) .into_boxed_slice();
}
let info_hash_index = select_info_hash_index(config, rng, gamma); let info_hash_index = select_info_hash_index(config, rng, gamma);
TorrentPeer { TorrentPeer {
info_hash: info_hashes[info_hash_index], info_hash: info_hashes[info_hash_index],
scrape_hash_indeces, scrape_hash_indices,
connection_id, connection_id,
peer_id: generate_peer_id(), peer_id: generate_peer_id(),
port: Port::new(rng.gen()), port: Port::new(rng.gen()),