aboutsummaryrefslogtreecommitdiff
path: root/src/diplonat.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/diplonat.rs')
-rw-r--r--src/diplonat.rs46
1 files changed, 15 insertions, 31 deletions
diff --git a/src/diplonat.rs b/src/diplonat.rs
index 01bd994..a4cb787 100644
--- a/src/diplonat.rs
+++ b/src/diplonat.rs
@@ -1,45 +1,29 @@
-use anyhow::{Result, Context};
-use tokio::sync::broadcast;
+use anyhow::Result;
use futures::future::try_join_all;
use log::*;
-use std::cell::Cell;
+use crate::consul_actor::ConsulActor;
+use crate::environment::Environment;
-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>,
+pub struct Diplonat {
+ consul: ConsulActor
}
-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,
+impl Diplonat {
+ pub async fn new() -> Result<Self> {
+ let env = Environment::new()?;
- env: EnvironmentAdapter::new(&ns, &tx).await?,
- igd: IgdAdapter::new(&ns, &tx).await?
+ let ctx = Self {
+ consul: ConsulActor::new(&env.consul_url, &env.consul_node_name)
};
- 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<()> {
+ pub async fn listen(&mut self) -> Result<()> {
+ try_join_all(vec![
+ self.consul.listen()
+ ]).await?;
+
return Ok(());
}
}