mirror of
https://github.com/netbirdio/ice-old.git
synced 2026-05-22 17:08:24 -07:00
Support parsing candidates with missing Foundation
Not RFC 8445 compliant but are currently emitted by Google. Resolves #390
This commit is contained in:
+12
-3
@@ -393,8 +393,13 @@ func (c *candidateBase) copy() (Candidate, error) {
|
||||
|
||||
// Marshal returns the string representation of the ICECandidate
|
||||
func (c *candidateBase) Marshal() string {
|
||||
val := fmt.Sprintf("%s %d %s %d %s %d typ %s",
|
||||
c.Foundation(),
|
||||
val := c.Foundation()
|
||||
if val == " " {
|
||||
val = ""
|
||||
}
|
||||
|
||||
val = fmt.Sprintf("%s %d %s %d %s %d typ %s",
|
||||
val,
|
||||
c.Component(),
|
||||
c.NetworkType().NetworkShort(),
|
||||
c.Priority(),
|
||||
@@ -419,7 +424,11 @@ func (c *candidateBase) Marshal() string {
|
||||
// UnmarshalCandidate creates a Candidate from its string representation
|
||||
func UnmarshalCandidate(raw string) (Candidate, error) {
|
||||
split := strings.Fields(raw)
|
||||
if len(split) < 8 {
|
||||
switch {
|
||||
// Foundation not specified: not RFC 8445 compliant but seen in the wild
|
||||
case len(split) == 7 && raw[0] == ' ':
|
||||
split = append([]string{" "}, split...)
|
||||
case len(split) < 8:
|
||||
return nil, fmt.Errorf("%w (%d)", errAttributeTooShortICECandidate, len(split))
|
||||
}
|
||||
|
||||
|
||||
@@ -294,6 +294,22 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
},
|
||||
"1380287402 1 udp 2130706431 e2494022-4d9a-4c1e-a750-cc48d4f8d6ee.local 60542 typ host", false,
|
||||
},
|
||||
// Missing Foundation
|
||||
{
|
||||
&CandidateHost{
|
||||
candidateBase{
|
||||
networkType: NetworkTypeUDP4,
|
||||
candidateType: CandidateTypeHost,
|
||||
address: "127.0.0.1",
|
||||
port: 80,
|
||||
priorityOverride: 500,
|
||||
foundationOverride: " ",
|
||||
},
|
||||
"",
|
||||
},
|
||||
" 1 udp 500 127.0.0.1 80 typ host",
|
||||
false,
|
||||
},
|
||||
|
||||
// Invalid candidates
|
||||
{nil, "", true},
|
||||
@@ -321,3 +337,10 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
assert.Equal(t, test.marshaled, actualCandidate.Marshal())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingCandidateFoundation(t *testing.T) {
|
||||
// " 1 udp 2113939711 2607:f8b0:400e:c0a::7f 19305 typ host generation 0"
|
||||
// " 1 tcp 2113939710 2607:f8b0:400e:c0a::7f 19305 typ host tcptype passive generation 0"
|
||||
// " 1 udp 2113932031 172.253.117.127 19305 typ host generation 0"
|
||||
// " 1 tcp 2113932030 172.253.117.127 19305 typ host tcptype passive generation 0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user