chiark / gitweb /
make route_packet async
[hippotat.git] / src / bin / server.rs
index a8cb59012735fd445b412cc8fc9534028d0d7f75..57f9bc75caa6b813365234c4f9c8e79f85a53c80 100644 (file)
@@ -24,7 +24,7 @@ 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
@@ -41,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>,
 }
@@ -57,13 +57,23 @@ struct WebResponse {
 type WebResponseData = Vec<u8>;
 
 #[throws(PacketError)]
-pub fn route_packet(_global: &Global,
-                    conn: &str, link: &dyn Display,
-                    packet: RoutedPacket, daddr: IpAddr)
+pub async fn route_packet(global: &Global,
+                          conn: &str, link: &(dyn Display + Sync),
+                          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(
@@ -211,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 {
@@ -268,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)]
@@ -279,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)
@@ -391,7 +401,7 @@ async fn run_client(global: Arc<Global>,
               &global, &conn, &ic.link.client, daddr,packet
             ),
               |e| Ok::<_,SlipFramesError<_>>({ warnings.add(&e)?; })
-            )?;
+            ).await?;
           }
 
           let oi = OutstandingInner {