From 5260907ffec9e0e6f8a30da0a787a2969d845bc5 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 19 May 2023 23:00:06 -0700 Subject: [PATCH] Disable active TCP (#1726) Active TCP was added in pion/ice v2.3.4. This is causing a couple of issues for us. Active TCP does not make sense for an SFU. Clients are expected to be behind NAT and we should not be dialing them. Instead, LiveKit exposes a TCP port so clients could dial in Active TCP is causing all iOS clients to become disconnected immediately. This is impacting all version of libwebrtc-based iOS clients (tested from M104 to M111) --- pkg/rtc/transport.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/rtc/transport.go b/pkg/rtc/transport.go index a2e88f9f2..0502c752b 100644 --- a/pkg/rtc/transport.go +++ b/pkg/rtc/transport.go @@ -1478,11 +1478,16 @@ func (t *PCTransport) handleLocalICECandidate(e *event) error { c := e.data.(*webrtc.ICECandidate) filtered := false - if t.preferTCP.Load() && c != nil && c.Protocol != webrtc.ICEProtocolTCP { - cstr := c.String() - t.params.Logger.Debugw("filtering out local candidate", "candidate", cstr) - t.filteredLocalCandidates = append(t.filteredLocalCandidates, cstr) - filtered = true + if c != nil { + if t.preferTCP.Load() && c.Protocol != webrtc.ICEProtocolTCP { + cstr := c.String() + t.params.Logger.Debugw("filtering out local candidate", "candidate", cstr) + t.filteredLocalCandidates = append(t.filteredLocalCandidates, cstr) + filtered = true + } else if c.Protocol == webrtc.ICEProtocolTCP && c.TCPType == ice.TCPTypeActive.String() { + // SFU should not support TCP active candidates. clients should connect to us + filtered = true + } } if filtered { @@ -1512,6 +1517,11 @@ func (t *PCTransport) handleRemoteICECandidate(e *event) error { t.params.Logger.Debugw("filtering out remote candidate", "candidate", c.Candidate) t.filteredRemoteCandidates = append(t.filteredRemoteCandidates, c.Candidate) filtered = true + } else if candidate, err := ice.UnmarshalCandidate(c.Candidate); err == nil { + if candidate != nil && candidate.TCPType() == ice.TCPTypePassive { + // SFU should ignore client's passive TCP, so Pion doesn't attempt to connect to it + filtered = true + } } if filtered {