Remove rand crate dependency

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

1
Cargo.lock generated

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

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

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

Loading…
Cancel
Save