-
Notifications
You must be signed in to change notification settings - Fork 225
ice: add extensible relay candidate providers #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bclswl0827
wants to merge
8
commits into
pion:main
Choose a base branch
from
bclswl0827:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+205
−10
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e70bed
ice: add extensible relay candidate providers
bclswl0827 f15a582
Merge branch 'main' into main
bclswl0827 cade5b9
Add manual local candidate registration
bclswl0827 3745b1e
Merge branch 'main' into main
bclswl0827 6c8df8b
Merge branch 'pion:main' into main
bclswl0827 d7617c6
Fix lint violations in local candidate support
bclswl0827 5e87d3b
Merge branch 'pion:main' into main
bclswl0827 9586aea
Handle duplicate local candidates safely
bclswl0827 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> | ||
| // SPDX-License-Identifier: MIT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please merge this test file with an existing test file? we're trying to limit how much files we add to / |
||
|
|
||
| package ice | ||
|
|
||
| import ( | ||
| "io" | ||
| "net" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| type localCandidatePacketConn struct { | ||
| addr net.Addr | ||
| closeCount atomic.Int32 | ||
| } | ||
|
|
||
| func (c *localCandidatePacketConn) ReadFrom([]byte) (int, net.Addr, error) { | ||
| return 0, c.addr, io.EOF | ||
| } | ||
|
|
||
| func (c *localCandidatePacketConn) WriteTo(payload []byte, _ net.Addr) (int, error) { | ||
| return len(payload), nil | ||
| } | ||
|
|
||
| func (c *localCandidatePacketConn) Close() error { | ||
| c.closeCount.Add(1) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *localCandidatePacketConn) LocalAddr() net.Addr { return c.addr } | ||
| func (c *localCandidatePacketConn) SetDeadline(time.Time) error { return nil } | ||
| func (c *localCandidatePacketConn) SetReadDeadline(time.Time) error { return nil } | ||
| func (c *localCandidatePacketConn) SetWriteDeadline(time.Time) error { return nil } | ||
|
|
||
| func TestAddLocalCandidateRegistersExternalRelay(t *testing.T) { | ||
| agent, err := NewAgentWithOptions( | ||
| WithCandidateTypes([]CandidateType{}), | ||
| WithMulticastDNSMode(MulticastDNSModeDisabled), | ||
| ) | ||
| require.NoError(t, err) | ||
| defer func() { require.NoError(t, agent.Close()) }() | ||
|
|
||
| gatheringComplete := make(chan struct{}) | ||
| candidates := make(chan Candidate, 1) | ||
| require.NoError(t, agent.OnCandidate(func(candidate Candidate) { | ||
| if candidate == nil { | ||
| close(gatheringComplete) | ||
|
|
||
| return | ||
| } | ||
| candidates <- candidate | ||
| })) | ||
|
|
||
| candidate, err := NewCandidateRelay(&CandidateRelayConfig{ | ||
| Network: NetworkTypeUDP4.String(), | ||
| Address: "192.0.2.10", | ||
| Port: 5000, | ||
| Component: ComponentRTP, | ||
| RelayProtocol: "custom", | ||
| }) | ||
| require.NoError(t, err) | ||
| packetConn := &localCandidatePacketConn{ | ||
| addr: &net.UDPAddr{IP: net.IPv4(192, 0, 2, 10), Port: 5000}, | ||
| } | ||
|
|
||
| require.NoError(t, agent.AddLocalCandidate(candidate, packetConn)) | ||
| localCandidates, err := agent.GetLocalCandidates() | ||
| require.NoError(t, err) | ||
| require.Len(t, localCandidates, 1) | ||
| relayCandidate, ok := localCandidates[0].(*CandidateRelay) | ||
| require.True(t, ok) | ||
| require.Equal(t, "custom", relayCandidate.RelayProtocol()) | ||
|
|
||
| select { | ||
| case got := <-candidates: | ||
| require.Equal(t, candidate, got) | ||
| case <-time.After(time.Second): | ||
| require.FailNow(t, "timed out waiting for local candidate callback") | ||
| } | ||
|
|
||
| require.NoError(t, agent.GatherCandidates()) | ||
| select { | ||
| case <-gatheringComplete: | ||
| case <-time.After(time.Second): | ||
| require.FailNow(t, "timed out waiting for gathering completion") | ||
| } | ||
| } | ||
|
|
||
| func TestAddLocalCandidateRejectsNilPacketConn(t *testing.T) { | ||
| agent, err := NewAgentWithOptions(WithMulticastDNSMode(MulticastDNSModeDisabled)) | ||
| require.NoError(t, err) | ||
| defer func() { require.NoError(t, agent.Close()) }() | ||
|
|
||
| candidate, err := NewCandidateRelay(&CandidateRelayConfig{ | ||
| Network: NetworkTypeUDP4.String(), | ||
| Address: "192.0.2.11", | ||
| Port: 5001, | ||
| Component: ComponentRTP, | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Error(t, agent.AddLocalCandidate(candidate, nil)) | ||
| } | ||
|
|
||
| func TestAddLocalCandidateClosesDuplicateConnection(t *testing.T) { | ||
| agent, err := NewAgentWithOptions(WithMulticastDNSMode(MulticastDNSModeDisabled)) | ||
| require.NoError(t, err) | ||
| defer func() { require.NoError(t, agent.Close()) }() | ||
|
|
||
| require.NoError(t, agent.OnCandidate(func(Candidate) {})) | ||
| config := CandidateRelayConfig{ | ||
| Network: NetworkTypeUDP4.String(), | ||
| Address: "192.0.2.12", | ||
| Port: 5002, | ||
| Component: ComponentRTP, | ||
| } | ||
| first, err := NewCandidateRelay(&config) | ||
| require.NoError(t, err) | ||
| second, err := NewCandidateRelay(&config) | ||
| require.NoError(t, err) | ||
| firstConn := &localCandidatePacketConn{addr: &net.UDPAddr{IP: net.IPv4(192, 0, 2, 12), Port: 5002}} | ||
| secondConn := &localCandidatePacketConn{addr: &net.UDPAddr{IP: net.IPv4(192, 0, 2, 12), Port: 5002}} | ||
|
|
||
| require.NoError(t, agent.AddLocalCandidate(first, firstConn)) | ||
| require.NoError(t, agent.AddLocalCandidate(second, secondConn)) | ||
| require.Eventually(t, func() bool { | ||
| return secondConn.closeCount.Load() == 1 | ||
| }, time.Second, time.Millisecond) | ||
|
|
||
| localCandidates, err := agent.GetLocalCandidates() | ||
| require.NoError(t, err) | ||
| require.Len(t, localCandidates, 1) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make sure that a user error with calling this function with the same candidate twice doesn't cause the agent to close the candidate during duplication checks and just returns an error?
ice/agent.go
Lines 1358 to 1364 in c649265
Maybe we can just add a new parameter to addCandidate so it errors and returns if it detects duplication, while keeping the close behavior for normal path?