diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-10-10 17:38:57 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-10-10 17:38:57 +0200 |
| commit | 2aee60f7bbc6186cf6ca63aef182e1fe52fa03ad (patch) | |
| tree | 3c60651a37bbdf082fea57bfc0e08bcde52ef764 /mumd/src/main.rs | |
| parent | e88e8df4d464e7c937e64ea68701a7c155bd3f1d (diff) | |
| download | mum-2aee60f7bbc6186cf6ca63aef182e1fe52fa03ad.tar.gz | |
move connect_udp to network.rs
Co-authored-by: Eskil Queseth <eskilq@kth.se>
Diffstat (limited to 'mumd/src/main.rs')
| -rw-r--r-- | mumd/src/main.rs | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/mumd/src/main.rs b/mumd/src/main.rs index c8cf68b..ffd5547 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -21,13 +21,9 @@ use mumble_protocol::voice::VoicePacketPayload; use std::convert::Into; use std::convert::TryInto; -use std::net::Ipv6Addr; use std::net::SocketAddr; use std::net::ToSocketAddrs; -use tokio::net::UdpSocket; -use tokio_util::udp::UdpFramed; - use tokio::time::{self, Duration}; use std::sync::Arc; @@ -130,19 +126,6 @@ async fn handle_udp( server_addr: SocketAddr, crypt_state: oneshot::Receiver<ClientCryptState>, ) { - // Bind UDP socket - let udp_socket = UdpSocket::bind((Ipv6Addr::from(0u128), 0u16)) - .await - .expect("Failed to bind UDP socket"); - - // Wait for initial CryptState - let crypt_state = match crypt_state.await { - Ok(crypt_state) => crypt_state, - // disconnected before we received the CryptSetup packet, oh well - Err(_) => return, - }; - println!("UDP ready!"); - let audio = Audio::new(); audio.output_stream.play().unwrap(); @@ -156,8 +139,7 @@ async fn handle_udp( } ).unwrap(); - // Wrap the raw UDP packets in Mumble's crypto and voice codec (CryptState does both) - let (mut sink, mut source) = UdpFramed::new(udp_socket, crypt_state).split(); + let (mut sink, mut source) = network::connect_udp(server_addr, crypt_state).await; // Note: A normal application would also send periodic Ping packets, and its own audio // via UDP. We instead trick the server into accepting us by sending it one |
