diff options
author | Alex Auvolat <alex@adnab.me> | 2023-04-20 14:14:30 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-04-20 14:14:30 +0200 |
commit | 48da5b61acf9edd582be5cecfdae58f63bd4527e (patch) | |
tree | 41fa7c00be62130386bf0c00516163620c7231a9 /src/diplonat.rs | |
parent | 21ab77b8288630c5f39a30b098c6a3888df622a1 (diff) | |
download | diplonat-48da5b61acf9edd582be5cecfdae58f63bd4527e.tar.gz diplonat-48da5b61acf9edd582be5cecfdae58f63bd4527e.zip |
better error handling
Diffstat (limited to 'src/diplonat.rs')
-rw-r--r-- | src/diplonat.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/diplonat.rs b/src/diplonat.rs index a94a6f8..96bac3b 100644 --- a/src/diplonat.rs +++ b/src/diplonat.rs @@ -1,4 +1,5 @@ -use anyhow::Result; +use anyhow::{Context, Result}; +use futures::future::FutureExt; use tokio::try_join; use crate::{ @@ -15,7 +16,7 @@ pub struct Diplonat { impl Diplonat { pub async fn new() -> Result<Self> { - let rt_cfg = ConfigOpts::from_env()?; + let rt_cfg = ConfigOpts::from_env().context("Parse configuration")?; println!("{:#?}", rt_cfg); let ca = ConsulActor::new(&rt_cfg.consul, &rt_cfg.consul.node_name); @@ -25,7 +26,8 @@ impl Diplonat { rt_cfg.firewall.refresh_time, &ca.rx_open_ports, ) - .await?; + .await + .context("Setup fireall actor")?; let ia = match rt_cfg.igd { Some(igdc) => Some( @@ -35,7 +37,8 @@ impl Diplonat { igdc.expiration_time, &ca.rx_open_ports, ) - .await?, + .await + .context("Setup IGD actor")?, ), None => None, }; @@ -56,16 +59,18 @@ impl Diplonat { let igd_opt = &mut self.igd; try_join!( - self.consul.listen(), + self.consul.listen().map(|x| x.context("Run consul actor")), async { if let Some(igd) = igd_opt { - igd.listen().await + igd.listen().await.context("Run IGD actor") } else { Ok(()) } }, - self.firewall.listen(), - self.stun.listen(), + self.firewall + .listen() + .map(|x| x.context("Run firewall actor")), + self.stun.listen().map(|x| x.context("Run STUN actor")), )?; Ok(()) |