From c19b763b5de1fd065f249d47e872ca84bbb39330 Mon Sep 17 00:00:00 2001 From: adrien Date: Sat, 11 Sep 2021 18:55:26 +0200 Subject: applied rustfmt from branch meta/formating, without rebasing anything --- src/fw_actor.rs | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'src/fw_actor.rs') diff --git a/src/fw_actor.rs b/src/fw_actor.rs index 9000048..fa905c0 100644 --- a/src/fw_actor.rs +++ b/src/fw_actor.rs @@ -4,18 +4,15 @@ use anyhow::Result; use iptables; use log::*; use tokio::{ - select, - sync::watch, - time::{ - Duration, - self, -}}; + select, + sync::watch, + time::{self, Duration}, +}; use crate::config::RuntimeConfigFirewall; use crate::fw; use crate::messages; - pub struct FirewallActor { pub ipt: iptables::IPTables, @@ -26,13 +23,16 @@ pub struct FirewallActor { } impl FirewallActor { - pub async fn new(config: Option, rxp: &watch::Receiver) -> Result> { + pub async fn new( + config: Option, + rxp: &watch::Receiver, + ) -> Result> { if config.is_none() { return Ok(None); } let config = config.unwrap(); - let ctx = Self { + let ctx = Self { ipt: iptables::new(false)?, last_ports: messages::PublicExposedPorts::new(), refresh: config.refresh_time, @@ -40,7 +40,7 @@ impl FirewallActor { }; fw::setup(&ctx.ipt)?; - + return Ok(Some(ctx)); } @@ -55,7 +55,9 @@ impl FirewallActor { }; // 2. Update last ports if needed - if let Some(p) = new_ports { self.last_ports = p; } + if let Some(p) = new_ports { + self.last_ports = p; + } // 3. Update firewall rules match self.do_fw_update().await { @@ -68,19 +70,27 @@ impl FirewallActor { pub async fn do_fw_update(&self) -> Result<()> { let curr_opened_ports = fw::get_opened_ports(&self.ipt)?; - let diff_tcp = self.last_ports.tcp_ports.difference(&curr_opened_ports.tcp_ports).copied().collect::>(); - let diff_udp = self.last_ports.udp_ports.difference(&curr_opened_ports.udp_ports).copied().collect::>(); + let diff_tcp = self + .last_ports + .tcp_ports + .difference(&curr_opened_ports.tcp_ports) + .copied() + .collect::>(); + let diff_udp = self + .last_ports + .udp_ports + .difference(&curr_opened_ports.udp_ports) + .copied() + .collect::>(); let ports_to_open = messages::PublicExposedPorts { - tcp_ports: diff_tcp, - udp_ports: diff_udp, - acme: HashSet::new() + tcp_ports: diff_tcp, + udp_ports: diff_udp, + acme: HashSet::new(), }; fw::open_ports(&self.ipt, ports_to_open)?; return Ok(()); } - } - -- cgit v1.2.3