diff options
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); } |