Skip to content

Conversation

@fippo
Copy link

@fippo fippo commented Dec 30, 2025

(ontop of #861)

This adds a nonblocking API for ICE that will allow the PeerConnection's startTransports to start ICE, not wait for ICE to connect and start DTLS so the DTLS handshake can be piggybacked into the STUN messages earlier.

@fippo fippo changed the title Sped nonblocking Expose nonblocking API for connect Dec 30, 2025
@jech
Copy link
Member

jech commented Jan 1, 2026

Could you please explain why a non-blocking API is better than using the existing API in a separate goroutine?

(Also, I could be mistaken, but I think that the new API is asynchronous rather than nonblocking.)

@fippo
Copy link
Author

fippo commented Jan 3, 2026

API symmetry is one reason, the DTLS API makes a clear distinction between setting up the connection and not returning until the connection is up (Handshake here)

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 93.44262% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.22%. Comparing base (fcd8591) to head (187b3ea).

Files with missing lines Patch % Lines
transport.go 87.87% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #862      +/-   ##
==========================================
+ Coverage   88.11%   88.22%   +0.11%     
==========================================
  Files          43       44       +1     
  Lines        5427     5479      +52     
==========================================
+ Hits         4782     4834      +52     
+ Misses        449      448       -1     
- Partials      196      197       +1     
Flag Coverage Δ
go 88.22% <93.44%> (+0.11%) ⬆️

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 fippo force-pushed the sped-nonblocking branch 2 times, most recently from af458bc to 7411e97 Compare January 6, 2026 09:16
@jech
Copy link
Member

jech commented Jan 6, 2026

No objection, even though I tend to prefer using multiple goroutines to asynchronous APIs, which I find error-prone.

I've looked at the first commit, and it looks good to me. Minor nits:

  • please change the summary of the first commit to say "asynchrounous" instead of "nonblocking";
  • please change the StartDial and StartAccept comments to indicate clearly that it returns immediately.

Have you already submitted the code where you use the new API? May I have a look?

I don't understand why the second commit is being submitted as part of the same PR, but in any case I'm not competent to review it.

@fippo fippo changed the title Expose nonblocking API for connect Expose asynchronous API for connect Jan 6, 2026
@fippo fippo force-pushed the sped-nonblocking branch 2 times, most recently from 0299f73 to e27a9c3 Compare January 6, 2026 12:57
adding `StartDial`, `StartAccept` and `AwaitConnect` methods
which allow more control than `Start` and `Accept`

This will allow the peer connection API to start DTLS before the
ICE connection is established, see
pion/webrtc#3335
@fippo fippo force-pushed the sped-nonblocking branch from e27a9c3 to 187b3ea Compare January 6, 2026 12:59
@jech
Copy link
Member

jech commented Jan 6, 2026

Thanks. The first commit looks good to me.

@fippo
Copy link
Author

fippo commented Jan 6, 2026

No objection, even though I tend to prefer using multiple goroutines to asynchronous APIs, which I find error-prone.

I've looked at the first commit, and it looks good to me. Minor nits:

  • please change the summary of the first commit to say "asynchrounous" instead of "nonblocking";
  • please change the StartDial and StartAccept comments to indicate clearly that it returns immediately.

Done, thank you!

Have you already submitted the code where you use the new API? May I have a look?

https://github.com/fippo/pion-webrtc/blob/snap-sped/icetransport.go#L93
has the intended usage. Currently the iceTransport.Start() only returns when ICE is connected which is kinda unhelpful if one wants to put the DTLS packets into the first few stun packets)

I don't understand why the second commit is being submitted as part of the same PR, but in any case I'm not competent to review it.

githubs continued lack of support for stacked PRs / branches... should vanish once the other PR is merged

@fippo fippo marked this pull request as ready for review January 6, 2026 19:21
@jech
Copy link
Member

jech commented Jan 6, 2026

https://github.com/fippo/pion-webrtc/blob/snap-sped/icetransport.go#L93
has the intended usage. Currently the iceTransport.Start() only returns when ICE is connected which is kinda unhelpful if > one wants to put the DTLS packets into the first few stun packets)

Thanks.

While you wait for this commit to land, you could do something like the following, which would decouple the two commits and avoid the issues with stacked branches:

type connErr struct {
    conn *Conn
    err error
}

func (a *Agent) StartDial(remoteUfrag, remotePwd string) (chan connErr) {
    ch := make(chan connErr)
    go func() {
        conn, err := a.Dial(context.Background(), remoteUfrag, remotePwd)
        ch <- connErr{conn, err}
    }()
    return ch
}

func (a *Agent) AwaitConnect(ch chan connErr) (*Conn, error) {
    ce <- ch
    return ce.conn, ce.err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants