2020-05-09 14:19:09 +00:00
|
|
|
use anyhow::{Result, Context};
|
2020-05-21 13:22:45 +00:00
|
|
|
use tokio::try_join;
|
2020-05-09 13:53:22 +00:00
|
|
|
use crate::*;
|
|
|
|
|
2020-05-09 14:50:38 +00:00
|
|
|
pub struct Diplonat {
|
2020-05-09 13:53:22 +00:00
|
|
|
pub config: config::DiplonatConfig,
|
2020-05-09 14:27:54 +00:00
|
|
|
pub gateway: igd::aio::Gateway
|
2020-05-09 13:53:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 14:50:38 +00:00
|
|
|
impl Diplonat {
|
|
|
|
pub async fn new() -> Result<Self> {
|
|
|
|
let ctx = Self {
|
|
|
|
config: config::load_env().context("Unable to read configuration from environment")?,
|
|
|
|
gateway: gw::get_gateway().await?
|
|
|
|
};
|
2020-05-09 14:27:54 +00:00
|
|
|
|
2020-05-09 14:50:38 +00:00
|
|
|
return Ok(ctx);
|
|
|
|
}
|
2020-05-09 13:53:22 +00:00
|
|
|
|
2020-05-21 13:22:45 +00:00
|
|
|
// 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(());
|
2020-05-09 14:50:38 +00:00
|
|
|
}
|
2020-05-09 13:53:22 +00:00
|
|
|
}
|