mirror of
https://github.com/netbirdio/ice.git
synced 2026-05-22 17:10:58 -07:00
Handle candidate: prefix with UnmarshalCandidate
Make UnmarshalCandidate able to handle candidate: prefix in the candidate string.
This commit is contained in:
+3
-1
@@ -693,8 +693,10 @@ func (c *candidateBase) setExtensions(extensions []CandidateExtension) {
|
||||
// UnmarshalCandidate Parses a candidate from a string
|
||||
// https://datatracker.ietf.org/doc/html/rfc5245#section-15.1
|
||||
func UnmarshalCandidate(raw string) (Candidate, error) { //nolint:cyclop
|
||||
pos := 0
|
||||
// Handle candidates with the "candidate:" prefix as defined in RFC 5245 section 15.1.
|
||||
raw = strings.TrimPrefix(raw, "candidate:")
|
||||
|
||||
pos := 0
|
||||
// foundation ( 1*32ice-char ) But we allow for empty foundation,
|
||||
foundation, pos, err := readCandidateCharToken(raw, pos, 32)
|
||||
if err != nil {
|
||||
|
||||
+30
-1
@@ -6,6 +6,7 @@ package ice
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -465,6 +466,18 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
" 1 udp 500 " + localhostIPStr + " 80 typ host",
|
||||
false,
|
||||
},
|
||||
// Missing Foundation
|
||||
{
|
||||
mustCandidateHost(t, &CandidateHostConfig{
|
||||
Network: NetworkTypeUDP4.String(),
|
||||
Address: localhostIPStr,
|
||||
Port: 80,
|
||||
Priority: 500,
|
||||
Foundation: " ",
|
||||
}),
|
||||
"candidate: 1 udp 500 " + localhostIPStr + " 80 typ host",
|
||||
false,
|
||||
},
|
||||
{
|
||||
mustCandidateHost(t, &CandidateHostConfig{
|
||||
Network: NetworkTypeUDP4.String(),
|
||||
@@ -487,6 +500,17 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
"3359356140 1 tcp 1671430143 172.28.142.173 7686 typ host",
|
||||
false,
|
||||
},
|
||||
{
|
||||
mustCandidateHost(t, &CandidateHostConfig{
|
||||
Network: NetworkTypeTCP4.String(),
|
||||
Address: "172.28.142.173",
|
||||
Port: 7686,
|
||||
Priority: 1671430143,
|
||||
Foundation: "+/3713fhi",
|
||||
}),
|
||||
"candidate:3359356140 1 tcp 1671430143 172.28.142.173 7686 typ host",
|
||||
false,
|
||||
},
|
||||
|
||||
// Invalid candidates
|
||||
{nil, "", true},
|
||||
@@ -562,7 +586,12 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
test.candidate.String(),
|
||||
actualCandidate.String(),
|
||||
)
|
||||
require.Equal(t, test.marshaled, actualCandidate.Marshal())
|
||||
|
||||
if strings.HasPrefix(test.marshaled, "candidate:") {
|
||||
require.Equal(t, test.marshaled[len("candidate:"):], actualCandidate.Marshal())
|
||||
} else {
|
||||
require.Equal(t, test.marshaled, actualCandidate.Marshal())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user