From 4da459ce8ba49f98084a8ce32f600470ff883ec5 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 21 May 2020 17:51:30 +0200 Subject: Working on logic --- src/adapter.rs | 7 +++++++ src/consul.rs | 0 src/diplonat.rs | 44 +++++++++++++++----------------------------- src/igd_adapter.rs | 12 ++++++++++++ src/main.rs | 2 ++ 5 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 src/adapter.rs create mode 100644 src/consul.rs create mode 100644 src/igd_adapter.rs (limited to 'src') 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 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 { - let ctx = Self { +impl<'a> Diplonat<'a> { + pub async fn new() -> Result> { + 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; -- cgit v1.2.3