WIP: looks better, but the Diplonat new function is still full of shit - I'll investigate
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
adrien 2021-09-22 17:02:25 +02:00
parent a464aabe25
commit 6015d85b73

View file

@ -2,14 +2,16 @@ use std::pin::Pin;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use futures::future::{try_join_all, Future}; use futures::future::{try_join_all, Future};
use tokio::try_join; // use tokio::try_join;
type ActorTask = Pin<Box<dyn Future<Output = Result<()>>>>;
use crate::{ use crate::{
config::ConfigOpts, consul_actor::ConsulActor, fw_actor::FirewallActor, igd_actor::IgdActor, config::ConfigOpts, consul_actor::ConsulActor, fw_actor::FirewallActor, igd_actor::IgdActor,
}; };
pub struct Diplonat { pub struct Diplonat {
actors: Vec<Pin<Box<dyn Future<Output = Result<()>>>>>, actors: Vec<ActorTask>,
} }
impl Diplonat { impl Diplonat {
@ -17,14 +19,19 @@ impl Diplonat {
let config = ConfigOpts::from_env()?; let config = ConfigOpts::from_env()?;
println!("{:#?}", config); println!("{:#?}", config);
let consul_actor = ConsulActor::new(config.consul); let mut consul_actor = ConsulActor::new(config.consul);
let mut actors = vec![Box::pin(consul_actor.listen())]; let consul_rx = consul_actor.rx_open_ports.clone();
let actor_task: ActorTask = Box::pin(consul_actor.listen());
if let Some(actor) = FirewallActor::new(config.firewall, &consul_actor.rx_open_ports)? { let mut actors = vec![actor_task];
actors.push(Box::pin(actor.listen()));
if let Some(mut actor) = FirewallActor::new(config.firewall, &consul_rx)? {
let actor_task: ActorTask = Box::pin(actor.listen());
actors.push(actor_task);
} }
if let Some(actor) = IgdActor::new(config.igd, &consul_actor.rx_open_ports).await? { if let Some(mut actor) = IgdActor::new(config.igd, &consul_rx).await? {
actors.push(Box::pin(actor.listen())); let actor_task: ActorTask = Box::pin(actor.listen());
actors.push(actor_task);
} }
if actors.len() == 1 { if actors.len() == 1 {