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

                                  





                                  
 
                         
                                   



                             

 


                                              


                                                       
                        
                



                                                    
      
 





                                                                

                   
 
                                            
                  
   
 
use anyhow::{Result, Context};
use tokio::sync::broadcast;
use futures::future::try_join_all;
use log::*;
use std::cell::Cell;

use crate::environment_adapter::*;
use crate::igd_adapter::*;
use crate::node_state::*;

pub struct Diplonat<'a> {
  pub notif: broadcast::Sender<()>,
  pub state: Cell<NodeState>,

  env: EnvironmentAdapter,
  igd: IgdAdapter<'a>,
}

impl<'a> Diplonat<'a> {
  pub async fn new() -> Result<Diplonat<'a>> {
    let (tx, _) = broadcast::channel(1);
    let ns = Cell::new(NodeState::new());

    // we deliberately choose to init one after another
    let ctx = Diplonat {
      notif: tx,
      state: ns,

      env: EnvironmentAdapter::new(&ns, &tx).await?,
      igd: IgdAdapter::new(&ns, &tx).await?
    };

    info!("Consul URL: {:#?}", ns.consul_url);
    info!("Consul node name: {:#?}", ns.consul_node_name);
    info!("Private IP address: {:#?}", ns.private_ip);
    info!("Refresh time: {:#?} seconds", ns.refresh_time);
    info!("Expiration time: {:#?} seconds", ns.expiration_time);

    return Ok(ctx);
  }

  pub async fn listen(&self) -> Result<()> {
    return Ok(());
  }
}