Changed the way the error are handled to removed dead code

This commit is contained in:
Thomas
2024-03-18 18:28:00 +01:00
parent d6be707242
commit 49821ec7a2

View File

@@ -28,13 +28,11 @@ fn listen(server_address: &str, config: &Config) {
let (num_bytes, src_addr) = socket.recv_from(&mut buf).expect("Error while receiving message"); let (num_bytes, src_addr) = socket.recv_from(&mut buf).expect("Error while receiving message");
if !serv_config.addr_is_blacklisted(src_addr.to_string()) { if !serv_config.addr_is_blacklisted(src_addr.to_string()) {
message.push_str(std::str::from_utf8(&buf[..num_bytes]).expect("Invalid UTF-8 data")); message.push_str(std::str::from_utf8(&buf[..num_bytes]).expect("Invalid UTF-8 data"));
match serv_config.is_forwarded(src_addr.to_string()) {
Some(v) => { let forwarding_addr_opt = serv_config.is_forwarded(src_addr.to_string());
socket.send_to(message.as_bytes(), v).expect("Error forwarding message to another ip."); if forwarding_addr_opt.is_some() {
}, let forwarding_addr = forwarding_addr_opt.unwrap();
None => { socket.send_to(message.as_bytes(), forwarding_addr).expect("Error forwarding message to another ip.");
//Nothing to do :)
}
} }
println!("{} say: {}", src_addr.to_string(), message); println!("{} say: {}", src_addr.to_string(), message);
} }