From: Ian Jackson Date: Thu, 29 Jul 2021 00:03:22 +0000 (+0100) Subject: client: wip code X-Git-Tag: hippotat/1.0.0~433 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=8df13fb3b5e876a7887e8ce05e9ff35d0f886b94;p=hippotat.git client: wip code Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index c7b1f45..78f0cba 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -14,9 +14,12 @@ struct Client { #[allow(unused_variables)] // xxx async fn run_client(ic: InstanceConfig, hclient: Arc>) -> Result +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(ic: InstanceConfig, hclient: Arc>) } 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(ic: InstanceConfig, hclient: Arc>) ).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(ic: InstanceConfig, hclient: Arc>) 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) { diff --git a/src/lib.rs b/src/lib.rs index 1bdd108..562f1bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,5 +15,6 @@ pub mod prelude; pub mod config; pub mod slip; +pub mod reporter; pub mod types; pub mod utils; diff --git a/src/prelude.rs b/src/prelude.rs index 2c96119..08cc6c5 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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 index 0000000..b87417b --- /dev/null +++ b/src/reporter.rs @@ -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(r: Result) -> Option { + match r { + Ok(t) => { + // xxx something something success + Some(t) + }, + Err(e) => { + // xxx something something error + error!("ERRO {:?}R", e); + None + }, + } + } +}