diplonat/src/diplonat.rs

32 lines
766 B
Rust
Raw Normal View History

2020-05-09 14:19:09 +00:00
use anyhow::{Result, Context};
2020-05-21 15:51:30 +00:00
use tokio::sync::broadcast;
use futures::future::try_join_all;
use crate::*;
2020-05-21 15:51:30 +00:00
pub struct Diplonat<'a> {
pub config: config::DiplonatConfig,
2020-05-21 15:51:30 +00:00
pub gateway: igd::aio::Gateway,
pub notif: broadcast::Sender<()>,
pub public_ports: &'a[u16],
adapters: &'a[&'a dyn adapter::Adapter]
}
2020-05-21 15:51:30 +00:00
impl<'a> Diplonat<'a> {
pub async fn new() -> Result<Diplonat<'a>> {
let (tx, _) = broadcast::channel(1);
let ctx = Diplonat {
2020-05-09 14:50:38 +00:00
config: config::load_env().context("Unable to read configuration from environment")?,
2020-05-21 15:51:30 +00:00
gateway: gw::get_gateway().await?,
notif: tx,
public_ports: &[110, 111, 112],
adapters: &[]
2020-05-09 14:50:38 +00:00
};
2020-05-09 14:27:54 +00:00
2020-05-09 14:50:38 +00:00
return Ok(ctx);
}
2020-05-21 13:22:45 +00:00
pub async fn listen(&self) -> Result<()> {
return Ok(());
2020-05-09 14:50:38 +00:00
}
}