Skip to content

Commit

Permalink
fix: dsp tcp denial of service
Browse files Browse the repository at this point in the history
  • Loading branch information
d-strobel committed May 27, 2024
1 parent 92cd87a commit 5adcb02
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Box<dyn Error>> {
let split = input.split(':').collect::<Vec<&str>>();

Expand Down Expand Up @@ -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
Expand All @@ -114,6 +120,9 @@ fn send_timescript(entries: Vec<Entry>, stream: &mut TcpStream) -> Result<(), Bo
// Add timestamp to timescript
send_tcp_packet(stream, &timescript_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
Expand All @@ -128,7 +137,6 @@ pub fn send(
create_entries: bool,
entry_offset: i32,
) -> Result<(), Box<dyn Error>> {
// Open TCP/IP stream
let mut stream = TcpStream::connect(target)?;
info!("TCP stream opened to address: {}", target);

Expand Down

0 comments on commit 5adcb02

Please sign in to comment.