From 6b181a6bfdc3556cdf40d52268c26ff67caa3714 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 15 Nov 2020 01:10:51 +0100 Subject: [PATCH] Do not fail on TLS errors. Pulled from https://github.com/ctz/hyper-rustls/pull/114/files. --- multipass.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/multipass.rs b/multipass.rs index d3187aa..629d07e 100644 --- a/multipass.rs +++ b/multipass.rs @@ -7,10 +7,7 @@ extern crate simple_error; use pcsc::*; use core::task::{Context, Poll}; -use futures_util::{ - future::TryFutureExt, - stream::{Stream, StreamExt, TryStreamExt}, -}; +use futures_util::stream::{Stream, StreamExt}; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Method, Request, Response, Server, StatusCode}; use hyper::header::HeaderValue; @@ -64,18 +61,25 @@ async fn run_server() -> Result<(), Box> { // Create a TCP listener via tokio. let mut tcp = TcpListener::bind(&addr).await?; - let tls_acceptor = TlsAcceptor::from(tls_cfg); + let tls_acceptor = &TlsAcceptor::from(tls_cfg); // Prepare a long-running future stream to accept and serve cients. let incoming_tls_stream = tcp .incoming() - .map_err(|e| error(format!("Incoming failed: {:?}", e))) - .and_then(move |s| { - tls_acceptor.accept(s).map_err(|e| { - println!("[!] Voluntary server halt due to client-connection error..."); - // Errors could be handled here, instead of server aborting. - // println!("TLS Error: {:?}", e); - error(format!("TLS Error: {:?}", e)) - }) + .filter_map(move |s| async move { + let client = match s { + Ok(x) => x, + Err(e) => { + println!("Failed to accept a client, should probably back off"); + return Some(Err(e)); + } + }; + match tls_acceptor.accept(client).await { + Ok(x) => Some(Ok(x)), + Err(e) => { + println!("[!] Client connection error: {}", e); + None + } + } }) .boxed(); -- 2.39.2