diff --git a/aquatic_ws_load_test/src/common.rs b/aquatic_ws_load_test/src/common.rs index db3be95..e1f6a54 100644 --- a/aquatic_ws_load_test/src/common.rs +++ b/aquatic_ws_load_test/src/common.rs @@ -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, - pub peer_id: PeerId, - pub port: u16, -} - - #[derive(Default)] pub struct Statistics { pub requests: AtomicUsize, diff --git a/aquatic_ws_load_test/src/network.rs b/aquatic_ws_load_test/src/network.rs index ef406ab..0545a9c 100644 --- a/aquatic_ws_load_test/src/network.rs +++ b/aquatic_ws_load_test/src/network.rs @@ -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, diff --git a/aquatic_ws_load_test/src/utils.rs b/aquatic_ws_load_test/src/utils.rs index c4e33a4..74aa0ef 100644 --- a/aquatic_ws_load_test/src/utils.rs +++ b/aquatic_ws_load_test/src/utils.rs @@ -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],