aboutsummaryrefslogtreecommitdiff
path: root/src/diplonat.rs
blob: 565c567591e78ad59ad513ef13894d67f8c73a3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use anyhow::Result;
use log::*;
use tokio::try_join;
use crate::consul_actor::ConsulActor;
use crate::igd_actor::IgdActor;
use crate::environment::Environment;

pub struct Diplonat {
  consul: ConsulActor,
  igd: IgdActor
}

impl Diplonat {
  pub async fn new() -> Result<Self> {
    let env = Environment::new()?;
    let ca = ConsulActor::new(&env.consul_url, &env.consul_node_name);
    let ia = IgdActor::new(&ca.rx_open_ports).await?;

    let ctx = Self {
      consul: ca,
      igd: ia
    };

    return Ok(ctx);
  }

  pub async fn listen(&mut self) -> Result<()> {
    try_join!(
      self.consul.listen(),
      self.igd.listen()
    )?;

    return Ok(());
  }
}