mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +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::*;
|
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)]
|
#[derive(Default)]
|
||||||
pub struct Statistics {
|
pub struct Statistics {
|
||||||
pub requests: AtomicUsize,
|
pub requests: AtomicUsize,
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ impl ConnectionState {
|
||||||
|
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
stream: ConnectionState,
|
stream: ConnectionState,
|
||||||
|
peer_id: PeerId,
|
||||||
can_send: bool,
|
can_send: bool,
|
||||||
send_answer: Option<(PeerId, OfferId)>,
|
send_answer: Option<(PeerId, OfferId)>,
|
||||||
}
|
}
|
||||||
|
|
@ -76,6 +77,7 @@ pub struct Connection {
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub fn create_and_register(
|
pub fn create_and_register(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
|
rng: &mut impl Rng,
|
||||||
connections: &mut ConnectionMap,
|
connections: &mut ConnectionMap,
|
||||||
poll: &mut Poll,
|
poll: &mut Poll,
|
||||||
token_counter: &mut usize,
|
token_counter: &mut usize,
|
||||||
|
|
@ -88,6 +90,7 @@ impl Connection {
|
||||||
|
|
||||||
let connection = Connection {
|
let connection = Connection {
|
||||||
stream: ConnectionState::TcpStream(stream),
|
stream: ConnectionState::TcpStream(stream),
|
||||||
|
peer_id: PeerId(rng.gen()),
|
||||||
can_send: false,
|
can_send: false,
|
||||||
send_answer: None,
|
send_answer: None,
|
||||||
};
|
};
|
||||||
|
|
@ -105,6 +108,7 @@ impl Connection {
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
stream,
|
stream,
|
||||||
|
peer_id: self.peer_id,
|
||||||
can_send,
|
can_send,
|
||||||
send_answer: None,
|
send_answer: None,
|
||||||
})
|
})
|
||||||
|
|
@ -176,7 +180,6 @@ impl Connection {
|
||||||
config: &Config,
|
config: &Config,
|
||||||
state: &LoadTestState,
|
state: &LoadTestState,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
connection_id: usize
|
|
||||||
) -> bool { // bool = remove connection
|
) -> bool { // bool = remove connection
|
||||||
if !self.can_send {
|
if !self.can_send {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -187,7 +190,7 @@ impl Connection {
|
||||||
&config,
|
&config,
|
||||||
&state,
|
&state,
|
||||||
rng,
|
rng,
|
||||||
connection_id
|
self.peer_id
|
||||||
);
|
);
|
||||||
|
|
||||||
// If self.send_answer is set and request is announce request, make
|
// If self.send_answer is set and request is announce request, make
|
||||||
|
|
@ -287,7 +290,6 @@ pub fn run_socket_thread(
|
||||||
config,
|
config,
|
||||||
&state,
|
&state,
|
||||||
&mut rng,
|
&mut rng,
|
||||||
*k
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if drop_connection {
|
if drop_connection {
|
||||||
|
|
@ -303,6 +305,7 @@ pub fn run_socket_thread(
|
||||||
if connections.len() < config.num_connections && iter_counter % create_conn_interval == 0 {
|
if connections.len() < config.num_connections && iter_counter % create_conn_interval == 0 {
|
||||||
let res = Connection::create_and_register(
|
let res = Connection::create_and_register(
|
||||||
config,
|
config,
|
||||||
|
&mut rng,
|
||||||
&mut connections,
|
&mut connections,
|
||||||
&mut poll,
|
&mut poll,
|
||||||
&mut token_counter,
|
&mut token_counter,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pub fn create_random_request(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
state: &LoadTestState,
|
state: &LoadTestState,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
connection_id: usize,
|
peer_id: PeerId
|
||||||
) -> InMessage {
|
) -> InMessage {
|
||||||
let weights = [
|
let weights = [
|
||||||
config.torrents.weight_announce as u32,
|
config.torrents.weight_announce as u32,
|
||||||
|
|
@ -32,7 +32,7 @@ pub fn create_random_request(
|
||||||
config,
|
config,
|
||||||
state,
|
state,
|
||||||
rng,
|
rng,
|
||||||
connection_id
|
peer_id
|
||||||
),
|
),
|
||||||
RequestType::Scrape => create_scrape_request(
|
RequestType::Scrape => create_scrape_request(
|
||||||
config,
|
config,
|
||||||
|
|
@ -49,7 +49,7 @@ fn create_announce_request(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
state: &LoadTestState,
|
state: &LoadTestState,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
connection_id: usize
|
peer_id: PeerId,
|
||||||
) -> InMessage {
|
) -> InMessage {
|
||||||
let (event, bytes_left) = {
|
let (event, bytes_left) = {
|
||||||
if rng.gen_bool(config.torrents.peer_seeder_probability) {
|
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 {
|
InMessage::AnnounceRequest(AnnounceRequest {
|
||||||
action: AnnounceAction,
|
action: AnnounceAction,
|
||||||
info_hash: state.info_hashes[info_hash_index],
|
info_hash: state.info_hashes[info_hash_index],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue