aboutsummaryrefslogblamecommitdiff
path: root/src/diplonat.rs
blob: 798b77927766332ed4c489144ed5accc45e70dd4 (plain) (tree)
1
2
3
4
5
6
7
8
9
                   
                    
                                     
                               
                                    
                                   
 
                     
                      

                         

 


                                      
                                                                      





                           
 




                                
                    
                 

                  
      
 

                   
 
                                                

                           

                            
       
 
                  
   
 
use anyhow::Result;
use tokio::try_join;
use crate::consul_actor::ConsulActor;
use crate::igd_actor::IgdActor;
use crate::environment::Environment;
use crate::fw_actor::FirewallActor;

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

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(
      &env.private_ip, 
      env.refresh_time, 
      env.expiration_time, 
      &ca.rx_open_ports
    ).await?;

    let fw = FirewallActor::new(
        env.refresh_time,
        &ca.rx_open_ports
    ).await?;

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

    return Ok(ctx);
  }

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

    return Ok(());
  }
}