34 lines
749 B
Rust
34 lines
749 B
Rust
use igd::aio::*;
|
|
use log::*;
|
|
use anyhow::{Result, Context};
|
|
use tokio::sync::watch;
|
|
use crate::messages;
|
|
|
|
pub struct IgdActor {
|
|
rx_ports: watch::Receiver<messages::PublicExposedPorts>,
|
|
gateway: Gateway,
|
|
}
|
|
|
|
impl IgdActor {
|
|
pub async fn new(rxp: &watch::Receiver<messages::PublicExposedPorts>) -> Result<Self> {
|
|
let gw = search_gateway(Default::default())
|
|
.await
|
|
.context("Failed to find gateway")?;
|
|
info!("Gateway: {}", gw);
|
|
|
|
let ctx = Self {
|
|
gateway: gw,
|
|
rx_ports: rxp.clone()
|
|
};
|
|
|
|
return Ok(ctx);
|
|
}
|
|
|
|
pub async fn listen(&mut self) -> Result<()> {
|
|
while let Some(ports) = self.rx_ports.recv().await {
|
|
println!("received = {:#?}", ports);
|
|
}
|
|
return Ok(());
|
|
}
|
|
}
|