Skip to content

Commit

Permalink
Include ufrag in generated ICE candidates
Browse files Browse the repository at this point in the history
Include ufrag extension in the ICE candidates generated by the ICE agent
  • Loading branch information
JoeTurki committed Jan 30, 2025
1 parent 60cb55e commit df554ef
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ func (a *Agent) addCandidate(ctx context.Context, cand Candidate, candidateConn
}
}

a.setCandidateExtensions(cand)
cand.start(a, candidateConn, a.startedCh)

set = append(set, cand)
Expand All @@ -818,6 +819,16 @@ func (a *Agent) addCandidate(ctx context.Context, cand Candidate, candidateConn
})
}

func (a *Agent) setCandidateExtensions(cand Candidate) {
err := cand.AddExtension(CandidateExtension{
Key: "ufrag",
Value: a.localUfrag,
})
if err != nil {
a.log.Errorf("Failed to add ufrag extension to candidate: %v", err)
}
}

// GetRemoteCandidates returns the remote candidates.
func (a *Agent) GetRemoteCandidates() ([]Candidate, error) {
var res []Candidate
Expand Down
39 changes: 39 additions & 0 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,3 +2071,42 @@ func TestAgentGracefulCloseDeadlock(t *testing.T) {
closeNow.Done()
closed.Wait()
}

func TestSetCandidatesUfrag(t *testing.T) {
var config AgentConfig

agent, err := NewAgent(&config)
if err != nil {
t.Fatalf("Error constructing ice.Agent: %v", err)
}
defer func() {
require.NoError(t, agent.Close())
}()

dummyConn := &net.UDPConn{}

for i := 0; i < 5; i++ {
cfg := CandidateHostConfig{
Network: "udp",
Address: "192.168.0.2",
Port: 1000 + i,
Component: 1,
}

cand, errCand := NewCandidateHost(&cfg)
require.NoError(t, errCand)

err = agent.addCandidate(context.Background(), cand, dummyConn)
require.NoError(t, err)
}

actualCandidates, err := agent.GetLocalCandidates()
require.NoError(t, err)

for _, candidate := range actualCandidates {
ext, ok := candidate.GetExtension("ufrag")

require.True(t, ok)
require.Equal(t, agent.localUfrag, ext.Value)
}
}

0 comments on commit df554ef

Please sign in to comment.