mirror of
https://github.com/livekit/livekit.git
synced 2026-08-28 02:54:12 +00:00
Only drop srflx if configured. (#3149)
This commit is contained in:
+15
-6
@@ -234,6 +234,8 @@ type PCTransport struct {
|
||||
|
||||
connectionDetails *types.ICEConnectionDetails
|
||||
selectedPair atomic.Pointer[webrtc.ICECandidatePair]
|
||||
|
||||
dropRemoteICECandidates bool
|
||||
}
|
||||
|
||||
type TransportParams struct {
|
||||
@@ -1415,7 +1417,7 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
||||
c := e.data.(*webrtc.ICECandidateInit)
|
||||
|
||||
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)
|
||||
filtered = true
|
||||
}
|
||||
@@ -1435,7 +1437,7 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
||||
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.connectionDetails.AddRemoteCandidate(*c, true, true, true)
|
||||
return nil
|
||||
@@ -1480,8 +1482,14 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription, preferTCP,
|
||||
}
|
||||
if liteSet && t.localICEIsLite != nil && t.remoteICEIsLite != nil {
|
||||
// only drop remote candidates if local is lite and remote is not
|
||||
t.params.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.dropRemoteICECandidates = t.params.DropRemoteICECandidates && (*t.localICEIsLite && !*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 {
|
||||
@@ -1494,7 +1502,7 @@ func (t *PCTransport) filterCandidates(sd webrtc.SessionDescription, preferTCP,
|
||||
filteredAttrs = append(filteredAttrs, a)
|
||||
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 !t.params.Config.UseMDNS && types.IsICECandidateMDNS(c) {
|
||||
excluded = true
|
||||
@@ -1712,7 +1720,8 @@ func (t *PCTransport) setRemoteDescription(sd webrtc.SessionDescription) error {
|
||||
}
|
||||
|
||||
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)
|
||||
continue
|
||||
}
|
||||
|
||||
+27
-27
@@ -506,39 +506,39 @@ func TestFilteringCandidates(t *testing.T) {
|
||||
}
|
||||
func TestDropRemoteICECandidates(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
remoteLite bool
|
||||
localLite bool
|
||||
expecteLocalDrop bool
|
||||
expecteRemoteDrop bool
|
||||
name string
|
||||
remoteLite bool
|
||||
localLite bool
|
||||
expectedLocalDrop bool
|
||||
expectedRemoteDrop bool
|
||||
}{
|
||||
{
|
||||
name: "both not lite",
|
||||
localLite: false,
|
||||
remoteLite: false,
|
||||
expecteLocalDrop: false,
|
||||
expecteRemoteDrop: false,
|
||||
name: "both not lite",
|
||||
localLite: false,
|
||||
remoteLite: false,
|
||||
expectedLocalDrop: false,
|
||||
expectedRemoteDrop: false,
|
||||
},
|
||||
{
|
||||
name: "remote lite",
|
||||
localLite: false,
|
||||
remoteLite: true,
|
||||
expecteLocalDrop: false,
|
||||
expecteRemoteDrop: true,
|
||||
name: "remote lite",
|
||||
localLite: false,
|
||||
remoteLite: true,
|
||||
expectedLocalDrop: false,
|
||||
expectedRemoteDrop: true,
|
||||
},
|
||||
{
|
||||
name: "local lite",
|
||||
localLite: true,
|
||||
remoteLite: false,
|
||||
expecteLocalDrop: true,
|
||||
expecteRemoteDrop: false,
|
||||
name: "local lite",
|
||||
localLite: true,
|
||||
remoteLite: false,
|
||||
expectedLocalDrop: true,
|
||||
expectedRemoteDrop: false,
|
||||
},
|
||||
{
|
||||
name: "both lite",
|
||||
localLite: true,
|
||||
remoteLite: true,
|
||||
expecteLocalDrop: false,
|
||||
expecteRemoteDrop: false,
|
||||
name: "both lite",
|
||||
localLite: true,
|
||||
remoteLite: true,
|
||||
expectedLocalDrop: false,
|
||||
expectedRemoteDrop: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -605,8 +605,8 @@ func TestDropRemoteICECandidates(t *testing.T) {
|
||||
return transportRemote.IsEstablished()
|
||||
}, 10*time.Second, time.Millisecond*10, "transportB is not established")
|
||||
|
||||
require.Equal(t, c.expecteLocalDrop, transportLocal.params.DropRemoteICECandidates)
|
||||
require.Equal(t, c.expecteRemoteDrop, transportRemote.params.DropRemoteICECandidates)
|
||||
require.Equal(t, c.expectedLocalDrop, transportLocal.dropRemoteICECandidates)
|
||||
require.Equal(t, c.expectedRemoteDrop, transportRemote.dropRemoteICECandidates)
|
||||
|
||||
transportLocal.Close()
|
||||
transportRemote.Close()
|
||||
|
||||
Reference in New Issue
Block a user