diff options
Diffstat (limited to 'src/diplonat.rs')
-rw-r--r-- | src/diplonat.rs | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/diplonat.rs b/src/diplonat.rs index 4252f43..604227c 100644 --- a/src/diplonat.rs +++ b/src/diplonat.rs @@ -2,54 +2,54 @@ use anyhow::Result; use tokio::try_join; use crate::{ - config::ConfigOpts, consul_actor::ConsulActor, fw_actor::FirewallActor, igd_actor::IgdActor, - stun_actor::StunActor, + config::ConfigOpts, consul_actor::ConsulActor, fw_actor::FirewallActor, igd_actor::IgdActor, + stun_actor::StunActor, }; pub struct Diplonat { - consul: ConsulActor, - firewall: FirewallActor, - igd: IgdActor, - stun: StunActor, + consul: ConsulActor, + firewall: FirewallActor, + igd: IgdActor, + stun: StunActor, } impl Diplonat { - pub async fn new() -> Result<Self> { - let rt_cfg = ConfigOpts::from_env()?; - println!("{:#?}", rt_cfg); - - let ca = ConsulActor::new(&rt_cfg.consul, &rt_cfg.consul.node_name); - - let fw = FirewallActor::new(rt_cfg.firewall.refresh_time, &ca.rx_open_ports).await?; - - let ia = IgdActor::new( - rt_cfg.igd.private_ip.as_ref().map(String::as_str), - rt_cfg.igd.refresh_time, - rt_cfg.igd.expiration_time, - &ca.rx_open_ports, - ) - .await?; - - let sa = StunActor::new(&rt_cfg.consul, &rt_cfg.stun, &rt_cfg.consul.node_name); - - let ctx = Self { - consul: ca, - igd: ia, - firewall: fw, - stun: sa, - }; - - Ok(ctx) - } - - pub async fn listen(&mut self) -> Result<()> { - try_join!( - self.consul.listen(), - self.igd.listen(), - self.firewall.listen(), - self.stun.listen(), - )?; - - Ok(()) - } + pub async fn new() -> Result<Self> { + let rt_cfg = ConfigOpts::from_env()?; + println!("{:#?}", rt_cfg); + + let ca = ConsulActor::new(&rt_cfg.consul, &rt_cfg.consul.node_name); + + let fw = FirewallActor::new(rt_cfg.firewall.refresh_time, &ca.rx_open_ports).await?; + + let ia = IgdActor::new( + rt_cfg.igd.private_ip.as_ref().map(String::as_str), + rt_cfg.igd.refresh_time, + rt_cfg.igd.expiration_time, + &ca.rx_open_ports, + ) + .await?; + + let sa = StunActor::new(&rt_cfg.consul, &rt_cfg.stun, &rt_cfg.consul.node_name); + + let ctx = Self { + consul: ca, + igd: ia, + firewall: fw, + stun: sa, + }; + + Ok(ctx) + } + + pub async fn listen(&mut self) -> Result<()> { + try_join!( + self.consul.listen(), + self.igd.listen(), + self.firewall.listen(), + self.stun.listen(), + )?; + + Ok(()) + } } |