Skip to content

Commit

Permalink
Take TCP Family into account before connecting
Browse files Browse the repository at this point in the history
Before if a user disabled TCPv6 (but enabled TCPv4) we would incorrectly
start TCP connections over TCPv6 still.

Resolves pion/webrtc#2782
  • Loading branch information
Sean-Der committed Aug 14, 2024
1 parent 5dfb91f commit 5d9b189
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion active_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
13 changes: 8 additions & 5 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 5d9b189

Please sign in to comment.