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 60f8b70
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

Check warning on line 707 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L707

Added line #L707 was not covered by tests
// 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

Check warning on line 712 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L709-L712

Added lines #L709 - L712 were not covered by tests
}
}
}

if !a.disableActiveTCP && tcpNetworkTypeFound && c.TCPType() == TCPTypePassive {
if acceptRemotePassiveTCPCandidate {

Check warning on line 717 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L717

Added line #L717 was not covered by tests
a.addRemotePassiveTCPCandidate(c)
}

Expand Down

0 comments on commit 60f8b70

Please sign in to comment.