Skip to content

webrtc: Decode webrtc message from multiple SCTP messages#594

Open
lexnv wants to merge 14 commits into
masterfrom
lexnv/decode-webrtc
Open

webrtc: Decode webrtc message from multiple SCTP messages#594
lexnv wants to merge 14 commits into
masterfrom
lexnv/decode-webrtc

Conversation

@lexnv
Copy link
Copy Markdown
Collaborator

@lexnv lexnv commented May 25, 2026

This PR extends WebRTC's compatibility to support interaction with libp2p-go clients.

The libp2p-go implementation makes two separate write calls on the substream:

  • one for variant length
  • one for protobuf actual message

This then translates over the wire into two SCTP messages. The current implementation only accepts WebRTC::Messages if it can be decoded from a single SCTP message.

This breaks the WebRTC spec compatibility at two levels:

  • during the noise handshake logic
  • during the message communication

To align the WebRTC impl to be spec-compliant, this PR adds a buffer for both places, ensuring the decoding acts immediately on:

  • a single message (legacy smoldot)
  • two SCTP messages that form one single WebRTC message (libp2p-go)

cc @gab8i @dmitry-markin @skunert

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv self-assigned this May 25, 2026
lexnv added 2 commits May 25, 2026 10:21
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
lexnv added 6 commits May 25, 2026 13:06
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
messages

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@lexnv lexnv changed the title webrtc: Decode webrtc message from 2 SCTP messages webrtc: Decode webrtc message from multiple SCTP messages May 25, 2026
lexnv added 3 commits May 25, 2026 13:29
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
channels

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Copy link
Copy Markdown
Contributor

@gab8i gab8i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread src/transport/webrtc/connection.rs Outdated
Comment thread src/transport/webrtc/opening.rs Outdated
tracing::trace!(
target: LOG_TARGET,
buffered = self.noise_recv_buffer.len(),
"incomplete noise frame, waiting for more bytes",
Copy link
Copy Markdown
Collaborator

@dmitry-markin dmitry-markin Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to also log peerid/remote endpoint here and in other logs.

Comment thread src/transport/webrtc/util.rs
lexnv and others added 2 commits June 1, 2026 15:34
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants