WIP loops

This commit is contained in:
Quentin 2020-05-21 15:22:45 +02:00
parent 32d62d1349
commit feadc844c0
3 changed files with 27 additions and 3 deletions

View file

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

View file

@ -1,4 +1,5 @@
use anyhow::{Result, Context}; use anyhow::{Result, Context};
use tokio::try_join;
use crate::*; use crate::*;
pub struct Diplonat { pub struct Diplonat {
@ -16,7 +17,29 @@ impl Diplonat {
return Ok(ctx); return Ok(ctx);
} }
pub fn listen(&self) -> bool { // Action sinks
return true; 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(());
} }
} }

View file

@ -14,7 +14,7 @@ async fn main() {
info!("Starting Diplonat"); info!("Starting Diplonat");
let diplo = Diplonat::new().await.expect("Setup failed"); let diplo = Diplonat::new().await.expect("Setup failed");
diplo.listen(); diplo.listen().await.expect("A runtime error occured");
/* /*
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name); let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
let resp = reqwest::get(&url) let resp = reqwest::get(&url)