From 86b55e5820e6e35a899739c6072560cf9cc725f4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 17 Aug 2021 01:31:42 +0100 Subject: [PATCH] server: route wip Signed-off-by: Ian Jackson --- src/bin/server.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 57f9bc7..ec55bda 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -14,6 +14,7 @@ pub struct Opts { } const METADATA_MAX_LEN: usize = MAX_OVERHEAD; +const INTERNAL_QUEUE: usize = 15; // xxx: config #[derive(Debug)] pub struct Global { @@ -25,6 +26,7 @@ pub struct Global { pub struct Client { ic: Arc, web: mpsc::Sender, + route: mpsc::Sender, } pub type RoutedPacket = Box<[u8]>; // not MIME data @@ -274,7 +276,8 @@ async fn handle( #[allow(unused_mut)] // xxx async fn run_client(global: Arc, ic: Arc, - mut web: mpsc::Receiver) + mut web: mpsc::Receiver, + mut routed: mpsc::Receiver) -> Result { struct Outstanding { @@ -441,19 +444,26 @@ async fn main() { let ics = ics.into_iter().map(Arc::new).collect_vec(); let (client_handles_send, client_handles_recv) = ics.iter() - .map(|_ic| mpsc::channel( - 5 // xxx should me max_requests_outstanding but that's - // marked client-only so needs rework - )).unzip::<_,_,Vec<_>,Vec<_>>(); + .map(|_ic| { + let (web_send, web_recv) = mpsc::channel( + 5 // xxx should me max_requests_outstanding but that's + // marked client-only so needs rework + ); + let (route_send, route_recv) = mpsc::channel( + INTERNAL_QUEUE + ); + ((web_send, route_send), (web_recv, route_recv)) + }).unzip::<_,_,Vec<_>,Vec<_>>(); let all_clients = izip!( &ics, client_handles_send, - ).map(|(ic, web_send)| { + ).map(|(ic, (web_send, route_send))| { (ic.link.client, Client { ic: ic.clone(), web: web_send, + route: route_send, }) }).collect(); @@ -462,14 +472,15 @@ async fn main() { all_clients, }); - for (ic, web_recv) in izip!( + for (ic, (web_recv, route_recv)) in izip!( ics, client_handles_recv, ) { let global_ = global.clone(); let ic_ = ic.clone(); tasks.push((tokio::spawn(async move { - run_client(global_, ic_, web_recv).await.void_unwrap_err() + run_client(global_, ic_, web_recv, route_recv) + .await.void_unwrap_err() }), format!("client {}", &ic))); } -- 2.30.2