chiark / gitweb /
wip client etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Jul 2021 12:30:45 +0000 (13:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Jul 2021 12:30:45 +0000 (13:30 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/config.rs
src/prelude.rs

index d7c8301d8c487affd4bc1838546b0782ee487504..cf16b37daafffd84fd9cb5f88925bbd173895345 100644 (file)
@@ -11,16 +11,45 @@ struct Client {
   rx_write_stream: something,
 }*/
 
-#[throws(AE)]
+#[allow(unused_variables)] // xxx
+async fn run_client<C>(ic: InstanceConfig, hclient: Arc<hyper::Client<C>>)
+                       -> Result<Void, AE>
+{
+  throw!(anyhow!("arrgh"));
+}
+
 #[tokio::main]
-async fn main() {
+async fn main() -> Result<(), AE> {
   let ics = config::read(LinkEnd::Client)?;
+  if ics.is_empty() { throw!(anyhow!("no associations with server(s)")); }
+
+  env_logger::init();
 
   let https = HttpsConnector::new();
-  let hclient = Client::builder().build::<_, hyper::Body>(https);
+  let hclient = hyper::Client::builder().build::<_, hyper::Body>(https);
+  let hclient = Arc::new(hclient);
 
-  let clients = ics.into_iter().map(|| run_client(ic));
-  
+  info!("starting");
+  let () = future::select_all(
+    ics.into_iter().map(|ic| Box::pin(async {
+      let assocname = ic.to_string();
+      info!("{} starting", &assocname);
+      let hclient = hclient.clone();
+      let join = task::spawn(async {
+        run_client(ic, hclient).await.void_unwrap_err()
+      });
+      match join.await {
+        Ok(e) => {
+          error!("{} failed: {:?}", &assocname, e);
+        },
+        Err(je) => {
+          error!("{} panicked!", &assocname);
+          panic::resume_unwind(je.into_panic());
+        },
+      }
+    }))
+  ).await.0;
 
-  eprintln!("{:#?}", &instances);
+  error!("quitting because one of your client connections crashed");
+  process::exit(16);
 }
index dea5bab0723b4450905d9f313a910d25ff01dfea..30e2c120f9c73c2b8e4fe61ee19da38e06121e9b 100644 (file)
@@ -191,6 +191,13 @@ impl FromStr for SectionName {
     SN::Link(LinkName { server, client })
   }
 }
+impl Display for InstanceConfig {
+  #[throws(fmt::Error)]
+  fn fmt(&self, f: &mut fmt::Formatter) {
+    write!(f, "[{} {}]", &self.server, &self.vaddr)?;
+  }
+}
+
 impl Display for SectionName {
   #[throws(fmt::Error)]
   fn fmt(&self, f: &mut fmt::Formatter) {
@@ -700,7 +707,7 @@ pub fn read(end: LinkEnd) -> Vec<InstanceConfig> {
       agg.read_extra(extra).context("extra config")?;
     }
 
-    eprintln!("GOT {:#?}", agg);
+    //eprintln!("GOT {:#?}", agg);
 
     Ok::<_,AE>(agg)
   })().context("read configuration")?;
index 7b02ea009896c1e770ac7c9820e0e7c1649d5180..7c7d099c4eb2d06a7ce4f9c9801cf0c83adc2924 100644 (file)
@@ -10,21 +10,27 @@ pub use std::io::{self, ErrorKind, Read as _};
 pub use std::mem;
 pub use std::net::{IpAddr, Ipv4Addr};
 pub use std::path::{Path, PathBuf};
+pub use std::panic;
+pub use std::process;
 pub use std::str::FromStr;
 pub use std::sync::Arc;
 
 pub use anyhow::{anyhow, Context};
 pub use extend::ext;
 pub use fehler::{throw, throws};
+pub use futures::future;
 pub use hyper::Uri;
+pub use hyper_tls::HttpsConnector;
 pub use ipnet::IpNet;
 pub use itertools::{iproduct, Itertools};
 pub use lazy_regex::regex_is_match;
+pub use log::{info, error};
 pub use structopt::StructOpt;
+pub use tokio::task;
 pub use tokio::time::Duration;
-pub use void::{self, Void};
+pub use void::{self, Void, ResultVoidExt, ResultVoidErrExt};
 
-pub use crate::config;
+pub use crate::config::{self, InstanceConfig};
 pub use crate::utils::*;
 pub use crate::types::*;