Add "max_ipv6_networks" field to RTCConfiguration.
This allows an application to easily override the default limit
(currently 5).
Also adding a test that covers more of the
PeerConnection<->PortAllocator interaction.
BUG=webrtc:7703
Review-Url: https://codereview.webrtc.org/2985653003
Cr-Commit-Position: refs/heads/master@{#19160}
diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h
index 65c1278..632fc3c 100644
--- a/webrtc/api/peerconnectioninterface.h
+++ b/webrtc/api/peerconnectioninterface.h
@@ -352,6 +352,13 @@
// IPv6 ICE candidates on Wi-Fi in those cases.
bool disable_ipv6_on_wifi = false;
+ // By default, the PeerConnection will use a limited number of IPv6 network
+ // interfaces, in order to avoid too many ICE candidate pairs being created
+ // and delaying ICE completion.
+ //
+ // Can be set to INT_MAX to effectively disable the limit.
+ int max_ipv6_networks = cricket::kDefaultMaxIPv6Networks;
+
// If set to true, use RTP data channels instead of SCTP.
// TODO(deadbeef): Remove this. We no longer commit to supporting RTP data
// channels, though some applications are still working on moving off of
diff --git a/webrtc/pc/peerconnection.cc b/webrtc/pc/peerconnection.cc
index f006b23..3af5667 100644
--- a/webrtc/pc/peerconnection.cc
+++ b/webrtc/pc/peerconnection.cc
@@ -240,6 +240,7 @@
int ice_candidate_pool_size;
bool disable_ipv6;
bool disable_ipv6_on_wifi;
+ int max_ipv6_networks;
bool enable_rtp_data_channel;
rtc::Optional<int> screencast_min_bitrate;
rtc::Optional<bool> combined_audio_video_bwe;
@@ -282,6 +283,7 @@
o.prioritize_most_likely_ice_candidate_pairs &&
media_config == o.media_config && disable_ipv6 == o.disable_ipv6 &&
disable_ipv6_on_wifi == o.disable_ipv6_on_wifi &&
+ max_ipv6_networks == o.max_ipv6_networks &&
enable_rtp_data_channel == o.enable_rtp_data_channel &&
enable_quic == o.enable_quic &&
screencast_min_bitrate == o.screencast_min_bitrate &&
@@ -2400,6 +2402,7 @@
port_allocator_->set_step_delay(cricket::kMinimumStepDelay);
port_allocator_->set_candidate_filter(
ConvertIceTransportTypeToCandidateFilter(configuration.type));
+ port_allocator_->set_max_ipv6_networks(configuration.max_ipv6_networks);
// Call this last since it may create pooled allocator sessions using the
// properties set above.
diff --git a/webrtc/pc/peerconnectioninterface_unittest.cc b/webrtc/pc/peerconnectioninterface_unittest.cc
index 1a26a43..114ffd7 100644
--- a/webrtc/pc/peerconnectioninterface_unittest.cc
+++ b/webrtc/pc/peerconnectioninterface_unittest.cc
@@ -1285,10 +1285,58 @@
session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
}
+// Test that network-related RTCConfiguration members are applied to the
+// PortAllocator when CreatePeerConnection is called. Specifically:
+// - disable_ipv6_on_wifi
+// - max_ipv6_networks
+// - tcp_candidate_policy
+// - candidate_network_policy
+// - prune_turn_ports
+//
+// Note that the candidate filter (RTCConfiguration::type) is already tested
+// above.
+TEST_F(PeerConnectionInterfaceTest,
+ CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
+ // Create fake port allocator.
+ std::unique_ptr<cricket::FakePortAllocator> port_allocator(
+ new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
+ cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
+
+ // Create RTCConfiguration with some network-related fields relevant to
+ // PortAllocator populated.
+ PeerConnectionInterface::RTCConfiguration config;
+ config.disable_ipv6_on_wifi = true;
+ config.max_ipv6_networks = 10;
+ config.tcp_candidate_policy =
+ PeerConnectionInterface::kTcpCandidatePolicyDisabled;
+ config.candidate_network_policy =
+ PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
+ config.prune_turn_ports = true;
+
+ // Create the PC factory and PC with the above config.
+ rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
+ webrtc::CreatePeerConnectionFactory(
+ rtc::Thread::Current(), rtc::Thread::Current(),
+ rtc::Thread::Current(), nullptr, nullptr, nullptr));
+ rtc::scoped_refptr<PeerConnectionInterface> pc(
+ pc_factory->CreatePeerConnection(
+ config, nullptr, std::move(port_allocator), nullptr, &observer_));
+
+ // Now validate that the config fields set above were applied to the
+ // PortAllocator, as flags or otherwise.
+ EXPECT_FALSE(raw_port_allocator->flags() &
+ cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
+ EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
+ EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
+ EXPECT_TRUE(raw_port_allocator->flags() &
+ cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
+ EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
+}
+
// Test that the PeerConnection initializes the port allocator passed into it,
// and on the correct thread.
TEST_F(PeerConnectionInterfaceTest,
- CreatePeerConnectionInitializesPortAllocator) {
+ CreatePeerConnectionInitializesPortAllocatorOnNetworkThread) {
std::unique_ptr<rtc::Thread> network_thread(
rtc::Thread::CreateWithSocketServer());
network_thread->Start();