diff --git a/Cargo.lock b/Cargo.lock index 6cdf533..2b2e716 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,7 @@ dependencies = [ "flume", "hashbrown", "indexmap", + "log", "mimalloc", "mio", "native-tls", diff --git a/TODO.md b/TODO.md index 932b5b2..1bfdfc3 100644 --- a/TODO.md +++ b/TODO.md @@ -3,11 +3,11 @@ ## aquatic_ws * ipv4 / ipv6 split state? * network - * panic/error in workers: exit program with non-zero exit code * send/recv buffer size config * limit ws message sizes? * is it even necessary to check if event is readable in poll, since that is all we're listening for? +* panic/error in workers: print error, exit program with non-zero exit code * privdrop ## aquatic_udp @@ -29,7 +29,6 @@ Probably not really necessary. If it is an honest mistake, peer will just keep announcing and after a few minutes, the peer in the map will be cleaned out and everything will start working -* log crate instead of println/eprintln? * stack-allocated vectors for announce request offers and scrape request info hashes? diff --git a/aquatic_ws/Cargo.toml b/aquatic_ws/Cargo.toml index 0a19ce9..de28bdc 100644 --- a/aquatic_ws/Cargo.toml +++ b/aquatic_ws/Cargo.toml @@ -21,6 +21,7 @@ either = "1" flume = "0.7" hashbrown = { version = "0.7", features = ["serde"] } indexmap = "1" +log = "0.4" mimalloc = { version = "0.1", default-features = false } mio = { version = "0.7", features = ["tcp", "os-poll", "os-util"] } native-tls = "0.2" diff --git a/aquatic_ws/src/lib/network/connection.rs b/aquatic_ws/src/lib/network/connection.rs index 09860d9..c77533e 100644 --- a/aquatic_ws/src/lib/network/connection.rs +++ b/aquatic_ws/src/lib/network/connection.rs @@ -3,6 +3,7 @@ use std::io::{Read, Write}; use either::Either; use hashbrown::HashMap; +use log::info; use mio::Token; use mio::net::TcpStream; use native_tls::{TlsAcceptor, TlsStream, MidHandshakeTlsStream}; @@ -145,7 +146,7 @@ impl HandshakeMachine { (Some(Either::Right(Self::TlsMidHandshake(handshake))), true) }, Err(native_tls::HandshakeError::Failure(err)) => { - eprintln!("tls handshake error: {}", err); + info!("tls handshake error: {}", err); (None, false) } @@ -171,7 +172,7 @@ impl HandshakeMachine { (Some(Either::Right(HandshakeMachine::WsMidHandshake(handshake))), true) }, Err(HandshakeError::Failure(err)) => { - eprintln!("ws handshake error: {}", err); + info!("ws handshake error: {}", err); (None, false) } @@ -243,7 +244,7 @@ impl Connection { // Required after ws.close() if let Err(err) = ews.ws.write_pending(){ - eprintln!( + info!( "error writing pending messages after closing ws: {}", err ) diff --git a/aquatic_ws/src/lib/network/mod.rs b/aquatic_ws/src/lib/network/mod.rs index ec003e5..e65116a 100644 --- a/aquatic_ws/src/lib/network/mod.rs +++ b/aquatic_ws/src/lib/network/mod.rs @@ -2,8 +2,8 @@ use std::time::Duration; use std::io::ErrorKind; use hashbrown::HashMap; +use log::info; use native_tls::TlsAcceptor; - use mio::{Events, Poll, Interest, Token}; use mio::net::TcpListener; @@ -145,7 +145,7 @@ fn accept_new_streams( break } - eprint!("error while accepting streams: {}", err); + info!("error while accepting streams: {}", err); } } } @@ -189,7 +189,7 @@ pub fn run_handshakes_and_read_messages( break }, Err(err) => { - eprintln!("error reading messages: {}", err); + info!("error reading messages: {}", err); remove_connection_if_exists(connections, poll_token); @@ -225,7 +225,7 @@ pub fn send_out_messages( if let Some(established_ws) = opt_established_ws { if established_ws.peer_addr != meta.peer_addr { - eprintln!("socket worker error: peer socket addrs didn't match"); + info!("socket worker error: peer socket addrs didn't match"); continue; } @@ -239,7 +239,7 @@ pub fn send_out_messages( remove_connection_if_exists(connections, meta.poll_token); }, Err(err) => { - eprintln!("error writing ws message: {}", err); + info!("error writing ws message: {}", err); remove_connection_if_exists( connections,