chiark / gitweb /
response plumbing
[hippotat.git] / server / server.rs
index cfceef6e2783ca7913285b1de42169aa49186392..dcadd54118f83b4b5124579e5da20650fb25d07c 100644 (file)
@@ -8,7 +8,7 @@ mod suser;
 mod slocal;
 mod sweb;
 
-pub use sweb::{WebRequest, WebResponse};
+pub use sweb::{WebRequest, WebResponse, WebResponseBody};
 pub use suser::User;
 
 #[derive(StructOpt,Debug)]
@@ -32,47 +32,62 @@ pub struct Global {
 
 pub struct RoutedPacket {
   pub data: RoutedPacketData,
-  pub source: Option<ClientName>, // for eh, tracing, etc.
+//  pub source: Option<ClientName>, // for eh, tracing, etc.
 }
 
 // not MIME data, valid SLIP (checked)
 pub type RoutedPacketData = Box<[u8]>;
 
-#[throws(PacketError)]
+// loop prevention
+// we don't decrement the ttl (naughty) but loops cannot arise
+// because only the server has any routing code, and server
+// has no internal loops, so worst case is
+//  client if -> client -> server -> client' -> client if'
+// and the ifs will decrement the ttl.
+mod may_route {
+  #[derive(Clone,Debug)]
+  pub struct MayRoute(());
+  impl MayRoute {
+    pub fn came_from_outside_hippotatd() -> Self { Self(()) }
+  }
+}
+pub use may_route::MayRoute;
+
 pub async fn route_packet(global: &Global,
-                          conn: &str, source: Option<&ClientName>,
-                          packet: RoutedPacketData, daddr: IpAddr)
+                          transport_conn: &str, source: Option<&ClientName>,
+                          packet: RoutedPacketData, daddr: IpAddr,
+                          _may_route: MayRoute)
 {
   let c = &global.config;
   let len = packet.len();
   let trace = |how: &str, why: &str| {
-    trace!("{} {} {} {} {:?} len={}",
-           conn,
+    trace!("{} to={:?} came=={} user={} len={} {}",
+           how, daddr, transport_conn,
            match source {
              Some(s) => (s as &dyn Display),
              None => &"local",
            },
-           how, why, daddr, len);
+           len, why);
   };
 
   let (dest, why) =
     if daddr == c.vaddr || ! c.vnetwork.iter().any(|n| n.contains(&daddr)) {
-      (None, "ipif-inbound-xxx")
+      (Some(&global.local_rx), "via=local")
     } else if daddr == c.vrelay {
-      (None, "vrelay")
+      (None, " vrelay")
     } else if let Some(client) = global.all_clients.get(&ClientName(daddr)) {
-      (Some(&client.route), "client")
+      (Some(&client.route), "via=client")
     } else {
       (None, "no-client")
     };
 
   let dest = if let Some(d) = dest { d } else {
-    trace("discard", why); return;
+    trace("discard ", why); return;
   };
 
   let packet = RoutedPacket {
     data: packet,
-    source: source.cloned(),
+//    source: source.cloned(),
   };
   match dest.send(packet).await {
     Ok(()) => trace("forward", why),