aboutsummaryrefslogtreecommitdiff
path: root/src/diplonat.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2020-05-22 18:41:13 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2020-05-22 18:41:13 +0200
commite1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554 (patch)
treed1e891b87684c7907ff1245ebd5ad403804f6fd9 /src/diplonat.rs
parentdeeecd93e1fc5545e6e0280d1799436638e84a38 (diff)
downloaddiplonat-e1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554.tar.gz
diplonat-e1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554.zip
WIP software
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(());
}
}