Working on logic

This commit is contained in:
Quentin 2020-05-21 17:51:30 +02:00
parent feadc844c0
commit 4da459ce8b
8 changed files with 69 additions and 50 deletions

51
Cargo.lock generated
View file

@ -125,6 +125,7 @@ name = "diplonat"
version = "0.1.0"
dependencies = [
"anyhow",
"futures",
"igd",
"log",
"pretty_env_logger",
@ -206,9 +207,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780"
checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613"
dependencies = [
"futures-channel",
"futures-core",
@ -221,9 +222,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8"
checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5"
dependencies = [
"futures-core",
"futures-sink",
@ -231,15 +232,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a"
checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
[[package]]
name = "futures-executor"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba"
checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314"
dependencies = [
"futures-core",
"futures-task",
@ -248,15 +249,15 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6"
checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789"
[[package]]
name = "futures-macro"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7"
checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39"
dependencies = [
"proc-macro-hack",
"proc-macro2",
@ -266,21 +267,24 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6"
checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc"
[[package]]
name = "futures-task"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626"
dependencies = [
"once_cell",
]
[[package]]
name = "futures-util"
version = "0.3.4"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5"
checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6"
dependencies = [
"futures-channel",
"futures-core",
@ -289,6 +293,7 @@ dependencies = [
"futures-sink",
"futures-task",
"memchr",
"pin-project",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
@ -629,6 +634,12 @@ dependencies = [
"version_check 0.1.5",
]
[[package]]
name = "once_cell"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
[[package]]
name = "openssl"
version = "0.10.28"
@ -702,9 +713,9 @@ checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae"
[[package]]
name = "pin-utils"
version = "0.1.0-alpha.4"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"

View file

@ -12,5 +12,6 @@ igd = { version = "0.10.0", features = ["aio"] }
log = "0.4"
pretty_env_logger = "0.4"
tokio = "0.2.11"
futures = "0.3.5"
serde = "1.0.107"
anyhow = "1.0.28"

View file

@ -18,6 +18,6 @@ export DIPLONAT_PRIVATE_IP="192.168.0.18"
export DIPLONAT_REFRESH_TIME="60"
export DIPLONAT_EXPIRATION_TIME="300"
export DIPLONAT_CONSUL_NODE_NAME="lheureduthe"
RUST_LOG=info
export RUST_LOG=debug
cargo run
```

7
src/adapter.rs Normal file
View file

@ -0,0 +1,7 @@
use anyhow::Result;
use crate::*;
pub trait Adapter {
fn new(&self, parent: &diplonat::Diplonat) -> Result<()>;
fn run(&self) -> Result<()>;
}

0
src/consul.rs Normal file
View file

View file

@ -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(());
}
}

12
src/igd_adapter.rs Normal file
View file

@ -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(());
}
}

View file

@ -1,6 +1,8 @@
mod diplonat;
mod config;
mod gw;
mod adapter;
mod igd_adapter;
//use std::net::SocketAddrV4;
//use std::collections::HashMap;