Skip to content

Commit

Permalink
reverse(tlv): remove incomplete packet handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
neochristou committed May 1, 2024
1 parent 0133432 commit 3e99ee7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
Binary file modified reverse/TLV/public/tlv
Binary file not shown.
9 changes: 2 additions & 7 deletions reverse/TLV/setup/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ fn run_shell_command(command: &str, args: &[&str]) -> Result<Output, std::io::Er

fn handle_client(mut stream: TcpStream) {
let mut buffer = [0; 4096];
let mut incomplete_packet: Vec<u8> = Vec::new();

loop {
match stream.read(&mut buffer) {
Expand All @@ -160,12 +159,10 @@ fn handle_client(mut stream: TcpStream) {
println!("Received {n} bytes");

let mut bytes = Vec::new();
let mut offset = 0;
bytes.extend_from_slice(&buffer[..n]);

let mut offset = 0;
while offset < n {
// Append any incomplete packet from previous reads
bytes.extend_from_slice(&incomplete_packet);
bytes.extend_from_slice(&buffer[..n]);

if let Some(header) = TLVHeader::from_bytes(&buffer) {

Expand All @@ -188,8 +185,6 @@ fn handle_client(mut stream: TcpStream) {
break; // Break the loop if the packet is invalid
}
}
// Store any incomplete packet for the next read
incomplete_packet = bytes[offset..].to_vec();
}
Ok(_) | Err(_) => {
println!("Client disconnected");
Expand Down
Binary file modified reverse/TLV/setup/tlv
Binary file not shown.

0 comments on commit 3e99ee7

Please sign in to comment.