From 2aee60f7bbc6186cf6ca63aef182e1fe52fa03ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sat, 10 Oct 2020 17:38:57 +0200 Subject: move connect_udp to network.rs Co-authored-by: Eskil Queseth --- mumd/src/main.rs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'mumd/src/main.rs') 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, ) { - // 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 -- cgit v1.2.1