mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic ws load test: gen random PeerId per connection
Necessary for multiple workers
This commit is contained in:
parent
2d3761fee2
commit
0a23b62bd5
3 changed files with 9 additions and 21 deletions
|
|
@ -5,16 +5,6 @@ use rand_distr::Pareto;
|
|||
pub use aquatic_ws_protocol::*;
|
||||
|
||||
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct TorrentPeer {
|
||||
pub info_hash: InfoHash,
|
||||
pub scrape_hash_indeces: Vec<usize>,
|
||||
pub peer_id: PeerId,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Statistics {
|
||||
pub requests: AtomicUsize,
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ impl ConnectionState {
|
|||
|
||||
pub struct Connection {
|
||||
stream: ConnectionState,
|
||||
peer_id: PeerId,
|
||||
can_send: bool,
|
||||
send_answer: Option<(PeerId, OfferId)>,
|
||||
}
|
||||
|
|
@ -76,6 +77,7 @@ pub struct Connection {
|
|||
impl Connection {
|
||||
pub fn create_and_register(
|
||||
config: &Config,
|
||||
rng: &mut impl Rng,
|
||||
connections: &mut ConnectionMap,
|
||||
poll: &mut Poll,
|
||||
token_counter: &mut usize,
|
||||
|
|
@ -88,6 +90,7 @@ impl Connection {
|
|||
|
||||
let connection = Connection {
|
||||
stream: ConnectionState::TcpStream(stream),
|
||||
peer_id: PeerId(rng.gen()),
|
||||
can_send: false,
|
||||
send_answer: None,
|
||||
};
|
||||
|
|
@ -105,6 +108,7 @@ impl Connection {
|
|||
|
||||
Some(Self {
|
||||
stream,
|
||||
peer_id: self.peer_id,
|
||||
can_send,
|
||||
send_answer: None,
|
||||
})
|
||||
|
|
@ -176,7 +180,6 @@ impl Connection {
|
|||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
connection_id: usize
|
||||
) -> bool { // bool = remove connection
|
||||
if !self.can_send {
|
||||
return false;
|
||||
|
|
@ -187,7 +190,7 @@ impl Connection {
|
|||
&config,
|
||||
&state,
|
||||
rng,
|
||||
connection_id
|
||||
self.peer_id
|
||||
);
|
||||
|
||||
// If self.send_answer is set and request is announce request, make
|
||||
|
|
@ -287,7 +290,6 @@ pub fn run_socket_thread(
|
|||
config,
|
||||
&state,
|
||||
&mut rng,
|
||||
*k
|
||||
);
|
||||
|
||||
if drop_connection {
|
||||
|
|
@ -303,6 +305,7 @@ pub fn run_socket_thread(
|
|||
if connections.len() < config.num_connections && iter_counter % create_conn_interval == 0 {
|
||||
let res = Connection::create_and_register(
|
||||
config,
|
||||
&mut rng,
|
||||
&mut connections,
|
||||
&mut poll,
|
||||
&mut token_counter,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub fn create_random_request(
|
|||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
connection_id: usize,
|
||||
peer_id: PeerId
|
||||
) -> InMessage {
|
||||
let weights = [
|
||||
config.torrents.weight_announce as u32,
|
||||
|
|
@ -32,7 +32,7 @@ pub fn create_random_request(
|
|||
config,
|
||||
state,
|
||||
rng,
|
||||
connection_id
|
||||
peer_id
|
||||
),
|
||||
RequestType::Scrape => create_scrape_request(
|
||||
config,
|
||||
|
|
@ -49,7 +49,7 @@ fn create_announce_request(
|
|||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
connection_id: usize
|
||||
peer_id: PeerId,
|
||||
) -> InMessage {
|
||||
let (event, bytes_left) = {
|
||||
if rng.gen_bool(config.torrents.peer_seeder_probability) {
|
||||
|
|
@ -74,11 +74,6 @@ fn create_announce_request(
|
|||
})
|
||||
}
|
||||
|
||||
let mut peer_id = PeerId([0u8; 20]);
|
||||
|
||||
(&mut peer_id.0[..8])
|
||||
.copy_from_slice(&connection_id.to_ne_bytes());
|
||||
|
||||
InMessage::AnnounceRequest(AnnounceRequest {
|
||||
action: AnnounceAction,
|
||||
info_hash: state.info_hashes[info_hash_index],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue