From 5adcb028e7c30541218c573152cae325ea64058a Mon Sep 17 00:00:00 2001 From: Dustin Strobel Date: Mon, 27 May 2024 19:08:13 +0200 Subject: [PATCH] fix: dsp tcp denial of service --- src/sender.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sender.rs b/src/sender.rs index dcc5eaa..35a2485 100644 --- a/src/sender.rs +++ b/src/sender.rs @@ -6,6 +6,9 @@ use std::error::Error; use std::io::prelude::*; use std::net::TcpStream; +// Define the TCP timeout in milliseconds +const TCP_TIMEOUT: u64 = 100; + fn replace_timestamp_last_colon_to_comma(input: &str) -> Result> { let split = input.split(':').collect::>(); @@ -89,6 +92,9 @@ fn send_timescript_and_entries( send_tcp_packet(stream, "")?; i += 1; + + // Sleep for to prevent the DSP from crashing + std::thread::sleep(std::time::Duration::from_millis(TCP_TIMEOUT)); } // Swtich to DSP main window @@ -114,6 +120,9 @@ fn send_timescript(entries: Vec, stream: &mut TcpStream) -> Result<(), Bo // Add timestamp to timescript send_tcp_packet(stream, ×cript_insert)?; send_tcp_packet(stream, "")?; + + // Sleep for to prevent the DSP from crashing + std::thread::sleep(std::time::Duration::from_millis(TCP_TIMEOUT)); } // Swtich to DSP main window @@ -128,7 +137,6 @@ pub fn send( create_entries: bool, entry_offset: i32, ) -> Result<(), Box> { - // Open TCP/IP stream let mut stream = TcpStream::connect(target)?; info!("TCP stream opened to address: {}", target);