aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2020-05-21 17:51:30 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2020-05-21 17:51:30 +0200
commit4da459ce8ba49f98084a8ce32f600470ff883ec5 (patch)
tree608f9e93ca740f76ab3d751103f99e8c9c991e32
parentfeadc844c060ff0879d8d547807147ae2213fd13 (diff)
downloaddiplonat-4da459ce8ba49f98084a8ce32f600470ff883ec5.tar.gz
diplonat-4da459ce8ba49f98084a8ce32f600470ff883ec5.zip
Working on logic
-rw-r--r--Cargo.lock51
-rw-r--r--Cargo.toml1
-rw-r--r--README.md2
-rw-r--r--src/adapter.rs7
-rw-r--r--src/consul.rs0
-rw-r--r--src/diplonat.rs44
-rw-r--r--src/igd_adapter.rs12
-rw-r--r--src/main.rs2
8 files changed, 69 insertions, 50 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6fd2e35..8299558 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
@@ -630,6 +635,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index 1164d5f..2e6eb3f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/README.md b/README.md
index 8c93635..af84a5c 100644
--- a/README.md
+++ b/README.md
@@ -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
```
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;