From 6a6b453953ff35223afc8472c878820d92ef7191 Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Wed, 31 May 2023 19:01:10 +0200 Subject: [PATCH] add .corrupt logic just like with the py version --- rust/client/src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/rust/client/src/main.rs b/rust/client/src/main.rs index a987d41..b76d7c0 100644 --- a/rust/client/src/main.rs +++ b/rust/client/src/main.rs @@ -225,8 +225,13 @@ fn main() { for i in 0..packets.len() { crc32.update(&packets[i]); if packet_hashes[i] != crc32.clone().finalize() { - println!("Packet {} hash does not match", i); - todo!("Request packets again") + println!("Packet {} crc does not match, writing .corrupt", i); + //TODO: Request packets again + let mut file = std::fs::File::create("received/".to_string()+filename+".corrupt").expect("Failed to create file"); + for i in 0..packets.len() { + file.write_all(&packets[i]).expect("Failed to write to file"); + } + return; } } @@ -239,7 +244,12 @@ fn main() { let client_hash = hasher.finalize(); if client_hash[..64] != server_hash { - panic!("Hashes do not match, correct hash: {:?}, client hash: {:?}", server_hash, client_hash); + println!("Hashes do not match, correct hash: {:?}, client hash: {:?}", server_hash, client_hash); + let mut file = std::fs::File::create("received/".to_string()+filename+".corrupt").expect("Failed to create file"); + for i in 0..packets.len() { + file.write_all(&packets[i]).expect("Failed to write to file"); + } + return; }