Skip to content

Commit 778b6f4

Browse files
committed
fixes: SharedState contains the combined gate of our datagram enabled setting and the peers datagram enabled setting
1 parent ff4c844 commit 778b6f4

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

h3-datagram/src/datagram_handler.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ where
4040
{
4141
/// Sends a datagram
4242
pub fn send_datagram(&mut self, data: B) -> Result<(), SendDatagramError> {
43+
//= https://www.rfc-editor.org/rfc/rfc9297#section-2.1.1
44+
//# QUIC DATAGRAM frames MUST NOT be sent until the SETTINGS_H3_DATAGRAM
45+
//# setting has been both sent and received with a value of 1.
46+
//
47+
// `settings()` holds the negotiated value: the peer's advertisement
48+
// ANDed with our own (see the SETTINGS handling in `h3::connection`).
49+
if !self.settings().enable_datagram() {
50+
return Err(SendDatagramError::NotAvailable);
51+
}
52+
4353
let encoded_datagram = Datagram::new(self.stream_id, data);
4454
match self.handler.send_datagram(encoded_datagram.encode()) {
4555
Ok(()) => Ok(()),

h3/src/connection.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use stream::WriteBuf;
1414
use tracing::{instrument, warn};
1515

1616
use crate::{
17-
config::Config,
17+
config::{Config, Settings},
1818
error::{
1919
connection_error_creators::{
2020
CloseRawQuicConnection, CloseStream, HandleFrameStreamErrorOnRequestStream,
@@ -579,14 +579,19 @@ where
579579
),
580580
)));
581581
}
582-
Ok(Some(Frame::Settings(settings))) => {
582+
Ok(Some(Frame::Settings(peer_settings))) => {
583583
if !self.got_peer_settings {
584584
// Received settings frame
585-
586585
self.got_peer_settings = true;
587-
self.set_settings((&settings).into());
588586

589-
Frame::Settings(settings)
587+
//= https://www.rfc-editor.org/rfc/rfc9297#section-2.1.1
588+
//# QUIC DATAGRAM frames MUST NOT be sent until the SETTINGS_H3_DATAGRAM
589+
//# setting has been both sent and received with a value of 1.
590+
let mut negotiated = Settings::from(&peer_settings);
591+
negotiated.enable_datagram &= self.config.settings.enable_datagram;
592+
self.set_settings(negotiated);
593+
594+
Frame::Settings(peer_settings)
590595
} else {
591596
//= https://www.rfc-editor.org/rfc/rfc9114#section-7.2.4
592597
//# If an endpoint receives a second SETTINGS

0 commit comments

Comments
 (0)