chiark / gitweb /
client: wip code
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 29 Jul 2021 00:03:22 +0000 (01:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 29 Jul 2021 00:03:22 +0000 (01:03 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/lib.rs
src/prelude.rs
src/reporter.rs [new file with mode: 0644]

index c7b1f450dbb9bd0b6d923187b240cd520ec2aa9f..78f0cba56dd0f1459c0fd5b60befe0c7d476a433 100644 (file)
@@ -14,9 +14,12 @@ struct Client {
 #[allow(unused_variables)] // xxx
 async fn run_client<C>(ic: InstanceConfig, hclient: Arc<hyper::Client<C>>)
                        -> Result<Void, AE>
+where C: hyper::client::connect::Connect + Clone + Send + Sync,
 {
   debug!("{}: config: {:?}", &ic, &ic);
 
+  let mut reporter = Reporter { };
+
   let mut ipif = tokio::process::Command::new("sh")
     .args(&["-c", &ic.ipif])
     .stdin (process::Stdio::piped())
@@ -68,7 +71,7 @@ async fn run_client<C>(ic: InstanceConfig, hclient: Arc<hyper::Client<C>>)
               }
               upbound_total = new_upbound_total;
               upbound.push(packet);
-              // we rely on `next_segment` being cancellation-safe,
+              // we rely oin `next_segment` being cancellation-safe,
               // which isn't documented as true but seems reasonably safe
               pin!{ let next_segment = tx_stream.next_segment(); }
               to_process = match poll!(next_segment) {
@@ -89,13 +92,13 @@ async fn run_client<C>(ic: InstanceConfig, hclient: Arc<hyper::Client<C>>)
             ).context("construct request")?;
 
           let resp = hclient.request(req);
-          let fut = Box::pin(tokio::timeout(
+          let fut = Box::pin(tokio::time::timeout(
             ic.http_timeout,
             async {
               let r = async {
                 let resp = resp.await;
                 if ! resp.status().is_success() {
-                  throw!("HTTP error status {}: {}", &resp.status());
+                  throw!(anyhow!("HTTP error status {}", &resp.status()));
                 }
                 let resp = resp.into_body();
                 // xxx: some size limit to avoid mallocing the universe
@@ -112,7 +115,7 @@ async fn run_client<C>(ic: InstanceConfig, hclient: Arc<hyper::Client<C>>)
           reqs.push(fut);
         }
 
-        (got, goti, _) = future::select_all(&mut reqs)
+        (got, goti, _) = future::select_all(&mut reqs) =>
         {
           reqs.swap_remove(goti);
           if let Some(got) = reporter.report(got) {
index 1bdd108e231ccd60b2f3a26cb23382f3fd892dd2..562f1bc05c29266ae3694244ac2912596ee90eab 100644 (file)
@@ -15,5 +15,6 @@ pub mod prelude;
 
 pub mod config;
 pub mod slip;
+pub mod reporter;
 pub mod types;
 pub mod utils;
index 2c961190307232696c00a41e1a7c463e5ef11abf..08cc6c595a3dcf6c7d3ac2b786bdc4a26e358beb 100644 (file)
@@ -39,6 +39,7 @@ pub use void::{self, Void, ResultVoidExt, ResultVoidErrExt};
 
 pub use crate::config::{self, InstanceConfig, u32Ext as _};
 pub use crate::utils::*;
+pub use crate::reporter::*;
 pub use crate::types::*;
 pub use crate::slip;
 
diff --git a/src/reporter.rs b/src/reporter.rs
new file mode 100644 (file)
index 0000000..b87417b
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2021 Ian Jackson and contributors to Hippotat
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+use crate::prelude::*;
+
+pub struct Reporter {
+}
+
+impl Reporter {
+  pub fn report<T>(r: Result<T,AE>) -> Option<T> {
+    match r {
+      Ok(t) => {
+        // xxx something something success
+        Some(t)
+      },
+      Err(e) => {
+        // xxx something something error
+        error!("ERRO {:?}R", e);
+        None
+      },
+    }
+  }
+}