Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rtc-dtls/src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ pub struct DTLSConn {
pub(crate) handshake_config: Arc<HandshakeConfig>,
pub(crate) retransmit: bool,
pub(crate) handshake_rx: Option<()>,
/// Whether the datagram most recently passed to [`Self::read`] carried a handshake record.
/// Reset on every `read`, unlike the sticky `handshake_rx`, so a completed association can tell
/// an RFC 6347 §4.2.4 last-flight repeat from ordinary post-handshake application data.
pub(crate) received_handshake_in_last_datagram: bool,
}

impl DTLSConn {
Expand Down Expand Up @@ -167,6 +171,7 @@ impl DTLSConn {
handshake_config,
retransmit: false,
handshake_rx: None,
received_handshake_in_last_datagram: false,
}
}

Expand Down Expand Up @@ -467,13 +472,18 @@ impl DTLSConn {

/// Feeds one received datagram into the connection.
///
/// Records whether this datagram carried a handshake record in
/// `received_handshake_in_last_datagram`, which a completed association uses to tell an
/// RFC 6347 §4.2.4 last-flight repeat from ordinary post-handshake application data.
///
/// # Errors
///
/// Fails if the record is malformed or fails authentication.
pub fn read(&mut self, buf: &[u8]) -> Result<()> {
// Per RFC 6347: buffer future-epoch packets only until Finished is received
// (i.e. until handshake completes). After that, discard them.
let enqueue = !self.is_handshake_completed();
self.received_handshake_in_last_datagram = false;
for pkt in unpack_datagram(buf)? {
let (hs, alert, err) = self.handle_incoming_packet(pkt, enqueue);
if let Some(alert) = alert {
Expand Down Expand Up @@ -502,6 +512,7 @@ impl DTLSConn {
}

if hs {
self.received_handshake_in_last_datagram = true;
self.handshake_rx = Some(());
}
}
Expand Down
Loading
Loading