Skip to content
Merged
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
32 changes: 22 additions & 10 deletions src/transport/webrtc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,26 @@ impl WebRtcTransport {
"received non-stun message"
);

if let Err(error) = self.opening.get_mut(&source).expect("to exist").on_input(contents)
{
tracing::error!(
target: LOG_TARGET,
?error,
?source,
"failed to handle inbound datagram"
);
}
match self.opening.get_mut(&source) {
Some(connection) =>
if let Err(error) = connection.on_input(contents) {
tracing::error!(
target: LOG_TARGET,
?error,
?source,
"failed to handle inbound datagram"
);
},
None => {
tracing::warn!(
target: LOG_TARGET,
?source,
"received non-stun message from unknown peer",
);
return Err(Error::InvalidData);
}
};

return Ok(true);
}

Expand Down Expand Up @@ -809,6 +820,7 @@ impl Stream for WebRtcTransport {
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// ```
fn is_stun_packet(bytes: &[u8]) -> bool {
const STUN_MAGIC_COOKIE: [u8; 4] = [0x21, 0x12, 0xA4, 0x42];
// 20 bytes for the header, then follows attributes.
bytes.len() >= 20 && bytes[0] < 2
bytes.len() >= 20 && bytes[0] < 2 && bytes[4..8] == STUN_MAGIC_COOKIE
}
Loading