diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-21 17:51:30 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-21 17:51:30 +0200 |
commit | 4da459ce8ba49f98084a8ce32f600470ff883ec5 (patch) | |
tree | 608f9e93ca740f76ab3d751103f99e8c9c991e32 /src/diplonat.rs | |
parent | feadc844c060ff0879d8d547807147ae2213fd13 (diff) | |
download | diplonat-4da459ce8ba49f98084a8ce32f600470ff883ec5.tar.gz diplonat-4da459ce8ba49f98084a8ce32f600470ff883ec5.zip |
Working on logic
Diffstat (limited to 'src/diplonat.rs')
-rw-r--r-- | src/diplonat.rs | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/src/diplonat.rs b/src/diplonat.rs index 9062dd7..a53a19e 100644 --- a/src/diplonat.rs +++ b/src/diplonat.rs @@ -1,45 +1,31 @@ use anyhow::{Result, Context}; -use tokio::try_join; +use tokio::sync::broadcast; +use futures::future::try_join_all; use crate::*; -pub struct Diplonat { +pub struct Diplonat<'a> { pub config: config::DiplonatConfig, - pub gateway: igd::aio::Gateway + pub gateway: igd::aio::Gateway, + pub notif: broadcast::Sender<()>, + pub public_ports: &'a[u16], + adapters: &'a[&'a dyn adapter::Adapter] } -impl Diplonat { - pub async fn new() -> Result<Self> { - let ctx = Self { +impl<'a> Diplonat<'a> { + pub async fn new() -> Result<Diplonat<'a>> { + let (tx, _) = broadcast::channel(1); + let ctx = Diplonat { config: config::load_env().context("Unable to read configuration from environment")?, - gateway: gw::get_gateway().await? + gateway: gw::get_gateway().await?, + notif: tx, + public_ports: &[110, 111, 112], + adapters: &[] }; return Ok(ctx); } - // Action sinks - pub async fn consul_catalog(&self) -> Result<()> { - info!("Consul catalog loop started"); - return Ok(()); - } - pub async fn control_loop(&self) -> Result<()> { - info!("Control loop started"); - return Ok(()); - } - - // Action taps - pub async fn igd(&self) -> Result<()> { - info!("IGD loop started"); - return Ok(()); - } - // @TODO: implement netfilter, dns - pub async fn listen(&self) -> Result<()> { - try_join!( - self.consul_catalog(), - self.control_loop(), - self.igd() - )?; return Ok(()); } } |