diff --git a/src/bin/chorus.rs b/src/bin/chorus.rs index 207a8fb..c10450a 100644 --- a/src/bin/chorus.rs +++ b/src/bin/chorus.rs @@ -124,18 +124,8 @@ async fn main() -> Result<(), Error> { }, None => Box::new(counting_stream) }; - if let Err(e) = chorus::serve(stream, hashed_peer).await { - log::error!( - target: "Client", - "{}: {}", hashed_peer, e - ); - } + chorus::serve(stream, hashed_peer).await; }); - - //Err(e) => log::error!( - //target: "Client", - //"{}: {}", hashed_peer, e - //), } }; } diff --git a/src/globals.rs b/src/globals.rs index 065d763..def9f68 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -1,7 +1,6 @@ use crate::config::Config; use crate::ip::HashedIp; use dashmap::DashMap; -use hyper::server::conn::Http; use lazy_static::lazy_static; use parking_lot::RwLock; use pocket_db::Store; @@ -17,7 +16,6 @@ pub struct Globals { pub bytes_outbound: AtomicU64, pub config: RwLock, pub store: OnceLock, - pub http_server: Http, pub rid: OnceLock, /// This is a broadcast channel where new incoming events are advertised by their offset. @@ -33,10 +31,6 @@ pub struct Globals { lazy_static! { pub static ref GLOBALS: Globals = { - let mut http_server = hyper::server::conn::Http::new(); - http_server.http1_only(true); - http_server.http1_keep_alive(true); - let (new_events, _) = tokio::sync::broadcast::channel(512); let (shutting_down, _) = tokio::sync::watch::channel(false); @@ -46,7 +40,6 @@ lazy_static! { bytes_outbound: AtomicU64::new(0), config: RwLock::new(Default::default()), store: OnceLock::new(), - http_server, rid: OnceLock::new(), new_events, num_connections: AtomicUsize::new(0), diff --git a/src/lib.rs b/src/lib.rs index 41ec5f7..cf5966d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,34 +48,42 @@ impl FullStream for CountingStream {} impl FullStream for TlsStream> {} /// Serve a single network connection -pub async fn serve(stream: Box, peer: HashedPeer) -> Result<(), Error> { +pub async fn serve(stream: Box, peer: HashedPeer) { // Serve the network stream with our http server and our HttpService let service = HttpService { peer }; - let connection = GLOBALS - .http_server + let mut http_server = hyper::server::conn::Http::new(); + http_server.http1_only(true); + http_server.http1_keep_alive(true); + let connection = http_server .serve_connection(stream, service) .with_upgrades(); - tokio::spawn(async move { - // If our service exits with an error, log the error - if let Err(he) = connection.await { - if let Some(src) = he.source() { - if &*format!("{}", src) == "Transport endpoint is not connected (os error 107)" { - // do nothing - } else { - // Print in detail - log::error!(target: "Client", "{}: {:?}", peer, src); - } - } else { - // Print in less detail - let e: Error = he.into(); - log::error!(target: "Client", "{}: {}", peer, e); - } - } - }); + /* hyper 1 + let mut http1builder = http1::Builder::new(); + http1builder.half_close(true); + http1builder.keep_alive(true); + http1builder.header_read_timeout(Duration::from_secs(5)); + let connection = http1builder + .serve_connection(stream, service) + .with_upgrades(); + */ - Ok(()) + // If our service exits with an error, log the error + if let Err(he) = connection.await { + if let Some(src) = he.source() { + if &*format!("{}", src) == "Transport endpoint is not connected (os error 107)" { + // do nothing + } else { + // Print in detail + log::error!(target: "Client", "{}: {:?}", peer, src); + } + } else { + // Print in less detail + let e: Error = he.into(); + log::error!(target: "Client", "{}: {}", peer, e); + } + } } // This is our per-connection HTTP service