aboutsummaryrefslogtreecommitdiff
path: root/src/igd_actor.rs
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2020-05-22 19:21:11 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2020-05-22 19:21:11 +0200
commitc8742b1f1498ffe6f618451ada3da3b3ecf2509f (patch)
tree2a0e928fcf04ea82daff070e7ae49d723436162f /src/igd_actor.rs
parente1d0eadb9dc5e2e3bea8bc48f7b33ad9ef632554 (diff)
downloaddiplonat-c8742b1f1498ffe6f618451ada3da3b3ecf2509f.tar.gz
diplonat-c8742b1f1498ffe6f618451ada3da3b3ecf2509f.zip
Connecting elements
Diffstat (limited to 'src/igd_actor.rs')
-rw-r--r--src/igd_actor.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/igd_actor.rs b/src/igd_actor.rs
index 6624ab3..4e2f4b6 100644
--- a/src/igd_actor.rs
+++ b/src/igd_actor.rs
@@ -1,31 +1,33 @@
use igd::aio::*;
use log::*;
-use tokio::sync::broadcast;
use anyhow::{Result, Context};
-use std::cell::Cell;
+use tokio::sync::watch;
+use crate::messages;
-use crate::diplonat::*;
-use crate::node_state::*;
-
-pub struct IgdAdapter<'a> {
- state: &'a Cell<NodeState>,
+pub struct IgdActor {
+ rx_ports: watch::Receiver<messages::PublicExposedPorts>,
gateway: Gateway,
}
-impl<'a> IgdAdapter<'a> {
- pub async fn new(ns: &'a Cell<NodeState>, send: &broadcast::Sender<()>) -> Result<IgdAdapter<'a>> {
+
+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 {
- state: ns,
- gateway: gw
+ gateway: gw,
+ rx_ports: rxp.clone()
};
+
return Ok(ctx);
}
- fn run(&self) -> Result<()> {
+ pub async fn listen(&mut self) -> Result<()> {
+ while let Some(ports) = self.rx_ports.recv().await {
+ println!("received = {:#?}", ports);
+ }
return Ok(());
}
}