diff --git a/src/bin/chorus.rs b/src/bin/chorus.rs index c10450a..2deedd3 100644 --- a/src/bin/chorus.rs +++ b/src/bin/chorus.rs @@ -3,7 +3,6 @@ use chorus::counting_stream::CountingStream; use chorus::error::Error; use chorus::globals::GLOBALS; use chorus::ip::HashedPeer; -use chorus::FullStream; use std::env; use std::fs::OpenOptions; use std::io::Read; @@ -109,10 +108,13 @@ async fn main() -> Result<(), Error> { let maybe_tls_acceptor_clone = maybe_tls_acceptor.clone(); tokio::spawn(async move { - let stream: Box = match maybe_tls_acceptor_clone { + match maybe_tls_acceptor_clone { Some(tls_acceptor) => { match tls_acceptor.accept(counting_stream).await { - Ok(stream) => Box::new(stream), + Ok(stream) => { + let io = hyper_util::rt::TokioIo::new(stream); + chorus::serve(io, hashed_peer).await; + }, Err(e) => { log::error!( target: "Client", @@ -122,9 +124,11 @@ async fn main() -> Result<(), Error> { } } }, - None => Box::new(counting_stream) + None => { + let io = hyper_util::rt::TokioIo::new(counting_stream); + chorus::serve(io, hashed_peer).await; + } }; - chorus::serve(stream, hashed_peer).await; }); } }; diff --git a/src/lib.rs b/src/lib.rs index 17f9c9c..1b175ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ pub mod tls; pub mod web; use crate::config::{Config, FriendlyConfig}; -use crate::counting_stream::CountingStream; use crate::error::{ChorusError, Error}; use crate::globals::GLOBALS; use crate::ip::{HashedIp, HashedPeer, IpData, SessionExit}; @@ -39,25 +38,22 @@ use std::sync::atomic::Ordering; use std::time::Duration; use textnonce::TextNonce; use tokio::io::{AsyncRead, AsyncWrite}; -use tokio::net::TcpStream; use tokio::time::Instant; -use tokio_rustls::server::TlsStream; use tungstenite::protocol::WebSocketConfig; use tungstenite::Message; -pub trait FullStream: AsyncRead + AsyncWrite + Unpin + Send {} -impl FullStream for CountingStream {} -impl FullStream for TlsStream> {} - /// Serve a single network connection -pub async fn serve(stream: Box, peer: HashedPeer) { +pub async fn serve(stream: TokioIo, peer: HashedPeer) +where + T: AsyncRead + AsyncWrite + Unpin + Send + 'static, +{ // Serve the network stream with our http server and our ChorusService let service = ChorusService { peer }; - let io = hyper_util::rt::TokioIo::new(stream); - let http1builder = GLOBALS.http1builder.clone(); - let connection = http1builder.serve_connection(io, service).with_upgrades(); + let connection = http1builder + .serve_connection(stream, service) + .with_upgrades(); // If our service exits with an error, log the error if let Err(he) = connection.await {