fix unecryted network

This commit is contained in:
PoliEcho 2025-08-01 19:38:59 +02:00
parent 4a70fb61f9
commit 4ca652cea5

View File

@ -84,22 +84,25 @@ pub async fn handle_ip_packet(
let mut iv: [u8; BLOCK_SIZE] = [0u8; BLOCK_SIZE]; let mut iv: [u8; BLOCK_SIZE] = [0u8; BLOCK_SIZE];
rng.fill_bytes(&mut iv); rng.fill_bytes(&mut iv);
let mut encrypted_data = let mut procesed_data: Vec<u8> = if network.read().unwrap().encrypted {
match shared::crypto::encrypt(&network.read().unwrap().key, &iv, &packet_data) { match shared::crypto::encrypt(&network.read().unwrap().key, &iv, &packet_data) {
Ok(cr) => cr, Ok(cr) => cr,
Err(e) => { Err(e) => {
eprintln!("Failed to encrypt packet droping it: {}", e); eprintln!("Failed to encrypt packet droping it: {}", e);
return; return;
} }
}; }
} else {
packet_data.to_vec()
};
encrypted_data.insert(0, P2PMethods::PACKET as u8); procesed_data.insert(0, P2PMethods::PACKET as u8);
encrypted_data.splice(1..1, iv); procesed_data.splice(1..1, iv);
if dst_ip.octets()[3] == 255 { if dst_ip.octets()[3] == 255 {
network.read().unwrap().peers.par_iter().for_each(|peer| { network.read().unwrap().peers.par_iter().for_each(|peer| {
// broadcast // broadcast
match socket.send_to(&encrypted_data, peer.sock_addr) { match socket.send_to(&procesed_data, peer.sock_addr) {
Ok(_) => {} Ok(_) => {}
Err(e) => eprintln!("failed to send packet: {}", e), Err(e) => eprintln!("failed to send packet: {}", e),
}; };
@ -117,7 +120,7 @@ pub async fn handle_ip_packet(
None => return, None => return,
}; };
match socket.send_to(&encrypted_data, dst) { match socket.send_to(&procesed_data, dst) {
Ok(_) => {} Ok(_) => {}
Err(e) => eprintln!("failed to send packet: {}", e), Err(e) => eprintln!("failed to send packet: {}", e),
}; };