diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/server/handler.rs | 21 | ||||
| -rw-r--r-- | src/bin/server/main.rs | 20 |
2 files changed, 37 insertions, 4 deletions
diff --git a/src/bin/server/handler.rs b/src/bin/server/handler.rs index e6b623f..55df244 100644 --- a/src/bin/server/handler.rs +++ b/src/bin/server/handler.rs | |||
| @@ -32,13 +32,19 @@ pub fn handle_client_tls(mut stream: TlsStream) { | |||
| 32 | 32 | ||
| 33 | let mut state = ConnectionState::default(); | 33 | let mut state = ConnectionState::default(); |
| 34 | let mut event_seq = 0u64; | 34 | let mut event_seq = 0u64; |
| 35 | println!("[TLS Client connected] {client_addr}"); | 35 | // Port scanners reach the TLS listener too. Do not write a connection log |
| 36 | // until they send a valid frame; v5 drops their HTTP request silently. | ||
| 37 | let mut announced = false; | ||
| 36 | 38 | ||
| 37 | 'connection: loop { | 39 | 'connection: loop { |
| 38 | let mut frame = String::new(); | 40 | let mut frame = String::new(); |
| 39 | match stream.read_frame(&mut frame) { | 41 | match stream.read_frame(&mut frame) { |
| 40 | Ok(0) => break, | 42 | Ok(0) => break, |
| 41 | Ok(_) => { | 43 | Ok(_) => { |
| 44 | if !announced { | ||
| 45 | println!("[TLS Client connected] {client_addr}"); | ||
| 46 | announced = true; | ||
| 47 | } | ||
| 42 | let user = state.user().unwrap_or("guest").to_string(); | 48 | let user = state.user().unwrap_or("guest").to_string(); |
| 43 | println!("[{user} @ {client_addr}] Received: {frame}"); | 49 | println!("[{user} @ {client_addr}] Received: {frame}"); |
| 44 | match parse_request(&frame) { | 50 | match parse_request(&frame) { |
| @@ -70,6 +76,15 @@ pub fn handle_client_tls(mut stream: TlsStream) { | |||
| 70 | { | 76 | { |
| 71 | // No request yet: fall through and let timed games advance. | 77 | // No request yet: fall through and let timed games advance. |
| 72 | } | 78 | } |
| 79 | Err(error) if error.kind() == std::io::ErrorKind::InvalidData => { | ||
| 80 | // A crawler or port scanner speaking HTTP hits a frame length | ||
| 81 | // far over the cap. Close without a reply or a log line; a | ||
| 82 | // real game client that has already greeted is worth logging. | ||
| 83 | if state.greeted() { | ||
| 84 | eprintln!("Protocol error from {client_addr}: {error}"); | ||
| 85 | } | ||
| 86 | break; | ||
| 87 | } | ||
| 73 | Err(error) => { | 88 | Err(error) => { |
| 74 | eprintln!("Read error: {error}"); | 89 | eprintln!("Read error: {error}"); |
| 75 | break; | 90 | break; |
| @@ -92,5 +107,7 @@ pub fn handle_client_tls(mut stream: TlsStream) { | |||
| 92 | } | 107 | } |
| 93 | 108 | ||
| 94 | core.disconnect(&state); | 109 | core.disconnect(&state); |
| 95 | println!("[TLS Client disconnected] {client_addr}"); | 110 | if announced || state.greeted() { |
| 111 | println!("[TLS Client disconnected] {client_addr}"); | ||
| 112 | } | ||
| 96 | } | 113 | } |
diff --git a/src/bin/server/main.rs b/src/bin/server/main.rs index f42574d..4f188a3 100644 --- a/src/bin/server/main.rs +++ b/src/bin/server/main.rs | |||
| @@ -73,8 +73,24 @@ fn main() { | |||
| 73 | Ok(tls_stream) => { | 73 | Ok(tls_stream) => { |
| 74 | handler::handle_client_tls(tls_stream); | 74 | handler::handle_client_tls(tls_stream); |
| 75 | } | 75 | } |
| 76 | Err(e) => { | 76 | Err(error) => { |
| 77 | eprintln!("TLS handshake failed: {}", e); | 77 | // Public ports get a constant stream of scanners and resets. |
| 78 | // Keep the useful failures, drop the background noise. | ||
| 79 | let message = error.to_string().to_ascii_lowercase(); | ||
| 80 | let noise = [ | ||
| 81 | "unexpected eof", | ||
| 82 | "connection reset", | ||
| 83 | "broken pipe", | ||
| 84 | "handshake failure", | ||
| 85 | "received fatal alert", | ||
| 86 | "bad record mac", | ||
| 87 | "timed out", | ||
| 88 | ] | ||
| 89 | .iter() | ||
| 90 | .any(|needle| message.contains(needle)); | ||
| 91 | if !noise { | ||
| 92 | eprintln!("TLS handshake failed: {error}"); | ||
| 93 | } | ||
| 78 | } | 94 | } |
| 79 | }); | 95 | }); |
| 80 | } | 96 | } |
