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.
This commit is contained in:
KernelErr 2021-10-21 17:01:52 +08:00
parent 2c2509a178
commit 4352050b04
2 changed files with 31 additions and 40 deletions

View File

@ -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<String> = 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),

View File

@ -7,20 +7,18 @@ use tls_parser::{
pub fn get_sni(buf: &[u8]) -> Vec<String> {
let mut snis: Vec<String> = Vec::new();
match parse_tls_raw_record(buf) {
Ok((_, ref r)) => {
match parse_tls_record_with_header(r.data, &r.hdr) {
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) => {
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 {
match *ext {
tls_parser::TlsExtension::SNI(ref v) => {
if let tls_parser::TlsExtension::SNI(ref v) = *ext {
for &(t, sni) in v {
match String::from_utf8(sni.to_vec()) {
Ok(s) => {
@ -33,8 +31,6 @@ pub fn get_sni(buf: &[u8]) -> Vec<String> {
}
}
}
_ => {}
}
}
}
Err(e) => {
@ -42,17 +38,12 @@ pub fn get_sni(buf: &[u8]) -> Vec<String> {
}
}
}
_ => {}
},
_ => {}
}
}
}
Err(err) => {
warn!("Failed to parse TLS: {}", err);
}
}
}
},
Err(err) => {
warn!("Failed to parse TLS: {}", err);
}