From 4352050b04b44bd30565fdb445e78e98884a8565 Mon Sep 17 00:00:00 2001 From: KernelErr <45716019+KernelErr@users.noreply.github.com> Date: Thu, 21 Oct 2021 17:01:52 +0800 Subject: [PATCH] Pass Clippy and ignore shutdown error The client might close the connection before the server noticed. So we simply ignore the error thrown by the shutdown operation. --- src/servers/mod.rs | 4 +-- src/servers/tls.rs | 67 ++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/servers/mod.rs b/src/servers/mod.rs index 1b25fef..c042a4c 100644 --- a/src/servers/mod.rs +++ b/src/servers/mod.rs @@ -41,7 +41,7 @@ impl Server { let default = proxy.default.clone().unwrap_or_else(|| "ban".to_string()); let upstream = config.upstream.clone(); let mut upstream_set: HashSet = HashSet::new(); - for (key, _) in &upstream { + for key in upstream.keys() { if key.eq("ban") || key.eq("echo") { continue; } @@ -200,7 +200,7 @@ where { match io::copy(reader, writer).await { Ok(u64) => { - writer.shutdown().await?; + let _ = writer.shutdown().await; Ok(u64) } Err(_) => Ok(0), diff --git a/src/servers/tls.rs b/src/servers/tls.rs index 315ea2d..9bf87a4 100644 --- a/src/servers/tls.rs +++ b/src/servers/tls.rs @@ -7,56 +7,47 @@ use tls_parser::{ pub fn get_sni(buf: &[u8]) -> Vec { let mut snis: Vec = Vec::new(); match parse_tls_raw_record(buf) { - Ok((_, ref r)) => { - match parse_tls_record_with_header(r.data, &r.hdr) { - Ok((_, ref msg_list)) => { - for msg in msg_list { - match *msg { - TlsMessage::Handshake(ref m) => match *m { - TlsMessageHandshake::ClientHello(ref content) => { - debug!("TLS ClientHello version: {}", content.version); - let ext = parse_tls_extensions(content.ext.unwrap_or(b"")); - match ext { - Ok((_, ref extensions)) => { - for ext in extensions { - match *ext { - tls_parser::TlsExtension::SNI(ref v) => { - for &(t, sni) in v { - match String::from_utf8(sni.to_vec()) { - Ok(s) => { - debug!("TLS SNI: {} {}", t, s); - snis.push(s); - } - Err(e) => { - warn!("Failed to parse SNI: {} {}", t, e); - } - } - } - } - _ => {} + Ok((_, ref r)) => match parse_tls_record_with_header(r.data, &r.hdr) { + Ok((_, ref msg_list)) => { + for msg in msg_list { + if let TlsMessage::Handshake(TlsMessageHandshake::ClientHello(ref content)) = + *msg + { + debug!("TLS ClientHello version: {}", content.version); + let ext = parse_tls_extensions(content.ext.unwrap_or(b"")); + match ext { + Ok((_, ref extensions)) => { + for ext in extensions { + if let tls_parser::TlsExtension::SNI(ref v) = *ext { + for &(t, sni) in v { + match String::from_utf8(sni.to_vec()) { + Ok(s) => { + debug!("TLS SNI: {} {}", t, s); + snis.push(s); + } + Err(e) => { + warn!("Failed to parse SNI: {} {}", t, e); } } } - Err(e) => { - warn!("TLS extensions error: {}", e); - } } } - _ => {} - }, - _ => {} + } + Err(e) => { + warn!("TLS extensions error: {}", e); + } } } } - Err(err) => { - warn!("Failed to parse TLS: {}", err); - } } - } + Err(err) => { + warn!("Failed to parse TLS: {}", err); + } + }, Err(err) => { warn!("Failed to parse TLS: {}", err); } } - + snis }