Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Seems useful @HashimTheArab! I’m curious what’s the bug/use case your solving for? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3371 +/- ##
==========================================
+ Coverage 84.97% 84.98% +0.01%
==========================================
Files 81 81
Lines 9637 9639 +2
==========================================
+ Hits 8189 8192 +3
+ Misses 1022 1020 -2
- Partials 426 427 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
We're using this for Minecraft Nethernet connections (https://github.com/lactyy/go-nethernet) and the transport methods can hang indefinitely if the remote peer never responds. Without this option we have to use this fragile hack: func withContextCancel(ctx context.Context, f func() error, cancel func()) error {
errCh := make(chan error, 1)
go func() {
errCh <- f()
}()
select {
case <-ctx.Done():
if cancel != nil {
cancel()
}
go func() { <-errCh }()
return ctx.Err()
case err := <-errCh:
return err
}
}Passing a context will allow us to simplify and improve all of the call sites: // Before
if err := withContextCancel(ctx, func() error {
return conn.ice.Start(nil, d.ice, &iceRole)
}, func() {
_ = conn.ice.Stop()
}); err != nil {
return fmt.Errorf("start ICE: %w", err)
}
// After
if err := conn.ice.StartContext(ctx, nil, d.ice, &iceRole); err != nil {
return fmt.Errorf("start ICE: %w", err)
}(I am not the author of the PR) |
|
@RealSexMC this is interesting I'm curious why you don't use pion/ice directly? seems more fit for your use, but I might be missing something. We're currently working on improving pion/ice and making it more suitable for non-webrtc use. |
|
@RealSexMC that is very interesting, couldn't you |
|
NetherNet is a full WebRTC stack, it uses ICE + DTLS + SCTP with data channels (ReliableDataChannel and UnreliableDataChannel) negotiated via SDP. We use pion's ORTC API to set up each transport individually since the signaling is custom (not standard WebSocket/HTTP), but the transports themselves are standard WebRTC. |
|
Anything else required to get this merged? |
|
Can you please fix the lint? |
Summary
StartContextmethod toICETransportthat accepts acontext.Contextparameter, allowing callers to control cancellation and timeouts for ICE connectivity checksStartto delegate toStartContextwithcontext.Background(), maintaining full backwards compatibility🤖 Generated with Claude Code