Only drop srflx if configured. (#3149)
This commit is contained in:
+15
-6
@@ -234,6 +234,8 @@ type PCTransport struct {
|
|||||||
|
|
||||||
connectionDetails *types.ICEConnectionDetails
|
connectionDetails *types.ICEConnectionDetails
|
||||||
selectedPair atomic.Pointer[webrtc.ICECandidatePair]
|
selectedPair atomic.Pointer[webrtc.ICECandidatePair]
|
||||||
|
|
||||||
|
dropRemoteICECandidates bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransportParams struct {
|
type TransportParams struct {
|
||||||
@@ -1415,7 +1417,7 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
|||||||
c := e.data.(*webrtc.ICECandidateInit)
|
c := e.data.(*webrtc.ICECandidateInit)
|
||||||
|
|
||||||
filtered := false
|
filtered := false
|
||||||
if t.preferTCP.Load() && !strings.Contains(c.Candidate, "tcp") {
|
if t.preferTCP.Load() && !strings.Contains(strings.ToLower(c.Candidate), "tcp") {
|
||||||
t.params.Logger.Debugw("filtering out remote candidate", "candidate", c.Candidate)
|
t.params.Logger.Debugw("filtering out remote candidate", "candidate", c.Candidate)
|
||||||
filtered = true
|
filtered = true
|
||||||
}
|
}
|
||||||
@@ -1435,7 +1437,7 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.params.DropRemoteICECandidates {
|
if t.dropRemoteICECandidates && strings.Contains(strings.ToLower(c.Candidate), "srflx") {
|
||||||
t.params.Logger.Debugw("dropping remote ICE candidate", "candidate", c.Candidate)
|
t.params.Logger.Debugw("dropping remote ICE candidate", "candidate", c.Candidate)
|
||||||
t.connectionDetails.AddRemoteCandidate(*c, true, true, true)
|
t.connectionDetails.AddRemoteCandidate(*c, true, true, true)
|
||||||
return nil
|
return nil
|
||||||
@@ -1480,8 +1482,14 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription, preferTCP,
|
|||||||
}
|
}
|
||||||
if liteSet && t.localICEIsLite != nil && t.remoteICEIsLite != nil {
|
if liteSet && t.localICEIsLite != nil && t.remoteICEIsLite != nil {
|
||||||
// only drop remote candidates if local is lite and remote is not
|
// only drop remote candidates if local is lite and remote is not
|
||||||
t.params.DropRemoteICECandidates = t.params.DropRemoteICECandidates && (*t.localICEIsLite && !*t.remoteICEIsLite)
|
t.dropRemoteICECandidates = t.params.DropRemoteICECandidates && (*t.localICEIsLite && !*t.remoteICEIsLite)
|
||||||
t.params.Logger.Debugw("setting DropRemoteICECandidates", "dropRemoteCandidate", t.params.DropRemoteICECandidates, "localICELite", *t.localICEIsLite, "remoteICELite", *t.remoteICEIsLite)
|
t.params.Logger.Debugw(
|
||||||
|
"setting DropRemoteICECandidates",
|
||||||
|
"dropRemoteICECandidatesConfig", t.params.DropRemoteICECandidates,
|
||||||
|
"dropRemoteICECandidatesCalculated", t.dropRemoteICECandidates,
|
||||||
|
"localICELite", *t.localICEIsLite,
|
||||||
|
"remoteICELite", *t.remoteICEIsLite,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
filterAttributes := func(attrs []sdp.Attribute) []sdp.Attribute {
|
filterAttributes := func(attrs []sdp.Attribute) []sdp.Attribute {
|
||||||
@@ -1494,7 +1502,7 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription, preferTCP,
|
|||||||
filteredAttrs = append(filteredAttrs, a)
|
filteredAttrs = append(filteredAttrs, a)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
excluded := (!isLocal && t.params.DropRemoteICECandidates) || (preferTCP && !c.NetworkType().IsTCP())
|
excluded := (!isLocal && t.dropRemoteICECandidates && c.Type() == ice.CandidateTypeServerReflexive) || (preferTCP && !c.NetworkType().IsTCP())
|
||||||
if !excluded {
|
if !excluded {
|
||||||
if !t.params.Config.UseMDNS && types.IsICECandidateMDNS(c) {
|
if !t.params.Config.UseMDNS && types.IsICECandidateMDNS(c) {
|
||||||
excluded = true
|
excluded = true
|
||||||
@@ -1712,7 +1720,8 @@ func (t *PCTransport) setRemoteDescription(sd webrtc.SessionDescription) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range t.pendingRemoteCandidates {
|
for _, c := range t.pendingRemoteCandidates {
|
||||||
if t.params.DropRemoteICECandidates {
|
if t.dropRemoteICECandidates && strings.Contains(strings.ToLower(c.Candidate), "srflx") {
|
||||||
|
t.params.Logger.Debugw("dropping remote ICE candidate (pending)", "candidate", c.Candidate)
|
||||||
t.connectionDetails.AddRemoteCandidate(*c, true, true, true)
|
t.connectionDetails.AddRemoteCandidate(*c, true, true, true)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -509,36 +509,36 @@ func TestDropRemoteICECandidates(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
remoteLite bool
|
remoteLite bool
|
||||||
localLite bool
|
localLite bool
|
||||||
expecteLocalDrop bool
|
expectedLocalDrop bool
|
||||||
expecteRemoteDrop bool
|
expectedRemoteDrop bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "both not lite",
|
name: "both not lite",
|
||||||
localLite: false,
|
localLite: false,
|
||||||
remoteLite: false,
|
remoteLite: false,
|
||||||
expecteLocalDrop: false,
|
expectedLocalDrop: false,
|
||||||
expecteRemoteDrop: false,
|
expectedRemoteDrop: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "remote lite",
|
name: "remote lite",
|
||||||
localLite: false,
|
localLite: false,
|
||||||
remoteLite: true,
|
remoteLite: true,
|
||||||
expecteLocalDrop: false,
|
expectedLocalDrop: false,
|
||||||
expecteRemoteDrop: true,
|
expectedRemoteDrop: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "local lite",
|
name: "local lite",
|
||||||
localLite: true,
|
localLite: true,
|
||||||
remoteLite: false,
|
remoteLite: false,
|
||||||
expecteLocalDrop: true,
|
expectedLocalDrop: true,
|
||||||
expecteRemoteDrop: false,
|
expectedRemoteDrop: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "both lite",
|
name: "both lite",
|
||||||
localLite: true,
|
localLite: true,
|
||||||
remoteLite: true,
|
remoteLite: true,
|
||||||
expecteLocalDrop: false,
|
expectedLocalDrop: false,
|
||||||
expecteRemoteDrop: false,
|
expectedRemoteDrop: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,8 +605,8 @@ func TestDropRemoteICECandidates(t *testing.T) {
|
|||||||
return transportRemote.IsEstablished()
|
return transportRemote.IsEstablished()
|
||||||
}, 10*time.Second, time.Millisecond*10, "transportB is not established")
|
}, 10*time.Second, time.Millisecond*10, "transportB is not established")
|
||||||
|
|
||||||
require.Equal(t, c.expecteLocalDrop, transportLocal.params.DropRemoteICECandidates)
|
require.Equal(t, c.expectedLocalDrop, transportLocal.dropRemoteICECandidates)
|
||||||
require.Equal(t, c.expecteRemoteDrop, transportRemote.params.DropRemoteICECandidates)
|
require.Equal(t, c.expectedRemoteDrop, transportRemote.dropRemoteICECandidates)
|
||||||
|
|
||||||
transportLocal.Close()
|
transportLocal.Close()
|
||||||
transportRemote.Close()
|
transportRemote.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user