Remove rand crate dependency

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 3 years ago
parent d4af9285c2
commit d5a8b4e693
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

1
Cargo.lock generated

@ -633,7 +633,6 @@ dependencies = [
"fakeit",
"native-tls",
"num_cpus",
"rand 0.8.3",
"scheduled-thread-pool",
"structopt",
]

@ -9,7 +9,6 @@ edition = "2018"
[dependencies]
native-tls = "0.2.7"
structopt = "0.3.21"
rand = "0.8.3"
fakeit = "1.1.1"
scheduled-thread-pool = "0.2.5"
num_cpus = "1.13.0"

@ -3,7 +3,6 @@ Copyright (c) 2021 trivernis
See LICENSE for more information
*/
use native_tls::TlsConnector;
use rand::Rng;
use scheduled_thread_pool::ScheduledThreadPool;
use std::io::Write;
use std::net::TcpStream;
@ -50,19 +49,17 @@ fn main() {
/// Sends Keep-Alive data to the server
fn keep_alive(pool: Arc<ScheduledThreadPool>, i: usize, address: String, port: u32, https: bool) {
let mut rng = rand::thread_rng();
if let Some(mut stream) = create_connection(&*address, port, https) {
println!("Connection {} established.", i);
let pool_clone = Arc::clone(&pool);
pool.execute_at_fixed_rate(
Duration::from_secs(rng.gen_range(5..10)),
Duration::from_secs(rng.gen_range(5..10)),
Duration::from_secs(fakeit::misc::random(5, 10)),
Duration::from_secs(fakeit::misc::random(5, 10)),
move || {
println!(r#"Sending "Keep-Alive-Header" for connection {}..."#, i);
if let Err(_) = stream.write_all(&[rand::random::<u8>()]) {
if let Err(_) = stream.write_all(&[fakeit::misc::random(0u8, 255u8)]) {
let address = address.clone();
let pool_clone2 = Arc::clone(&pool_clone);
println!("Connection {} lost. Reestablishing...", i);
@ -96,7 +93,6 @@ fn create_connection(
} else {
Box::new(tcp_stream)
};
stream
.write_all(
format!(

Loading…
Cancel
Save