Skip to content

feat(webrtc-utils): move the offer SDP template alongside the answer - #6572

Open
yexiyue wants to merge 2 commits into
libp2p:masterfrom
yexiyue:feat/share-offer-sdp-template
Open

feat(webrtc-utils): move the offer SDP template alongside the answer#6572
yexiyue wants to merge 2 commits into
libp2p:masterfrom
yexiyue:feat/share-offer-sdp-template

Conversation

@yexiyue

@yexiyue yexiyue commented Jul 28, 2026

Copy link
Copy Markdown

Description

libp2p-webrtc-utils owns half of the SDP pair. sdp::answer and
SERVER_SESSION_DESCRIPTION live there; the offer template sits private in
transports/webrtc/src/tokio/sdp.rs. The split is visible in the source — the doc comment on
SERVER_SESSION_DESCRIPTION opens with:

// See [`CLIENT_SESSION_DESCRIPTION`].

pointing at a constant in a different crate, where the shared RFC annotations for both templates
actually live.

This moves CLIENT_SESSION_DESCRIPTION over with its annotations and adds sdp::offer mirroring
sdp::answer, so both descriptions of the libp2p WebRTC handshake sit in one place:

pub fn offer(addr: SocketAddr, client_fingerprint: Fingerprint, client_ufrag: &str) -> String
pub fn answer(addr: SocketAddr, server_fingerprint: Fingerprint, client_ufrag: &str) -> String

The offer takes the fingerprint as an argument rather than hardcoding Fingerprint::FF. That
keeps the two symmetric and leaves the "we don't verify the client's certificate, its identity
comes from the Noise handshake" decision at the call site, where the comment explaining it already
is. libp2p-webrtc's sdp::offer becomes the same thin RTCSessionDescription wrapper its
sdp::answer already was.

No behaviour change — the rendered offer is byte-for-byte what it was.

AI Assistance Disclosure

Tools used (required — write none if no AI was used): Claude Code

Attestation (required):

  • I have read every line of this diff, understand what it does, and can explain it in review.

Notes & open questions

This came out of building a WebRTC-Direct transport outside the tree. libp2p-webrtc-utils is
otherwise exactly the crate you need for that — fingerprints, the Noise prologue, the stream
framing, the answer template — and the offer template was the one piece I had to copy out of
libp2p-webrtc verbatim.

One thing this makes visible: with both templates rendered inside the crate, render_description
no longer has any caller outside it. I left it pub since narrowing it would be a breaking change
unrelated to this PR, but happy to fold that in if you'd rather.

The changelog entries have placeholder PR numbers; I'll push the real one once this is assigned.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

yexiyue added 2 commits July 28, 2026 19:12
`libp2p-webrtc-utils` owns half of the SDP pair: `sdp::answer` and
`SERVER_SESSION_DESCRIPTION` live here, while the offer template sits private in
`transports/webrtc/src/tokio/sdp.rs`. The split is visible in the source --
`SERVER_SESSION_DESCRIPTION`'s doc comment opens with "See
[`CLIENT_SESSION_DESCRIPTION`]", pointing at a constant in another crate.

Move `CLIENT_SESSION_DESCRIPTION` here with its annotations and add `sdp::offer`
mirroring `sdp::answer`, so both descriptions of the libp2p WebRTC handshake are
in one place. The offer takes the fingerprint as an argument rather than
hardcoding `Fingerprint::FF`, which keeps the two functions symmetric and leaves
the "we don't verify the client certificate" decision at the call site where it
is explained.

`libp2p-webrtc`'s `sdp::offer` becomes the same thin `RTCSessionDescription`
wrapper its `sdp::answer` already was. No behaviour change: the rendered offer is
byte-for-byte what it was.
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.

1 participant