Modular Diplonat (with the option to disable useless modules) #8
3 changed files with 32 additions and 35 deletions
|
@ -19,7 +19,7 @@ impl Diplonat {
|
||||||
|
|
||||||
let consul_actor = ConsulActor::new(config.consul);
|
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?;
|
let igd_actor = IgdActor::new(config.igd, &consul_actor.rx_open_ports).await?;
|
||||||
|
|
||||||
|
|
|
@ -21,25 +21,24 @@ pub struct FirewallActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FirewallActor {
|
impl FirewallActor {
|
||||||
pub async fn new(
|
pub fn new(
|
||||||
config: Option<RuntimeConfigFirewall>,
|
config: Option<RuntimeConfigFirewall>,
|
||||||
rxp: &watch::Receiver<messages::PublicExposedPorts>,
|
rxp: &watch::Receiver<messages::PublicExposedPorts>,
|
||||||
) -> Result<Option<Self>> {
|
) -> Result<Option<Self>> {
|
||||||
if config.is_none() {
|
match config {
|
||||||
return Ok(None)
|
None => Ok(None),
|
||||||
|
Some(c) => {
|
||||||
|
let ctx = Self {
|
||||||
|
ipt: iptables::new(false)?,
|
||||||
|
last_ports: messages::PublicExposedPorts::new(),
|
||||||
|
refresh: c.refresh_time,
|
||||||
|
rx_ports: rxp.clone(),
|
||||||
|
};
|
||||||
|
fw::setup(&ctx.ipt)?;
|
||||||
|
|
||||||
|
Ok(Some(ctx))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let config = config.unwrap();
|
|
||||||
|
|
||||||
let ctx = Self {
|
|
||||||
ipt: iptables::new(false)?,
|
|
||||||
last_ports: messages::PublicExposedPorts::new(),
|
|
||||||
refresh: config.refresh_time,
|
|
||||||
rx_ports: rxp.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
fw::setup(&ctx.ipt)?;
|
|
||||||
|
|
||||||
return Ok(Some(ctx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn listen(&mut self) -> Result<()> {
|
pub async fn listen(&mut self) -> Result<()> {
|
||||||
|
|
|
@ -26,26 +26,24 @@ impl IgdActor {
|
||||||
config: Option<RuntimeConfigIgd>,
|
config: Option<RuntimeConfigIgd>,
|
||||||
rxp: &watch::Receiver<messages::PublicExposedPorts>,
|
rxp: &watch::Receiver<messages::PublicExposedPorts>,
|
||||||
) -> Result<Option<Self>> {
|
) -> Result<Option<Self>> {
|
||||||
if config.is_none() {
|
match config {
|
||||||
return Ok(None)
|
None => Ok(None),
|
||||||
|
Some(c) => {
|
||||||
|
let gw = search_gateway(Default::default())
|
||||||
|
.await
|
||||||
|
.context("Failed to find IGD gateway")?;
|
||||||
|
info!("IGD gateway: {}", gw);
|
||||||
|
|
||||||
|
Ok(Some(Self {
|
||||||
|
expire: c.expiration_time,
|
||||||
|
gateway: gw,
|
||||||
|
last_ports: messages::PublicExposedPorts::new(),
|
||||||
|
private_ip: c.private_ip,
|
||||||
|
refresh: c.refresh_time,
|
||||||
|
rx_ports: rxp.clone(),
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let config = config.unwrap();
|
|
||||||
|
|
||||||
let gw = search_gateway(Default::default())
|
|
||||||
.await
|
|
||||||
.context("Failed to find IGD gateway")?;
|
|
||||||
info!("IGD gateway: {}", gw);
|
|
||||||
|
|
||||||
let ctx = Self {
|
|
||||||
expire: config.expiration_time,
|
|
||||||
gateway: gw,
|
|
||||||
last_ports: messages::PublicExposedPorts::new(),
|
|
||||||
private_ip: config.private_ip,
|
|
||||||
refresh: config.refresh_time,
|
|
||||||
rx_ports: rxp.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(Some(ctx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn listen(&mut self) -> Result<()> {
|
pub async fn listen(&mut self) -> Result<()> {
|
||||||
|
|
Loading…
Reference in a new issue
Now that our actors are modular, I think that this function fails to convey the real meaning of what we want to do.
IMHO, I think we want to:
With the current code, I see many problems.
((1)) I have a feeling that we are duplicating logic between the "runtime config" and our actor initialization. Currently, the constructor of the actor is only:
To fix this problem, I see 2 options:
((2)) The current
try_join!
fails to convey the information that we run only the initialized actors. I think that, independently of the choice you made for 1, you should create a vector of initialized actors that you will populate and then run. You will replacetry_join!
bytry_join_all
Tip: start by solving problem number 2, it will help you solve problem number 1