Skip to content

Implement SCTP Negotiation Acceleration Protocol (SNAP)#449

Merged
fippo merged 9 commits intopion:masterfrom
fippo:snap
Mar 21, 2026
Merged

Implement SCTP Negotiation Acceleration Protocol (SNAP)#449
fippo merged 9 commits intopion:masterfrom
fippo:snap

Conversation

@fippo
Copy link
Copy Markdown
Contributor

@fippo fippo commented Dec 28, 2025

This commit adds a createAssociationWithOutOfBandTokens method that creates the SCTP association with a local and remote sctp-init token as described in draft-hancke-tsvwg-snap-00.

Tokens can be generated using the newly added GenerateOutOfBandToken method and set in the sctp.Config as LocalSctpInit and RemoteSctpInit.

This allows the peer connection to generate and negotiate the sctp-init in the SDP which skips two network round trips.

pion/WebRTC changes are in pion/webrtc#3327

@fippo fippo marked this pull request as draft December 28, 2025 15:56
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.17%. Comparing base (e3a1986) to head (61380d5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
association.go 84.21% 7 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #449      +/-   ##
==========================================
+ Coverage   84.13%   84.17%   +0.03%     
==========================================
  Files          54       54              
  Lines        4287     4366      +79     
==========================================
+ Hits         3607     3675      +68     
- Misses        494      500       +6     
- Partials      186      191       +5     
Flag Coverage Δ
go 84.17% <85.71%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Jan 13, 2026

I think this is now independent of options/config but still a breaking change 😨

@JoTurk
Copy link
Copy Markdown
Member

JoTurk commented Jan 13, 2026

@fippo this should be merged after or base on #450 as an option With[name] we're going to deprecate this config struct. We shouldn't break the API. I think @philipch07 is going to land this in few days.

@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Jan 14, 2026

@JoTurk problem is that sctp-init (and maxMessageSize + sctp port) should not be a config option, these are negotiated parameters. https://draft.ortc.org/#sctp-transport* had them as "capabilities" but that distinction is too fine-grained (as shown by the non-object remotePort argument)

@JoTurk
Copy link
Copy Markdown
Member

JoTurk commented Jan 14, 2026

@fippo I get the point in the WebRTC context that these inputs are negotiated/signaled values.

But pion/sctp as well as most of our libraries are intentionally standalone. it doesn't own SDP/signaling, We try to make our libraries less aware of the webrtc semantics as much as possible, so the only thing it should do is accept those negotiated values as inputs from the caller. In some applications these valuse can be provided by the application for example application with static maxMessageSize.

Exposing them via options patterns doesn't mean "the app must pick them" and shouldn't negotiate them, it's just the mechanism for providing externally parameters to library, config or negotiated parameters, or anything else, that's all. we are adopting this pattern across all of pion libraries, and we have many users that aren't webrtc users.

@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Feb 26, 2026

Noting here so I don't forget. I have a local rebase but will wait with pushing.

func WithSNAP(localSctpInit []byte, remoteSctpInit []byte) AssociationOption { ... }

@JoTurk
Copy link
Copy Markdown
Member

JoTurk commented Feb 26, 2026

options got merged, sorry for the conflicts.

@fippo fippo force-pushed the snap branch 3 times, most recently from cc13ea6 to 9bac17b Compare February 28, 2026 08:03
@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Feb 28, 2026

not sure if comparing config's (which will be internal at some point anyway?) is needed

@fippo fippo marked this pull request as ready for review March 1, 2026 10:13
@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Mar 8, 2026

(casting to strings was 😭 but...)

@JoTurk
Copy link
Copy Markdown
Member

JoTurk commented Mar 8, 2026

@fippo I try not to be rushed with the reviews if it's still pending / experimental work, but you can ping me if you want quick or actual review, just making sure you're not being ghosted :)

@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Mar 8, 2026

A review would be great but it is probably best to not to merge until some IETF folks have read the draft ;-)

fippo added 6 commits March 18, 2026 11:26
This commit adds a createAssociationWithOutOfBandTokens method
that creates the SCTP association with a local and remote sctp-init
token as described in draft-hancke-tsvwg-snap-00.

Tokens can be generated using the newly added GenerateOutOfBandToken
method and set in the sctp.Config as LocalSctpInit and RemoteSctpInit.

This allows the peer connection to generate and negotiate the
sctp-init attribute in the SDP which skips two network round trips.
Copy link
Copy Markdown
Member

@JoTurk JoTurk left a comment

Choose a reason for hiding this comment

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

thank you so much, this is really cool, just few comments mostly on the library's api.

Comment on lines +170 to +171
c.LocalSctpInit = string(localSctpInit)
c.RemoteSctpInit = string(remoteSctpInit)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we silently fallback to regular handshake if only only one of them is set, we should return an error here if only one is set.

Copy link
Copy Markdown
Contributor Author

@fippo fippo Mar 19, 2026

Choose a reason for hiding this comment

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

but that would make taking them from the SDP and throwing them into WithSNAP harder?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's fair, we can add a warning later then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

only one of both sides supporting an attribute is common enough though, see cryptex or some of the opus variants. Dumping WithSnap(nil, whatevertheremotehas) is useful

Copy link
Copy Markdown
Member

@JoTurk JoTurk Mar 19, 2026

Choose a reason for hiding this comment

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

Yes but this should be handled in pion/webrtc, no?, WithSnap(nil, remote) is a silent non-op now, and while it's convenient, it feels like a bug with our how we usually make our options APIs validate only valid inputs and return errors, i think it's not a clear contract for a public library, it feels that something is wrong. but this is more of a nit. so feel free to ignore it :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah but that means it has to become something along the lines of
WithSnap(localAndRemoteSet ? local : nil, localAndRemoteSet ? remote : nil)
The contract is that Snap is used if both are set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated pion/webrtc#3327 along those lines

which solves the whole string-array conversion (or does it?)
@juberti-oai
Copy link
Copy Markdown

is this patch ready to go?

Copy link
Copy Markdown
Member

@JoTurk JoTurk left a comment

Choose a reason for hiding this comment

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

Just two questions sorry for the back and forth, we had many public API changes recently.

I'll make a PR to update pion/webrtc to sctp options tonight.

I think we can merge this PR and tag a release after the questions get addressed.

@fippo
Copy link
Copy Markdown
Contributor Author

fippo commented Mar 21, 2026

heh, the timing of the options migration got indeed in the way but it is what it is. Thank you for the review(s) and the patience!

(the snap branch in pion/webrtc should have most of what the migration needs, feel free to borrow)

Copy link
Copy Markdown
Member

@JoTurk JoTurk left a comment

Choose a reason for hiding this comment

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

Thank you so much, and sorry again for all the back and forth.

@fippo fippo merged commit 85890bb into pion:master Mar 21, 2026
26 of 27 checks passed
@fippo fippo deleted the snap branch March 21, 2026 19:47
xnorpx added a commit to algesten/sctp-proto that referenced this pull request Mar 22, 2026
Implements SCTP Negotiation Acceleration Protocol (draft-hancke-tsvwg-snap-01), allowing associations to skip the SCTP 4-way handshake by exchanging INIT chunks out-of-band via a signaling channel (e.g., SDP a=sctp-init).

Based on pion/sctp#449.
fippo added a commit to pion/webrtc that referenced this pull request Mar 25, 2026
implements
[draft-hancke-tsvwg-snap.html](https://datatracker.ietf.org/doc/draft-hancke-tsvwg-snap/),
i.e. moving the sctp handshake to out-of-band negotiation as
`a=sctp-init` in the SDP which saves two network round-trips.

(based on #3326, sctp changes in pion/sctp#449)
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.

4 participants