aboutsummaryrefslogtreecommitdiff
path: root/src/diplonat.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/diplonat.rs')
-rw-r--r--src/diplonat.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/diplonat.rs b/src/diplonat.rs
index 6334e5b..b2310f9 100644
--- a/src/diplonat.rs
+++ b/src/diplonat.rs
@@ -1,14 +1,17 @@
use anyhow::{Result, anyhow};
+use log::debug;
use tokio::try_join;
use crate::config::ConfigOpts;
use crate::consul_actor::ConsulActor;
+use crate::acme_actor::AcmeActor;
use crate::fw_actor::FirewallActor;
use crate::igd_actor::IgdActor;
pub struct Diplonat {
consul: ConsulActor,
+ acme: Option<AcmeActor>,
firewall: Option<FirewallActor>,
igd: Option<IgdActor>,
}
@@ -16,10 +19,15 @@ pub struct Diplonat {
impl Diplonat {
pub async fn new() -> Result<Self> {
let config = ConfigOpts::from_env()?;
- println!("{:#?}", config);
+ debug!("{:#?}", config);
let consul_actor = ConsulActor::new(config.consul);
+ let acme_actor = AcmeActor::new(
+ config.acme,
+ &consul_actor.rx_open_ports
+ ).await?;
+
let firewall_actor = FirewallActor::new(
config.firewall,
&consul_actor.rx_open_ports
@@ -30,13 +38,16 @@ impl Diplonat {
&consul_actor.rx_open_ports
).await?;
- if firewall_actor.is_none() && igd_actor.is_none() {
+ if acme_actor.is_none() &&
+ firewall_actor.is_none() &&
+ igd_actor.is_none() {
return Err(anyhow!(
"At least enable *one* module, otherwise it's boring!"));
}
let ctx = Self {
consul: consul_actor,
+ acme: acme_actor,
firewall: firewall_actor,
igd: igd_actor,
};
@@ -45,12 +56,19 @@ impl Diplonat {
}
pub async fn listen(&mut self) -> Result<()> {
+ let acme = &mut self.acme;
let firewall = &mut self.firewall;
let igd = &mut self.igd;
try_join!(
self.consul.listen(),
async {
+ match acme {
+ Some(x) => x.listen().await,
+ None => Ok(())
+ }
+ },
+ async {
match firewall {
Some(x) => x.listen().await,
None => Ok(())