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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1613>
This commit is contained in:
Sanchayan Maity 2024-06-13 12:07:09 +05:30
parent dbad98132f
commit bc5ed023e4
2 changed files with 46 additions and 6 deletions

View file

@ -498,6 +498,15 @@ impl QuinnQuicSink {
};
if use_datagram {
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!(
@ -505,6 +514,13 @@ impl QuinnQuicSink {
["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
};

View file

@ -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
};