forked from Deuxfleurs/diplonat
41 lines
766 B
Rust
41 lines
766 B
Rust
use anyhow::Result;
|
|
use log::*;
|
|
use tokio::try_join;
|
|
use crate::consul_actor::ConsulActor;
|
|
use crate::igd_actor::IgdActor;
|
|
use crate::environment::Environment;
|
|
|
|
pub struct Diplonat {
|
|
consul: ConsulActor,
|
|
igd: IgdActor
|
|
}
|
|
|
|
impl Diplonat {
|
|
pub async fn new() -> Result<Self> {
|
|
let env = Environment::new()?;
|
|
let ca = ConsulActor::new(&env.consul_url, &env.consul_node_name);
|
|
let ia = IgdActor::new(
|
|
&env.private_ip,
|
|
env.refresh_time,
|
|
env.expiration_time,
|
|
&ca.rx_open_ports
|
|
).await?;
|
|
|
|
let ctx = Self {
|
|
consul: ca,
|
|
igd: ia
|
|
};
|
|
|
|
return Ok(ctx);
|
|
}
|
|
|
|
pub async fn listen(&mut self) -> Result<()> {
|
|
try_join!(
|
|
self.consul.listen(),
|
|
self.igd.listen()
|
|
)?;
|
|
|
|
return Ok(());
|
|
}
|
|
}
|