chiark / gitweb /
use tokio::sync import aliases
[hippotat.git] / src / bin / server.rs
index 1cc0660414a101f0caa6a2a4e657e2380f4ddc9c..a45bec6d92e4351bd75f3484332925527e1302d1 100644 (file)
@@ -24,9 +24,11 @@ pub struct Global {
 #[derive(Debug)]
 pub struct Client {
   ic: Arc<InstanceConfig>,
-  web: tokio::sync::mpsc::Sender<WebRequest>,
+  web: mpsc::Sender<WebRequest>,
 }
 
+pub type RoutedPacket = Box<[u8]>; // not MIME data
+
 /// Sent from hyper worker pool task to client task
 #[allow(dead_code)] // xxx
 #[derive(Debug)]
@@ -39,7 +41,7 @@ struct WebRequest {
   length_hint: usize,
   body: hyper::body::Body,
   boundary_finder: multipart::BoundaryFinder,
-  reply_to: tokio::sync::oneshot::Sender<WebResponse>,
+  reply_to: oneshot::Sender<WebResponse>,
   warnings: Warnings,
   conn: Arc<String>,
 }
@@ -55,13 +57,23 @@ struct WebResponse {
 type WebResponseData = Vec<u8>;
 
 #[throws(PacketError)]
-pub fn route_packet(_global: &Global,
+pub fn route_packet(global: &Global,
                     conn: &str, link: &dyn Display,
-                    packet: Box<[u8]>, daddr: IpAddr)
+                    packet: RoutedPacket, daddr: IpAddr)
 {
-  // xxx
-  trace!("{} {} discarding packet daddr={:?} len={}",
-         conn, link, daddr, packet.len());
+  let c = &global.config;
+  let trace = |how| trace!("{} {} route {} daddr={:?} len={}",
+                           conn, link, how, daddr, packet.len());
+
+  if daddr == c.vaddr || ! c.vnetwork.iter().any(|n| n.contains(&daddr)) {
+    trace("ipif inbound xxx discarding");
+  } else if daddr == c.vrelay {
+    trace("discard (relay)");
+  } else if let Some(_client) = global.all_clients.get(&ClientName(daddr)) {
+    trace("ipif route xxx discarding");
+  } else {
+    trace("discard (no client)");
+  }
 }
 
 async fn handle(
@@ -209,7 +221,7 @@ async fn handle(
     //eprintln!("boundary={:?} start={} name={:?} client={}",
     // boundary, start, &comp.name, &client.ic);
 
-    let (reply_to, reply_recv) = tokio::sync::oneshot::channel();
+    let (reply_to, reply_recv) = oneshot::channel();
     trace!("{} {} request, Content-Length={}",
            &conn, &client_name, length_hint);
     let wreq = WebRequest {
@@ -266,7 +278,7 @@ async fn run_client(global: Arc<Global>,
                     -> Result<Void, AE>
 {
   struct Outstanding {
-    reply_to: tokio::sync::oneshot::Sender<WebResponse>,
+    reply_to: oneshot::Sender<WebResponse>,
     oi: OutstandingInner,
   }
   #[derive(Debug)]
@@ -277,7 +289,7 @@ async fn run_client(global: Arc<Global>,
   let  downbound: VecDeque<(/*xxx*/)> = default();
 
   let try_send_response = |
-    reply_to: tokio::sync::oneshot::Sender<WebResponse>,
+    reply_to: oneshot::Sender<WebResponse>,
     response: WebResponse
   | {
     reply_to.send(response)