Skip to content
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

fix:issue#1212 candidate with empty string #1584

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion icetransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (t *ICETransport) SetRemoteCandidates(remoteCandidates []ICECandidate) erro
}

// AddRemoteCandidate adds a candidate associated with the remote ICETransport.
func (t *ICETransport) AddRemoteCandidate(remoteCandidate ICECandidate) error {
func (t *ICETransport) AddRemoteCandidate(remoteCandidate *ICECandidate) error {
t.lock.RLock()
defer t.lock.RUnlock()

Expand Down
23 changes: 19 additions & 4 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
}
}

for _, c := range candidates {
if err = pc.iceTransport.AddRemoteCandidate(c); err != nil {
for i := range candidates {
if err = pc.iceTransport.AddRemoteCandidate(&candidates[i]); err != nil {
return err
}
}
Expand Down Expand Up @@ -1454,13 +1454,28 @@ func (pc *PeerConnection) RemoteDescription() *SessionDescription {
}

// AddICECandidate accepts an ICE candidate string and adds it
// to the existing set of candidates
// to the existing set of candidates.
// If ICE candidate string is empty, do not adds it to the existing
// set of candidates
func (pc *PeerConnection) AddICECandidate(candidate ICECandidateInit) error {
if pc.RemoteDescription() == nil {
return &rtcerr.InvalidStateError{Err: ErrNoRemoteDescription}
}

candidateValue := strings.TrimPrefix(candidate.Candidate, "candidate:")

if candidateValue == "" {
pc.iceTransport.lock.RLock()
defer pc.iceTransport.lock.RUnlock()

agent := pc.iceTransport.gatherer.getAgent()
if agent == nil {
return fmt.Errorf("%w: unable to add remote candidates", errICEAgentNotExist)
}
Comment on lines +1472 to +1474
Copy link
Member Author

Choose a reason for hiding this comment

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

Anyway, I can cover this by setting agent=nil in test?


return agent.AddRemoteCandidate(nil)
}

c, err := ice.UnmarshalCandidate(candidateValue)
if err != nil {
return err
Expand All @@ -1471,7 +1486,7 @@ func (pc *PeerConnection) AddICECandidate(candidate ICECandidateInit) error {
return err
}

return pc.iceTransport.AddRemoteCandidate(iceCandidate)
return pc.iceTransport.AddRemoteCandidate(&iceCandidate)
}

// ICEConnectionState returns the ICE connection state of the
Expand Down
37 changes: 37 additions & 0 deletions peerconnection_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,3 +1158,40 @@ func TestPeerConnection_MassiveTracks(t *testing.T) {
assert.NoError(t, offerPC.Close())
assert.NoError(t, answerPC.Close())
}

func TestEmptyCandidate(t *testing.T) {
testCases := []struct {
ICECandidate ICECandidateInit
expectError bool
}{
{ICECandidateInit{"", nil, nil, nil}, false},
{ICECandidateInit{
"211962667 1 udp 2122194687 10.0.3.1 40864 typ host generation 0",
nil, nil, nil,
}, false},
{ICECandidateInit{
"1234567",
nil, nil, nil,
}, true},
}

for i, testCase := range testCases {
peerConn, err := NewPeerConnection(Configuration{})
if err != nil {
t.Errorf("Case %d: got error: %v", i, err)
}

err = peerConn.SetRemoteDescription(SessionDescription{Type: SDPTypeOffer, SDP: minimalOffer})
if err != nil {
t.Errorf("Case %d: got error: %v", i, err)
}

if testCase.expectError {
assert.Error(t, peerConn.AddICECandidate(testCase.ICECandidate))
} else {
assert.NoError(t, peerConn.AddICECandidate(testCase.ICECandidate))
}

assert.NoError(t, peerConn.Close())
}
}