chiark / gitweb /
wip server ipif
[hippotat.git] / server / server.rs
index 022d00bafc6c214b9c670aef5b91bb9375136e04..b8cedaf9e8cf457597deb5ac2cfe934a22970a68 100644 (file)
@@ -4,11 +4,12 @@
 
 use hippotat::prelude::*;
 
-mod sclient;
+mod suser;
+mod slocal;
 mod sweb;
 
 pub use sweb::{WebRequest, WebResponse};
-pub use sclient::Client;
+pub use suser::User;
 
 #[derive(StructOpt,Debug)]
 pub struct Opts {
@@ -25,7 +26,8 @@ pub const INTERNAL_QUEUE: usize = 15; // xxx: config
 #[derive(Debug)]
 pub struct Global {
   config: config::InstanceConfigGlobal,
-  all_clients: HashMap<ClientName, Client>,
+  local_rx: mpsc::Sender<RoutedPacket>,
+  all_clients: HashMap<ClientName, User>,
 }
 
 pub type RoutedPacket = Box<[u8]>; // not MIME data
@@ -71,7 +73,7 @@ async fn main() {
     String,
   )> = vec![];
 
-  let (global, ipif) = config::startup(
+  let global = config::startup(
     "hippotatd", LinkEnd::Server,
     &opts.config, &opts.log, |ics|
   {
@@ -97,15 +99,20 @@ async fn main() {
       client_handles_send,
     ).map(|(ic, (web_send, route_send))| {
       (ic.link.client,
-       Client {
+       User {
          ic: ic.clone(),
          web: web_send,
          route: route_send,
        })
     }).collect();
 
+    let (local_rx_send, local_tx_recv) = mpsc::channel(
+      50 // xxx configurable?
+    );
+
     let global = Arc::new(Global {
       config: global_config,
+      local_rx: local_rx_send,
       all_clients,
     });
 
@@ -116,7 +123,7 @@ async fn main() {
       let global_ = global.clone();
       let ic_ = ic.clone();
       tasks.push((tokio::spawn(async move {
-        sclient::run(global_, ic_, web_recv, route_recv)
+        suser::run(global_, ic_, web_recv, route_recv)
           .await.void_unwrap_err()
       }), format!("client {}", &ic)));
     }
@@ -147,8 +154,15 @@ async fn main() {
       });
       tasks.push((task, format!("http server {}", addr)));
     }
-    
-    Ok((global, ipif))
+
+    let global_ = global.clone();
+    let ipif = tokio::task::spawn(async move {
+      slocal::run(global_, local_tx_recv, ipif).await
+        .void_unwrap_err()
+    });
+    tasks.push((ipif, format!("ipif")));
+
+    Ok(global)
   });
 
   let died = future::select_all(
@@ -156,7 +170,5 @@ async fn main() {
   ).await;
   error!("xxx {:?}", &died);
 
-  ipif.quitting(None).await;
-
   dbg!(global);
 }