From d21eab3eea96925c4e1fab25402b5f6dd16032bb Mon Sep 17 00:00:00 2001 From: deadbeef Date: Wed, 26 Jul 2017 16:50:11 -0700 Subject: [PATCH] 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} --- webrtc/api/peerconnectioninterface.h | 7 +++ webrtc/pc/peerconnection.cc | 3 ++ webrtc/pc/peerconnectioninterface_unittest.cc | 50 ++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index 65c1278320..632fc3ca9f 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -352,6 +352,13 @@ class PeerConnectionInterface : public rtc::RefCountInterface { // 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 f006b23cbd..3af56671af 100644 --- a/webrtc/pc/peerconnection.cc +++ b/webrtc/pc/peerconnection.cc @@ -240,6 +240,7 @@ bool PeerConnectionInterface::RTCConfiguration::operator==( int ice_candidate_pool_size; bool disable_ipv6; bool disable_ipv6_on_wifi; + int max_ipv6_networks; bool enable_rtp_data_channel; rtc::Optional screencast_min_bitrate; rtc::Optional combined_audio_video_bwe; @@ -282,6 +283,7 @@ bool PeerConnectionInterface::RTCConfiguration::operator==( 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 @@ bool PeerConnection::InitializePortAllocator_n( 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 1a26a43522..114ffd75e2 100644 --- a/webrtc/pc/peerconnectioninterface_unittest.cc +++ b/webrtc/pc/peerconnectioninterface_unittest.cc @@ -1285,10 +1285,58 @@ TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { 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 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 pc_factory( + webrtc::CreatePeerConnectionFactory( + rtc::Thread::Current(), rtc::Thread::Current(), + rtc::Thread::Current(), nullptr, nullptr, nullptr)); + rtc::scoped_refptr 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 network_thread( rtc::Thread::CreateWithSocketServer()); network_thread->Start();