mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
Run rustfmt, clean up aquatic_http_protocol/Cargo.toml
This commit is contained in:
parent
0cc312a78d
commit
d0e716f80b
65 changed files with 1754 additions and 2590 deletions
|
|
@ -1,49 +1,33 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use rand::distributions::WeightedIndex;
|
||||
use rand_distr::Pareto;
|
||||
use rand::prelude::*;
|
||||
use rand_distr::Pareto;
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::*;
|
||||
|
||||
|
||||
pub fn create_random_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
peer_id: PeerId
|
||||
peer_id: PeerId,
|
||||
) -> InMessage {
|
||||
let weights = [
|
||||
config.torrents.weight_announce as u32,
|
||||
config.torrents.weight_scrape as u32,
|
||||
config.torrents.weight_scrape as u32,
|
||||
];
|
||||
|
||||
let items = [
|
||||
RequestType::Announce,
|
||||
RequestType::Scrape,
|
||||
];
|
||||
let items = [RequestType::Announce, RequestType::Scrape];
|
||||
|
||||
let dist = WeightedIndex::new(&weights)
|
||||
.expect("random request weighted index");
|
||||
let dist = WeightedIndex::new(&weights).expect("random request weighted index");
|
||||
|
||||
match items[dist.sample(rng)] {
|
||||
RequestType::Announce => create_announce_request(
|
||||
config,
|
||||
state,
|
||||
rng,
|
||||
peer_id
|
||||
),
|
||||
RequestType::Scrape => create_scrape_request(
|
||||
config,
|
||||
state,
|
||||
rng,
|
||||
)
|
||||
RequestType::Announce => create_announce_request(config, state, rng, peer_id),
|
||||
RequestType::Scrape => create_scrape_request(config, state, rng),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[inline]
|
||||
fn create_announce_request(
|
||||
config: &Config,
|
||||
|
|
@ -61,10 +45,8 @@ fn create_announce_request(
|
|||
|
||||
let info_hash_index = select_info_hash_index(config, &state, rng);
|
||||
|
||||
let mut offers = Vec::with_capacity(
|
||||
config.torrents.offers_per_request
|
||||
);
|
||||
|
||||
let mut offers = Vec::with_capacity(config.torrents.offers_per_request);
|
||||
|
||||
for _ in 0..config.torrents.offers_per_request {
|
||||
offers.push(AnnounceRequestOffer {
|
||||
offer_id: OfferId(rng.gen()),
|
||||
|
|
@ -88,13 +70,8 @@ fn create_announce_request(
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn create_scrape_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> InMessage {
|
||||
fn create_scrape_request(config: &Config, state: &LoadTestState, rng: &mut impl Rng) -> InMessage {
|
||||
let mut scrape_hashes = Vec::with_capacity(5);
|
||||
|
||||
for _ in 0..5 {
|
||||
|
|
@ -109,25 +86,15 @@ fn create_scrape_request(
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn select_info_hash_index(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> usize {
|
||||
fn select_info_hash_index(config: &Config, state: &LoadTestState, rng: &mut impl Rng) -> usize {
|
||||
pareto_usize(rng, &state.pareto, config.torrents.number_of_torrents - 1)
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn pareto_usize(
|
||||
rng: &mut impl Rng,
|
||||
pareto: &Arc<Pareto<f64>>,
|
||||
max: usize,
|
||||
) -> usize {
|
||||
fn pareto_usize(rng: &mut impl Rng, pareto: &Arc<Pareto<f64>>, max: usize) -> usize {
|
||||
let p: f64 = pareto.sample(rng);
|
||||
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
||||
|
||||
(p * max as f64) as usize
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue