mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
WIP: cleanup aquatic_http_load_test and aquatic_http_protocol
This commit is contained in:
parent
d1e9d24773
commit
da3b2bcd8c
10 changed files with 232 additions and 410 deletions
|
|
@ -1,12 +1,94 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use rand_distr::{Standard, Pareto};
|
||||
use rand::distributions::WeightedIndex;
|
||||
use rand_distr::Pareto;
|
||||
use rand::prelude::*;
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::*;
|
||||
|
||||
|
||||
pub fn select_info_hash_index(
|
||||
pub fn create_random_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> Request {
|
||||
let weights = vec![
|
||||
config.handler.weight_announce as u32,
|
||||
config.handler.weight_scrape as u32,
|
||||
];
|
||||
|
||||
let items = vec![
|
||||
RequestType::Announce,
|
||||
RequestType::Scrape,
|
||||
];
|
||||
|
||||
let dist = WeightedIndex::new(&weights)
|
||||
.expect("random request weighted index");
|
||||
|
||||
match items[dist.sample(rng)] {
|
||||
RequestType::Announce => create_announce_request(
|
||||
config,
|
||||
state,
|
||||
rng,
|
||||
),
|
||||
RequestType::Scrape => create_scrape_request(
|
||||
config,
|
||||
state,
|
||||
rng,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn create_announce_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> Request {
|
||||
let (event, bytes_left) = {
|
||||
if rng.gen_bool(config.handler.peer_seeder_probability) {
|
||||
(AnnounceEvent::Completed, 0)
|
||||
} else {
|
||||
(AnnounceEvent::Started, 50)
|
||||
}
|
||||
};
|
||||
|
||||
let info_hash_index = select_info_hash_index(config, &state, rng);
|
||||
|
||||
Request::Announce(AnnounceRequest {
|
||||
info_hash: state.info_hashes[info_hash_index],
|
||||
peer_id: PeerId(rng.gen()),
|
||||
bytes_left,
|
||||
event,
|
||||
key: None,
|
||||
numwant: None,
|
||||
compact: true,
|
||||
port: rng.gen()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fn create_scrape_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> Request {
|
||||
let mut scrape_hashes = Vec::new();
|
||||
|
||||
for _ in 0..20 {
|
||||
let info_hash_index = select_info_hash_index(config, &state, rng);
|
||||
|
||||
scrape_hashes.push(state.info_hashes[info_hash_index]);
|
||||
}
|
||||
|
||||
Request::Scrape(ScrapeRequest {
|
||||
info_hashes: scrape_hashes,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fn select_info_hash_index(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
|
|
@ -15,7 +97,7 @@ pub fn select_info_hash_index(
|
|||
}
|
||||
|
||||
|
||||
pub fn pareto_usize(
|
||||
fn pareto_usize(
|
||||
rng: &mut impl Rng,
|
||||
pareto: &Arc<Pareto<f64>>,
|
||||
max: usize,
|
||||
|
|
@ -24,9 +106,4 @@ pub fn pareto_usize(
|
|||
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
||||
|
||||
(p * max as f64) as usize
|
||||
}
|
||||
|
||||
|
||||
pub fn generate_info_hash(rng: &mut impl Rng) -> InfoHash {
|
||||
InfoHash(rng.gen())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue