From 60f8b707e28482e9fe589cc13638c55e67fa4bc2 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Wed, 14 Aug 2024 14:50:58 -0400 Subject: [PATCH] Take TCP Family into account before connecting Before if a user disabled TCPv6 (but enabled TCPv4) we would incorrectly start TCP connections over TCPv6 still. Resolves pion/webrtc#2782 --- active_tcp_test.go | 2 +- agent.go | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/active_tcp_test.go b/active_tcp_test.go index ee8d1727..1e0cb0ff 100644 --- a/active_tcp_test.go +++ b/active_tcp_test.go @@ -244,7 +244,7 @@ func TestActiveTCP_Respect_NetworkTypes(t *testing.T) { }() cfg := &AgentConfig{ - NetworkTypes: []NetworkType{NetworkTypeUDP4, NetworkTypeUDP6}, + NetworkTypes: []NetworkType{NetworkTypeUDP4, NetworkTypeUDP6, NetworkTypeTCP6}, InterfaceFilter: problematicNetworkInterfaces, IncludeLoopback: true, } diff --git a/agent.go b/agent.go index a574dd12..fad036e4 100644 --- a/agent.go +++ b/agent.go @@ -704,14 +704,17 @@ func (a *Agent) addRemoteCandidate(c Candidate) { } } - tcpNetworkTypeFound := false - for _, networkType := range a.networkTypes { - if networkType.IsTCP() { - tcpNetworkTypeFound = true + acceptRemotePassiveTCPCandidate := false + // Assert that TCP4 or TCP6 is a enabled NetworkType locally + if !a.disableActiveTCP && c.TCPType() == TCPTypePassive { + for _, networkType := range a.networkTypes { + if c.NetworkType() == networkType { + acceptRemotePassiveTCPCandidate = true + } } } - if !a.disableActiveTCP && tcpNetworkTypeFound && c.TCPType() == TCPTypePassive { + if acceptRemotePassiveTCPCandidate { a.addRemotePassiveTCPCandidate(c) }