diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-30 14:40:46 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-30 15:25:56 +0200 |
| commit | 79702d18bbd23df2faf0c00b0d9537ce26508f6b (patch) | |
| tree | cb0ae21df0b436336b30cb6c914eda820f999a43 /mumd | |
| parent | 80dba403ed968982ec23ab7416d48dc5b69329f6 (diff) | |
| download | mum-79702d18bbd23df2faf0c00b0d9537ce26508f6b.tar.gz | |
udp error
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/src/client.rs | 3 | ||||
| -rw-r--r-- | mumd/src/error.rs | 13 | ||||
| -rw-r--r-- | mumd/src/network/udp.rs | 16 |
3 files changed, 23 insertions, 9 deletions
diff --git a/mumd/src/client.rs b/mumd/src/client.rs index 6b66731..7c1b0b7 100644 --- a/mumd/src/client.rs +++ b/mumd/src/client.rs @@ -27,7 +27,8 @@ pub async fn handle( let state = Arc::new(Mutex::new(state)); - join!( + //TODO report error here + let (_, _, _, _) = join!( tcp::handle( Arc::clone(&state), connection_info_receiver.clone(), diff --git a/mumd/src/error.rs b/mumd/src/error.rs index 6f77d52..e4a8fee 100644 --- a/mumd/src/error.rs +++ b/mumd/src/error.rs @@ -24,6 +24,19 @@ impl From<mpsc::error::SendError<ControlPacket<Serverbound>>> for TcpError { } } +pub enum UdpError { + NoConnectionInfoReceived, + DisconnectBeforeCryptSetup, + + IOError(std::io::Error), +} + +impl From<std::io::Error> for UdpError { + fn from(e: std::io::Error) -> Self { + UdpError::IOError(e) + } +} + pub enum AudioStream { Input, Output, diff --git a/mumd/src/network/udp.rs b/mumd/src/network/udp.rs index da92dcb..5996e43 100644 --- a/mumd/src/network/udp.rs +++ b/mumd/src/network/udp.rs @@ -1,3 +1,4 @@ +use crate::error::UdpError; use crate::network::ConnectionInfo; use crate::state::{State, StatePhase}; @@ -31,7 +32,7 @@ pub async fn handle( state: Arc<Mutex<State>>, mut connection_info_receiver: watch::Receiver<Option<ConnectionInfo>>, mut crypt_state_receiver: mpsc::Receiver<ClientCryptState>, -) { +) -> Result<(), UdpError> { let receiver = state.lock().await.audio().input_receiver(); loop { @@ -41,9 +42,9 @@ pub async fn handle( break 'data data; } } - return; + return Err(UdpError::NoConnectionInfoReceived); }; - let (sink, source) = connect(&mut crypt_state_receiver).await; + let (sink, source) = connect(&mut crypt_state_receiver).await?; let sink = Arc::new(Mutex::new(sink)); let source = Arc::new(Mutex::new(source)); @@ -82,22 +83,21 @@ pub async fn handle( async fn connect( crypt_state: &mut mpsc::Receiver<ClientCryptState>, -) -> (UdpSender, UdpReceiver) { +) -> Result<(UdpSender, UdpReceiver), UdpError> { // Bind UDP socket let udp_socket = UdpSocket::bind((Ipv6Addr::from(0u128), 0u16)) - .await - .expect("Failed to bind UDP socket"); + .await?; // Wait for initial CryptState let crypt_state = match crypt_state.recv().await { Some(crypt_state) => crypt_state, // disconnected before we received the CryptSetup packet, oh well - None => panic!("Disconnect before crypt packet received"), //TODO exit gracefully + None => return Err(UdpError::DisconnectBeforeCryptSetup), }; debug!("UDP connected"); // Wrap the raw UDP packets in Mumble's crypto and voice codec (CryptState does both) - UdpFramed::new(udp_socket, crypt_state).split() + Ok(UdpFramed::new(udp_socket, crypt_state).split()) } async fn new_crypt_state( |
