From bc5ed023e4fa9657ec679f8a6e1176224186266b Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Thu, 13 Jun 2024 12:07:09 +0530 Subject: [PATCH] net/quinn: Improve datagram handling We now check if the peer actually supports Datagram and refusing to proceed if it does not. Since the datagram size can actually change over the lifetime of a connection according to variation in path MTU estimate, also check buffer size before trying to send. Part-of: --- net/quinn/src/quinnquicsink/imp.rs | 40 +++++++++++++++++++++++++----- net/quinn/src/quinnquicsrc/imp.rs | 12 +++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/net/quinn/src/quinnquicsink/imp.rs b/net/quinn/src/quinnquicsink/imp.rs index a556fd4d..f731df7f 100644 --- a/net/quinn/src/quinnquicsink/imp.rs +++ b/net/quinn/src/quinnquicsink/imp.rs @@ -498,12 +498,28 @@ impl QuinnQuicSink { }; if use_datagram { - match conn.send_datagram(Bytes::copy_from_slice(src)) { - Ok(_) => Ok(()), - Err(e) => Err(Some(gst::error_msg!( - gst::ResourceError::Failed, - ["Sending data failed: {}", e] - ))), + match conn.max_datagram_size() { + Some(size) => { + if src.len() > size { + return Err(Some(gst::error_msg!( + gst::ResourceError::Failed, + ["Sending data failed, current max datagram size: {size}"] + ))); + } + + match conn.send_datagram(Bytes::copy_from_slice(src)) { + Ok(_) => Ok(()), + Err(e) => Err(Some(gst::error_msg!( + gst::ResourceError::Failed, + ["Sending data failed: {}", e] + ))), + } + } + /* + * We check for datagram being unsupported by peer in + * start/init_connection, so we should never reach here. + */ + None => unreachable!(), } } else { let send = &mut stream.as_mut().unwrap(); @@ -627,6 +643,18 @@ impl QuinnQuicSink { Some(res) } else { + match connection.max_datagram_size() { + Some(datagram_size) => { + gst::info!(CAT, imp: self, "Datagram size reported by peer: {datagram_size}"); + } + None => { + return Err(WaitError::FutureError(gst::error_msg!( + gst::ResourceError::Failed, + ["Datagram unsupported by the peer"] + ))); + } + } + None }; diff --git a/net/quinn/src/quinnquicsrc/imp.rs b/net/quinn/src/quinnquicsrc/imp.rs index f1855ea6..5bdd8cc2 100644 --- a/net/quinn/src/quinnquicsrc/imp.rs +++ b/net/quinn/src/quinnquicsrc/imp.rs @@ -690,6 +690,18 @@ impl QuinnQuicSrc { Some(res) } else { + match connection.max_datagram_size() { + Some(datagram_size) => { + gst::info!(CAT, imp: self, "Datagram size reported by peer: {datagram_size}"); + } + None => { + return Err(WaitError::FutureError(gst::error_msg!( + gst::ResourceError::Failed, + ["Datagram unsupported by the peer"] + ))); + } + } + None };