Properly exclude mDNS when not trickling also. (#2956)

This commit is contained in:
Raja Subramanian
2024-08-24 23:23:23 +05:30
committed by GitHub
parent 7cce1917ad
commit 56e67c9d25
2 changed files with 25 additions and 13 deletions
+10 -13
View File
@@ -706,19 +706,6 @@ func (t *PCTransport) SetPreferTCP(preferTCP bool) {
}
func (t *PCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) {
if !t.params.Config.UseMDNS {
candidateValue := strings.TrimPrefix(candidate.Candidate, "candidate:")
if candidateValue != "" {
candidate, err := ice.UnmarshalCandidate(candidateValue)
if err != nil {
t.params.Logger.Errorw("failed to parse ice candidate", err)
} else if strings.HasSuffix(candidate.Address(), ".local") {
t.params.Logger.Debugw("ignoring mDNS candidate", "candidate", candidateValue)
return
}
}
}
t.postEvent(event{
signal: signalRemoteICECandidate,
data: &candidate,
@@ -1395,6 +1382,11 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error {
filtered = true
}
if !t.params.Config.UseMDNS && types.IsCandidateMDNS(*c) {
t.params.Logger.Debugw("ignoring mDNS candidate", "candidate", c.Candidate)
filtered = true
}
t.connectionDetails.AddRemoteCandidate(*c, filtered, true)
if filtered {
return nil
@@ -1440,6 +1432,11 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription, preferTCP,
continue
}
excluded := preferTCP && !c.NetworkType().IsTCP()
if !excluded {
if !t.params.Config.UseMDNS && types.IsICECandidateMDNS(c) {
excluded = true
}
}
if !excluded {
filteredAttrs = append(filteredAttrs, a)
}
+15
View File
@@ -224,6 +224,8 @@ func (d *ICEConnectionDetails) SetSelectedPair(pair *webrtc.ICECandidatePair) {
}
}
// -------------------------------------------------------------
func isCandidateEqualTo(c1, c2 *webrtc.ICECandidate) bool {
if c1 == nil && c2 == nil {
return true
@@ -332,3 +334,16 @@ func unmarshalCandidate(i ice.Candidate) (*webrtc.ICECandidate, error) {
return &c, nil
}
func IsCandidateMDNS(candidate webrtc.ICECandidateInit) bool {
c, err := unmarshalICECandidate(candidate)
if err != nil {
return false
}
return IsICECandidateMDNS(c)
}
func IsICECandidateMDNS(candidate ice.Candidate) bool {
return strings.HasSuffix(candidate.Address(), ".local")
}