Skip to content

Commit

Permalink
Use XorShiftRng to generate non-zero payload
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-markin committed Mar 19, 2024
1 parent 7e75ae5 commit ba8fb1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ libp2p = { version = "0.51.3", features = [
"quic",
]}
quickcheck = "1.0.3"
rand_xorshift = "0.3.0"
sc-network = "0.28.0"
sc-utils = "8.0.0"
serde_json = "1.0.108"
Expand Down
7 changes: 6 additions & 1 deletion tests/protocol/request_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ use litep2p::{
use futures::{channel, StreamExt};
use multiaddr::{Multiaddr, Protocol};
use multihash::Multihash;
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;
use tokio::time::sleep;

use std::{
Expand Down Expand Up @@ -2582,7 +2584,10 @@ async fn large_response(transport1: Transport, transport2: Transport) {
}
});

let response = vec![0; 15 * 1024 * 1024];
// Generate the response first and use a fast insecure RNG to make the test not timeout on
// GitHub CI when generating 15 MB of data.
let mut rng = XorShiftRng::from_rng(rand::thread_rng()).expect("`thread_rng` to seed");
let response = (0..15 * 1024 * 1024).map(|_| rng.gen::<u8>()).collect::<Vec<_>>();

let request_id =
handle1.try_send_request(peer2, vec![1, 3, 3, 7], DialOptions::Reject).unwrap();
Expand Down

0 comments on commit ba8fb1c

Please sign in to comment.