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 | |
parent | feadc844c060ff0879d8d547807147ae2213fd13 (diff) | |
download | diplonat-4da459ce8ba49f98084a8ce32f600470ff883ec5.tar.gz diplonat-4da459ce8ba49f98084a8ce32f600470ff883ec5.zip |
Working on logic
Diffstat (limited to 'src')
-rw-r--r-- | src/adapter.rs | 7 | ||||
-rw-r--r-- | src/consul.rs | 0 | ||||
-rw-r--r-- | src/diplonat.rs | 44 | ||||
-rw-r--r-- | src/igd_adapter.rs | 12 | ||||
-rw-r--r-- | src/main.rs | 2 |
5 files changed, 36 insertions, 29 deletions
diff --git a/src/adapter.rs b/src/adapter.rs new file mode 100644 index 0000000..567e1cd --- /dev/null +++ b/src/adapter.rs @@ -0,0 +1,7 @@ +use anyhow::Result; +use crate::*; + +pub trait Adapter { + fn new(&self, parent: &diplonat::Diplonat) -> Result<()>; + fn run(&self) -> Result<()>; +} diff --git a/src/consul.rs b/src/consul.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/consul.rs 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(()); } } diff --git a/src/igd_adapter.rs b/src/igd_adapter.rs new file mode 100644 index 0000000..3803d5f --- /dev/null +++ b/src/igd_adapter.rs @@ -0,0 +1,12 @@ +use crate::*; +use anyhow::Result; + +pub struct IgdAdapter {} +impl adapter::Adapter for IgdAdapter { + fn new(&self, parent: &diplonat::Diplonat) -> Result<()> { + return Ok(()); + } + fn run(&self) -> Result<()> { + return Ok(()); + } +} diff --git a/src/main.rs b/src/main.rs index c8a4b0a..c4d8c0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ mod diplonat; mod config; mod gw; +mod adapter; +mod igd_adapter; //use std::net::SocketAddrV4; //use std::collections::HashMap; |