WIP: rewrote body of 'new(...)' for FirewallActor and IgdActor using match; clearer intent
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
This commit is contained in:
parent
f5ac36e21f
commit
006f84e3b0
3 changed files with 32 additions and 35 deletions
|
@ -19,7 +19,7 @@ impl Diplonat {
|
|||
|
||||
let consul_actor = ConsulActor::new(config.consul);
|
||||
|
||||
let firewall_actor = FirewallActor::new(config.firewall, &consul_actor.rx_open_ports).await?;
|
||||
let firewall_actor = FirewallActor::new(config.firewall, &consul_actor.rx_open_ports)?;
|
||||
|
||||
let igd_actor = IgdActor::new(config.igd, &consul_actor.rx_open_ports).await?;
|
||||
|
||||
|
|
|
@ -21,25 +21,24 @@ pub struct FirewallActor {
|
|||
}
|
||||
|
||||
impl FirewallActor {
|
||||
pub async fn new(
|
||||
pub fn new(
|
||||
config: Option<RuntimeConfigFirewall>,
|
||||
rxp: &watch::Receiver<messages::PublicExposedPorts>,
|
||||
) -> Result<Option<Self>> {
|
||||
if config.is_none() {
|
||||
return Ok(None)
|
||||
}
|
||||
let config = config.unwrap();
|
||||
|
||||
match config {
|
||||
None => Ok(None),
|
||||
Some(c) => {
|
||||
let ctx = Self {
|
||||
ipt: iptables::new(false)?,
|
||||
last_ports: messages::PublicExposedPorts::new(),
|
||||
refresh: config.refresh_time,
|
||||
refresh: c.refresh_time,
|
||||
rx_ports: rxp.clone(),
|
||||
};
|
||||
|
||||
fw::setup(&ctx.ipt)?;
|
||||
|
||||
return Ok(Some(ctx))
|
||||
Ok(Some(ctx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn listen(&mut self) -> Result<()> {
|
||||
|
|
|
@ -26,26 +26,24 @@ impl IgdActor {
|
|||
config: Option<RuntimeConfigIgd>,
|
||||
rxp: &watch::Receiver<messages::PublicExposedPorts>,
|
||||
) -> Result<Option<Self>> {
|
||||
if config.is_none() {
|
||||
return Ok(None)
|
||||
}
|
||||
let config = config.unwrap();
|
||||
|
||||
match config {
|
||||
None => Ok(None),
|
||||
Some(c) => {
|
||||
let gw = search_gateway(Default::default())
|
||||
.await
|
||||
.context("Failed to find IGD gateway")?;
|
||||
info!("IGD gateway: {}", gw);
|
||||
|
||||
let ctx = Self {
|
||||
expire: config.expiration_time,
|
||||
Ok(Some(Self {
|
||||
expire: c.expiration_time,
|
||||
gateway: gw,
|
||||
last_ports: messages::PublicExposedPorts::new(),
|
||||
private_ip: config.private_ip,
|
||||
refresh: config.refresh_time,
|
||||
private_ip: c.private_ip,
|
||||
refresh: c.refresh_time,
|
||||
rx_ports: rxp.clone(),
|
||||
};
|
||||
|
||||
return Ok(Some(ctx))
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn listen(&mut self) -> Result<()> {
|
||||
|
|
Loading…
Reference in a new issue