diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-21 22:25:33 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-21 22:25:33 +0200 |
commit | 8c43611eb5bbaeb42f19da8d8ed521df208bfada (patch) | |
tree | c207e950744f451424e139e97aaf852c2d8ff949 /src/diplonat.rs | |
parent | 4da459ce8ba49f98084a8ce32f600470ff883ec5 (diff) | |
download | diplonat-8c43611eb5bbaeb42f19da8d8ed521df208bfada.tar.gz diplonat-8c43611eb5bbaeb42f19da8d8ed521df208bfada.zip |
Broken Diplonat
Diffstat (limited to 'src/diplonat.rs')
-rw-r--r-- | src/diplonat.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/diplonat.rs b/src/diplonat.rs index a53a19e..01bd994 100644 --- a/src/diplonat.rs +++ b/src/diplonat.rs @@ -1,27 +1,41 @@ use anyhow::{Result, Context}; use tokio::sync::broadcast; use futures::future::try_join_all; -use crate::*; +use log::*; +use std::cell::Cell; + +use crate::environment_adapter::*; +use crate::igd_adapter::*; +use crate::node_state::*; pub struct Diplonat<'a> { - pub config: config::DiplonatConfig, - pub gateway: igd::aio::Gateway, pub notif: broadcast::Sender<()>, - pub public_ports: &'a[u16], - adapters: &'a[&'a dyn adapter::Adapter] + 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 { - config: config::load_env().context("Unable to read configuration from environment")?, - gateway: gw::get_gateway().await?, notif: tx, - public_ports: &[110, 111, 112], - adapters: &[] + 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); } |