2020-05-21 20:25:33 +00:00
|
|
|
use igd::aio::*;
|
|
|
|
use log::*;
|
|
|
|
use tokio::sync::broadcast;
|
|
|
|
use anyhow::{Result, Context};
|
|
|
|
use std::cell::Cell;
|
2020-05-21 15:51:30 +00:00
|
|
|
|
2020-05-21 20:25:33 +00:00
|
|
|
use crate::diplonat::*;
|
|
|
|
use crate::node_state::*;
|
|
|
|
|
|
|
|
pub struct IgdAdapter<'a> {
|
|
|
|
state: &'a Cell<NodeState>,
|
|
|
|
gateway: Gateway,
|
|
|
|
}
|
|
|
|
impl<'a> IgdAdapter<'a> {
|
|
|
|
pub async fn new(ns: &'a Cell<NodeState>, send: &broadcast::Sender<()>) -> Result<IgdAdapter<'a>> {
|
|
|
|
let gw = search_gateway(Default::default())
|
|
|
|
.await
|
|
|
|
.context("Failed to find gateway")?;
|
|
|
|
info!("Gateway: {}", gw);
|
|
|
|
|
|
|
|
let ctx = Self {
|
|
|
|
state: ns,
|
|
|
|
gateway: gw
|
|
|
|
};
|
|
|
|
return Ok(ctx);
|
2020-05-21 15:51:30 +00:00
|
|
|
}
|
2020-05-21 20:25:33 +00:00
|
|
|
|
2020-05-21 15:51:30 +00:00
|
|
|
fn run(&self) -> Result<()> {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|