aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/network.rs
diff options
context:
space:
mode:
authorKapten Z∅∅m <55669224+default-username-852@users.noreply.github.com>2021-01-07 22:22:24 +0100
committerGitHub <noreply@github.com>2021-01-07 22:22:24 +0100
commit154a2930b3bbe5ede06648c3a10b8fa4904277f4 (patch)
tree18ee2f8b569991d1d0e6b6248539f70da63a62d7 /mumd/src/network.rs
parentba4aa72654f2d57d59f6e25151315213bec21192 (diff)
parent62d3e3d6bf3842a1aad28874a69992b0b880137e (diff)
downloadmum-154a2930b3bbe5ede06648c3a10b8fa4904277f4.tar.gz
Merge pull request #58 from mum-rs/tcp-voice-tunnel-2
TCP voice tunnel
Diffstat (limited to 'mumd/src/network.rs')
-rw-r--r--mumd/src/network.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/mumd/src/network.rs b/mumd/src/network.rs
index 1a31ee2..6c67b3a 100644
--- a/mumd/src/network.rs
+++ b/mumd/src/network.rs
@@ -1,7 +1,17 @@
pub mod tcp;
pub mod udp;
+use futures::Future;
+use futures::FutureExt;
+use futures::channel::oneshot;
+use futures::join;
+use futures::pin_mut;
+use futures::select;
+use log::*;
use std::net::SocketAddr;
+use tokio::sync::watch;
+
+use crate::state::StatePhase;
#[derive(Clone, Debug)]
pub struct ConnectionInfo {
@@ -19,3 +29,43 @@ impl ConnectionInfo {
}
}
}
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
+pub enum VoiceStreamType {
+ TCP,
+ UDP,
+}
+
+async fn run_until<F>(
+ phase_checker: impl Fn(StatePhase) -> bool,
+ fut: F,
+ mut phase_watcher: watch::Receiver<StatePhase>,
+) where
+ F: Future<Output = ()>,
+{
+ let (tx, rx) = oneshot::channel();
+ let phase_transition_block = async {
+ loop {
+ phase_watcher.changed().await.unwrap();
+ if phase_checker(*phase_watcher.borrow()) {
+ break;
+ }
+ }
+ if tx.send(true).is_err() {
+ warn!("future resolved before it could be cancelled");
+ }
+ };
+
+ let main_block = async {
+ let rx = rx.fuse();
+ pin_mut!(rx);
+ let fut = fut.fuse();
+ pin_mut!(fut);
+ select! {
+ _ = fut => (),
+ _ = rx => (),
+ };
+ };
+
+ join!(main_block, phase_transition_block);
+}