|
|
|
@ -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!(
|
|
|
|
|