aboutsummaryrefslogtreecommitdiff
path: root/src/fw_actor.rs
diff options
context:
space:
mode:
authoradrien <adrien@luxeylab.net>2021-08-25 17:20:31 +0200
committeradrien <adrien@luxeylab.net>2021-08-26 16:05:39 +0200
commit76fe63791baea5577bde3f83243f85ba781f46fe (patch)
tree1f7ffed5671f30cbd13093db02d7462183bf1952 /src/fw_actor.rs
parentfa25c54e47decf9f323ba0c614f4d9de106626d5 (diff)
downloaddiplonat-76fe63791baea5577bde3f83243f85ba781f46fe.tar.gz
diplonat-76fe63791baea5577bde3f83243f85ba781f46fe.zip
Rewrote the configuration options to make Diplonat modular: IGD and Firewall modules will only be enabled if correponding `DIPLONAT_*_ENABLE` is set. (Breaking changes!)
Also rearranged imports throughout the project, because I couldn't resist, sorry.
Diffstat (limited to 'src/fw_actor.rs')
-rw-r--r--src/fw_actor.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/fw_actor.rs b/src/fw_actor.rs
index b5e4c7e..29e6473 100644
--- a/src/fw_actor.rs
+++ b/src/fw_actor.rs
@@ -1,37 +1,47 @@
+use std::collections::HashSet;
+
use anyhow::Result;
+use iptables;
+use log::*;
use tokio::{
select,
sync::watch,
time::{
+ Duration,
self,
- Duration
}};
-use log::*;
-use iptables;
-use crate::messages;
+use crate::config::RuntimeConfigFirewall;
use crate::fw;
-use std::collections::HashSet;
+use crate::messages;
+
pub struct FirewallActor {
pub ipt: iptables::IPTables,
- rx_ports: watch::Receiver<messages::PublicExposedPorts>,
+
last_ports: messages::PublicExposedPorts,
- refresh: Duration
+ refresh: Duration,
+
+ rx_ports: watch::Receiver<messages::PublicExposedPorts>,
}
impl FirewallActor {
- pub async fn new(_refresh: Duration, rxp: &watch::Receiver<messages::PublicExposedPorts>) -> Result<Self> {
+ pub async fn new(config: Option<RuntimeConfigFirewall>, rxp: &watch::Receiver<messages::PublicExposedPorts>) -> Result<Option<Self>> {
+ if config.is_none() {
+ return Ok(None);
+ }
+ let config = config.unwrap();
+
let ctx = Self {
ipt: iptables::new(false)?,
- rx_ports: rxp.clone(),
last_ports: messages::PublicExposedPorts::new(),
- refresh: _refresh,
+ refresh: config.refresh_time,
+ rx_ports: rxp.clone(),
};
fw::setup(&ctx.ipt)?;
- return Ok(ctx);
+ return Ok(Some(ctx));
}
pub async fn listen(&mut self) -> Result<()> {