Skip to content

Commit

Permalink
Update ice-lite remote check to ignore whitespace
Browse files Browse the repository at this point in the history
When parsing SDP, ice-lite attributes with whitespaces
were parsed incorrectly. This fix trims whitespaces.
  • Loading branch information
donotanswer authored and Sean-Der committed Feb 19, 2021
1 parent 11ee5d5 commit 8e85670
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
* [Cameron Elliott](https://github.com/cameronelliott)
* [Pascal Benoit](https://github.com/pascal-ace)
* [Mats](https://github.com/Mindgamesnl)
* [donotanswer](https://github.com/f-viktor)

### License
MIT License - see [LICENSE](LICENSE) for full text
6 changes: 4 additions & 2 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,10 @@ func (pc *PeerConnection) SetRemoteDescription(desc SessionDescription) error {
}

remoteIsLite := false
if liteValue, haveRemoteIs := desc.parsed.Attribute(sdp.AttrKeyICELite); haveRemoteIs && liteValue == sdp.AttrKeyICELite {
remoteIsLite = true
for _, a := range desc.parsed.Attributes {
if strings.TrimSpace(a.Key) == sdp.AttrKeyICELite {
remoteIsLite = true
}
}

fingerprint, fingerprintHash, err := extractFingerprint(desc.parsed)
Expand Down
35 changes: 35 additions & 0 deletions peerconnection_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,3 +1193,38 @@ func TestEmptyCandidate(t *testing.T) {
assert.NoError(t, peerConn.Close())
}
}

const liteOffer = `v=0
o=- 4596489990601351948 2 IN IP4 127.0.0.1
s=-
t=0 0
a=msid-semantic: WMS
a=ice-lite
m=application 47299 DTLS/SCTP 5000
c=IN IP4 192.168.20.129
a=ice-ufrag:1/MvHwjAyVf27aLu
a=ice-pwd:3dBU7cFOBl120v33cynDvN1E
a=fingerprint:sha-256 75:74:5A:A6:A4:E5:52:F4:A7:67:4C:01:C7:EE:91:3F:21:3D:A2:E3:53:7B:6F:30:86:F2:30:AA:65:FB:04:24
a=mid:data
`

// this test asserts that if an ice-lite offer is received,
// pion will take the ICE-CONTROLLING role
func TestICELite(t *testing.T) {
peerConnection, err := NewPeerConnection(Configuration{})
assert.NoError(t, err)

assert.NoError(t, peerConnection.SetRemoteDescription(
SessionDescription{SDP: liteOffer, Type: SDPTypeOffer},
))

SDPAnswer, err := peerConnection.CreateAnswer(nil)
assert.NoError(t, err)

assert.NoError(t, peerConnection.SetLocalDescription(SDPAnswer))

assert.Equal(t, ICERoleControlling, peerConnection.iceTransport.role,
"pion did not set state to ICE-CONTROLLED against ice-light offer")

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

0 comments on commit 8e85670

Please sign in to comment.