diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index 082f4853b2..1203972010 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -157,6 +157,7 @@ cricket::Candidate CreateUdpCandidate(const std::string& type, cricket::BasicPortAllocator* CreateBasicPortAllocator( rtc::NetworkManager* network_manager, + rtc::SocketServer* socket_server, const cricket::ServerAddresses& stun_servers, const rtc::SocketAddress& turn_server_udp, const rtc::SocketAddress& turn_server_tcp) { @@ -172,11 +173,13 @@ cricket::BasicPortAllocator* CreateBasicPortAllocator( } std::vector turn_servers(1, turn_server); - cricket::BasicPortAllocator* allocator = - new cricket::BasicPortAllocator(network_manager); + std::unique_ptr allocator = + std::make_unique( + network_manager, + std::make_unique(socket_server)); allocator->Initialize(); allocator->SetConfiguration(stun_servers, turn_servers, 0, webrtc::NO_PRUNE); - return allocator; + return allocator.release(); } class MockIceControllerFactory : public cricket::IceControllerFactoryInterface { @@ -280,12 +283,12 @@ class P2PTransportChannelTestBase : public ::testing::Test, ServerAddresses stun_servers; stun_servers.insert(kStunAddr); - ep1_.allocator_.reset( - CreateBasicPortAllocator(&ep1_.network_manager_, stun_servers, - kTurnUdpIntAddr, rtc::SocketAddress())); - ep2_.allocator_.reset( - CreateBasicPortAllocator(&ep2_.network_manager_, stun_servers, - kTurnUdpIntAddr, rtc::SocketAddress())); + ep1_.allocator_.reset(CreateBasicPortAllocator( + &ep1_.network_manager_, ss_.get(), stun_servers, kTurnUdpIntAddr, + rtc::SocketAddress())); + ep2_.allocator_.reset(CreateBasicPortAllocator( + &ep2_.network_manager_, ss_.get(), stun_servers, kTurnUdpIntAddr, + rtc::SocketAddress())); webrtc::metrics::Reset(); } @@ -4915,7 +4918,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest kTurnUdpExtAddr) { network_manager_.AddInterface(kPublicAddrs[0]); allocator_.reset( - CreateBasicPortAllocator(&network_manager_, ServerAddresses(), + CreateBasicPortAllocator(&network_manager_, ss(), ServerAddresses(), kTurnUdpIntAddr, rtc::SocketAddress())); allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_TCP); diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc index f4306f1798..3a1488e66b 100644 --- a/p2p/client/basic_port_allocator.cc +++ b/p2p/client/basic_port_allocator.cc @@ -165,23 +165,35 @@ BasicPortAllocator::BasicPortAllocator( Init(relay_port_factory, nullptr); RTC_DCHECK(relay_port_factory_ != nullptr); RTC_DCHECK(network_manager_ != nullptr); - RTC_DCHECK(socket_factory_ != nullptr); + RTC_CHECK(socket_factory_ != nullptr); SetConfiguration(ServerAddresses(), std::vector(), 0, webrtc::NO_PRUNE, customizer); } -BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) - : network_manager_(network_manager), socket_factory_(nullptr) { +BasicPortAllocator::BasicPortAllocator( + rtc::NetworkManager* network_manager, + std::unique_ptr owned_socket_factory) + : network_manager_(network_manager), + socket_factory_(std::move(owned_socket_factory)) { Init(nullptr, nullptr); RTC_DCHECK(relay_port_factory_ != nullptr); RTC_DCHECK(network_manager_ != nullptr); + RTC_CHECK(socket_factory_ != nullptr); } -BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, - const ServerAddresses& stun_servers) - : BasicPortAllocator(network_manager, - /*socket_factory=*/nullptr, - stun_servers) {} +BasicPortAllocator::BasicPortAllocator( + rtc::NetworkManager* network_manager, + std::unique_ptr owned_socket_factory, + const ServerAddresses& stun_servers) + : network_manager_(network_manager), + socket_factory_(std::move(owned_socket_factory)) { + Init(nullptr, nullptr); + RTC_DCHECK(relay_port_factory_ != nullptr); + RTC_DCHECK(network_manager_ != nullptr); + RTC_CHECK(socket_factory_ != nullptr); + SetConfiguration(stun_servers, std::vector(), 0, + webrtc::NO_PRUNE, nullptr); +} BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, rtc::PacketSocketFactory* socket_factory, @@ -190,6 +202,7 @@ BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, Init(nullptr, nullptr); RTC_DCHECK(relay_port_factory_ != nullptr); RTC_DCHECK(network_manager_ != nullptr); + RTC_CHECK(socket_factory_ != nullptr); SetConfiguration(stun_servers, std::vector(), 0, webrtc::NO_PRUNE, nullptr); } @@ -394,11 +407,6 @@ void BasicPortAllocatorSession::SetCandidateFilter(uint32_t filter) { void BasicPortAllocatorSession::StartGettingPorts() { RTC_DCHECK_RUN_ON(network_thread_); state_ = SessionState::GATHERING; - if (!socket_factory_) { - owned_socket_factory_.reset( - new rtc::BasicPacketSocketFactory(network_thread_->socketserver())); - socket_factory_ = owned_socket_factory_.get(); - } network_thread_->PostTask(webrtc::ToQueuedTask( network_safety_, [this] { GetPortConfigurations(); })); diff --git a/p2p/client/basic_port_allocator.h b/p2p/client/basic_port_allocator.h index 01d07e76b3..048b52749a 100644 --- a/p2p/client/basic_port_allocator.h +++ b/p2p/client/basic_port_allocator.h @@ -21,6 +21,7 @@ #include "p2p/client/relay_port_factory_interface.h" #include "p2p/client/turn_port_factory.h" #include "rtc_base/checks.h" +#include "rtc_base/memory/always_valid_pointer.h" #include "rtc_base/network.h" #include "rtc_base/system/rtc_export.h" #include "rtc_base/task_utils/pending_task_safety_flag.h" @@ -32,18 +33,19 @@ namespace cricket { class RTC_EXPORT BasicPortAllocator : public PortAllocator { public: // The NetworkManager is a mandatory argument. The other arguments are - // optional. All these objects are owned by caller and must have a life time + // optional. All pointers are owned by caller and must have a life time // that exceeds that of BasicPortAllocator. - // TODO(bugs.webrtc.org/13145): The SocketFactory should be mandatory, but - // currenly isn't. When not specified, one is created internally, based on the - // socket server associated with the thread calling CreateSession. BasicPortAllocator(rtc::NetworkManager* network_manager, rtc::PacketSocketFactory* socket_factory, webrtc::TurnCustomizer* customizer = nullptr, RelayPortFactoryInterface* relay_port_factory = nullptr); - explicit BasicPortAllocator(rtc::NetworkManager* network_manager); - BasicPortAllocator(rtc::NetworkManager* network_manager, - const ServerAddresses& stun_servers); + BasicPortAllocator( + rtc::NetworkManager* network_manager, + std::unique_ptr owned_socket_factory); + BasicPortAllocator( + rtc::NetworkManager* network_manager, + std::unique_ptr owned_socket_factory, + const ServerAddresses& stun_servers); BasicPortAllocator(rtc::NetworkManager* network_manager, rtc::PacketSocketFactory* socket_factory, const ServerAddresses& stun_servers); @@ -62,7 +64,7 @@ class RTC_EXPORT BasicPortAllocator : public PortAllocator { // creates its own socket factory. rtc::PacketSocketFactory* socket_factory() { CheckRunOnValidThreadIfInitialized(); - return socket_factory_; + return socket_factory_.get(); } PortAllocatorSession* CreateSessionInternal( @@ -97,7 +99,8 @@ class RTC_EXPORT BasicPortAllocator : public PortAllocator { const webrtc::FieldTrialsView* field_trials_; std::unique_ptr owned_field_trials_; rtc::NetworkManager* network_manager_; - rtc::PacketSocketFactory* socket_factory_; + const webrtc::AlwaysValidPointerNoDefault + socket_factory_; int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask; // This is the factory being used. @@ -273,7 +276,6 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession { BasicPortAllocator* allocator_; rtc::Thread* network_thread_; - std::unique_ptr owned_socket_factory_; rtc::PacketSocketFactory* socket_factory_; bool allocation_started_; bool network_manager_started_; diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc index aa04b78855..8fc40a6c3a 100644 --- a/p2p/client/basic_port_allocator_unittest.cc +++ b/p2p/client/basic_port_allocator_unittest.cc @@ -161,8 +161,10 @@ class BasicPortAllocatorTestBase : public ::testing::Test, ServerAddresses stun_servers; stun_servers.insert(kStunAddr); - allocator_ = - std::make_unique(&network_manager_, stun_servers); + allocator_ = std::make_unique( + &network_manager_, + std::make_unique(fss_.get()), + stun_servers); allocator_->Initialize(); allocator_->set_step_delay(kMinimumStepDelay); webrtc::metrics::Reset(); @@ -199,7 +201,9 @@ class BasicPortAllocatorTestBase : public ::testing::Test, } // Endpoint is on the public network. No STUN or TURN. void ResetWithNoServersOrNat() { - allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator( + &network_manager_, + std::make_unique(fss_.get()))); allocator_->Initialize(); allocator_->set_step_delay(kMinimumStepDelay); } @@ -578,7 +582,9 @@ class BasicPortAllocatorTest : public FakeClockBase, // Add two IP addresses on the same interface. AddInterface(kClientAddr, "net1"); AddInterface(kClientIPv6Addr, "net1"); - allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator( + &network_manager_, + std::make_unique(fss_.get()))); allocator_->Initialize(); allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), 0, @@ -619,7 +625,9 @@ class BasicPortAllocatorTest : public FakeClockBase, bool tcp_pruned) { turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); - allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator( + &network_manager_, + std::make_unique(fss_.get()))); allocator_->Initialize(); allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), 0, prune_policy); @@ -671,7 +679,9 @@ class BasicPortAllocatorTest : public FakeClockBase, AddInterface(kClientIPv6Addr, "net1", rtc::ADAPTER_TYPE_WIFI); AddInterface(kClientAddr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); AddInterface(kClientIPv6Addr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); - allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator( + &network_manager_, + std::make_unique(fss_.get()))); allocator_->Initialize(); allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), 0, @@ -1637,7 +1647,9 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); - allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator( + &network_manager_, + std::make_unique(fss_.get()))); allocator_->Initialize(); AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); @@ -1772,7 +1784,9 @@ TEST_F(BasicPortAllocatorTestWithRealClock, turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), PROTO_UDP); AddInterface(kClientAddr); - allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator( + &network_manager_, + std::make_unique(fss_.get()))); allocator_->Initialize(); RelayServerConfig turn_server; RelayCredentials credentials(kTurnUsername, kTurnPassword); diff --git a/pc/peer_connection_bundle_unittest.cc b/pc/peer_connection_bundle_unittest.cc index fed4930f43..ad3d118510 100644 --- a/pc/peer_connection_bundle_unittest.cc +++ b/pc/peer_connection_bundle_unittest.cc @@ -224,8 +224,9 @@ class PeerConnectionBundleBaseTest : public ::testing::Test { WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { auto* fake_network = NewFakeNetwork(); - auto port_allocator = - std::make_unique(fake_network); + auto port_allocator = std::make_unique( + fake_network, + std::make_unique(vss_.get())); port_allocator->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY); port_allocator->set_step_delay(cricket::kMinimumStepDelay); diff --git a/pc/peer_connection_histogram_unittest.cc b/pc/peer_connection_histogram_unittest.cc index 4a3c6794c4..da2ff40190 100644 --- a/pc/peer_connection_histogram_unittest.cc +++ b/pc/peer_connection_histogram_unittest.cc @@ -270,7 +270,9 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { fake_network->AddInterface(NextLocalAddress()); std::unique_ptr port_allocator( - new cricket::BasicPortAllocator(fake_network)); + new cricket::BasicPortAllocator( + fake_network, + std::make_unique(vss_.get()))); deps.async_resolver_factory = std::move(resolver_factory); deps.allocator = std::move(port_allocator); @@ -292,8 +294,9 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(kPrivateLocalAddress); - auto port_allocator = - std::make_unique(fake_network); + auto port_allocator = std::make_unique( + fake_network, + std::make_unique(vss_.get())); RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; return CreatePeerConnection(config, @@ -306,8 +309,9 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(kPrivateIpv6LocalAddress); - auto port_allocator = - std::make_unique(fake_network); + auto port_allocator = std::make_unique( + fake_network, + std::make_unique(vss_.get())); RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; @@ -339,8 +343,9 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { if (!deps.allocator) { auto fake_network = NewFakeNetwork(); fake_network->AddInterface(NextLocalAddress()); - deps.allocator = - std::make_unique(fake_network); + deps.allocator = std::make_unique( + fake_network, + std::make_unique(vss_.get())); } auto observer = std::make_unique(); diff --git a/pc/peer_connection_ice_unittest.cc b/pc/peer_connection_ice_unittest.cc index c51970eb22..c7eecc901f 100644 --- a/pc/peer_connection_ice_unittest.cc +++ b/pc/peer_connection_ice_unittest.cc @@ -46,6 +46,7 @@ #include "pc/sdp_utils.h" #include "pc/session_description.h" #include "rtc_base/checks.h" +#include "rtc_base/internal/default_socket_server.h" #include "rtc_base/ip_address.h" #include "rtc_base/logging.h" #include "rtc_base/net_helper.h" @@ -158,8 +159,9 @@ class PeerConnectionIceBaseTest : public ::testing::Test { WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { auto* fake_network = NewFakeNetwork(); - auto port_allocator = - std::make_unique(fake_network); + auto port_allocator = std::make_unique( + fake_network, + std::make_unique(vss_.get())); port_allocator->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY); port_allocator->set_step_delay(cricket::kMinimumStepDelay); diff --git a/pc/peer_connection_rampup_tests.cc b/pc/peer_connection_rampup_tests.cc index e1ebebb8dd..ff28906f00 100644 --- a/pc/peer_connection_rampup_tests.cc +++ b/pc/peer_connection_rampup_tests.cc @@ -184,7 +184,10 @@ class PeerConnectionRampUpTest : public ::testing::Test { auto observer = std::make_unique(); webrtc::PeerConnectionDependencies dependencies(observer.get()); cricket::BasicPortAllocator* port_allocator = - new cricket::BasicPortAllocator(fake_network_manager); + new cricket::BasicPortAllocator( + fake_network_manager, + std::make_unique( + firewall_socket_server_.get())); port_allocator->set_step_delay(cricket::kDefaultStepDelay); dependencies.allocator = std::unique_ptr(port_allocator); diff --git a/pc/test/integration_test_helpers.h b/pc/test/integration_test_helpers.h index a1d3a548e5..d9042eab31 100644 --- a/pc/test/integration_test_helpers.h +++ b/pc/test/integration_test_helpers.h @@ -744,6 +744,7 @@ class PeerConnectionIntegrationWrapper : public webrtc::PeerConnectionObserver, bool Init(const PeerConnectionFactory::Options* options, const PeerConnectionInterface::RTCConfiguration* config, webrtc::PeerConnectionDependencies dependencies, + rtc::SocketServer* socket_server, rtc::Thread* network_thread, rtc::Thread* worker_thread, std::unique_ptr event_log_factory, @@ -758,7 +759,9 @@ class PeerConnectionIntegrationWrapper : public webrtc::PeerConnectionObserver, fake_network_manager_->AddInterface(kDefaultLocalAddress); std::unique_ptr port_allocator( - new cricket::BasicPortAllocator(fake_network_manager_.get())); + new cricket::BasicPortAllocator( + fake_network_manager_.get(), + std::make_unique(socket_server))); port_allocator_ = port_allocator.get(); fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); if (!fake_audio_capture_module_) { @@ -1469,7 +1472,7 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { new PeerConnectionIntegrationWrapper(debug_name)); if (!client->Init(options, &modified_config, std::move(dependencies), - network_thread_.get(), worker_thread_.get(), + fss_.get(), network_thread_.get(), worker_thread_.get(), std::move(event_log_factory), reset_encoder_factory, reset_decoder_factory, create_media_engine)) { return nullptr; diff --git a/rtc_base/memory/always_valid_pointer.h b/rtc_base/memory/always_valid_pointer.h index db7d0a1cb4..4e68104b55 100644 --- a/rtc_base/memory/always_valid_pointer.h +++ b/rtc_base/memory/always_valid_pointer.h @@ -105,6 +105,144 @@ class AlwaysValidPointer { Interface* const pointer_; }; +// This class is similar to AlwaysValidPointer, but it does not create +// a default object and crashes if none of the input pointers are non-null. +template +class AlwaysValidPointerNoDefault { + public: + explicit AlwaysValidPointerNoDefault(Interface* pointer) : pointer_(pointer) { + RTC_CHECK(pointer_); + } + + // Create a pointer by + // a) taking over ownership of |instance| + // b) or fallback to |pointer|, without taking ownership. + // At least one of the arguments must be non-null. + explicit AlwaysValidPointerNoDefault(std::unique_ptr instance, + Interface* pointer = nullptr) + : owned_instance_(std::move(instance)), + pointer_(owned_instance_ ? owned_instance_.get() : pointer) { + RTC_CHECK(pointer_); + } + + Interface* get() { return pointer_; } + Interface* operator->() { return pointer_; } + Interface& operator*() { return *pointer_; } + + Interface* get() const { return pointer_; } + Interface* operator->() const { return pointer_; } + Interface& operator*() const { return *pointer_; } + + private: + const std::unique_ptr owned_instance_; + Interface* const pointer_; +}; + +template +bool operator==(const AlwaysValidPointer& a, + const AlwaysValidPointer& b) { + return a.get() == b.get(); +} + +template +bool operator!=(const AlwaysValidPointer& a, + const AlwaysValidPointer& b) { + return !(a == b); +} + +template +bool operator==(const AlwaysValidPointer& a, std::nullptr_t) { + return a.get() == nullptr; +} + +template +bool operator!=(const AlwaysValidPointer& a, std::nullptr_t) { + return !(a == nullptr); +} + +template +bool operator==(std::nullptr_t, const AlwaysValidPointer& a) { + return a.get() == nullptr; +} + +template +bool operator!=(std::nullptr_t, const AlwaysValidPointer& a) { + return !(a == nullptr); +} + +template +bool operator==(const AlwaysValidPointerNoDefault& a, + const AlwaysValidPointerNoDefault& b) { + return a.get() == b.get(); +} + +template +bool operator!=(const AlwaysValidPointerNoDefault& a, + const AlwaysValidPointerNoDefault& b) { + return !(a == b); +} + +template +bool operator==(const AlwaysValidPointerNoDefault& a, std::nullptr_t) { + return a.get() == nullptr; +} + +template +bool operator!=(const AlwaysValidPointerNoDefault& a, std::nullptr_t) { + return !(a == nullptr); +} + +template +bool operator==(std::nullptr_t, const AlwaysValidPointerNoDefault& a) { + return a.get() == nullptr; +} + +template +bool operator!=(std::nullptr_t, const AlwaysValidPointerNoDefault& a) { + return !(a == nullptr); +} + +// Comparison with raw pointer. +template +bool operator==(const AlwaysValidPointer& a, const V* b) { + return a.get() == b; +} + +template +bool operator!=(const AlwaysValidPointer& a, const V* b) { + return !(a == b); +} + +template +bool operator==(const T* a, const AlwaysValidPointer& b) { + return a == b.get(); +} + +template +bool operator!=(const T* a, const AlwaysValidPointer& b) { + return !(a == b); +} + +template +bool operator==(const AlwaysValidPointerNoDefault& a, const U* b) { + return a.get() == b; +} + +template +bool operator!=(const AlwaysValidPointerNoDefault& a, const U* b) { + return !(a == b); +} + +template +bool operator==(const T* a, const AlwaysValidPointerNoDefault& b) { + return a == b.get(); +} + +template +bool operator!=(const T* a, const AlwaysValidPointerNoDefault& b) { + return !(a == b); +} + } // namespace webrtc #endif // RTC_BASE_MEMORY_ALWAYS_VALID_POINTER_H_ diff --git a/rtc_base/memory/always_valid_pointer_unittest.cc b/rtc_base/memory/always_valid_pointer_unittest.cc index 30110c7969..a228c102d0 100644 --- a/rtc_base/memory/always_valid_pointer_unittest.cc +++ b/rtc_base/memory/always_valid_pointer_unittest.cc @@ -90,4 +90,40 @@ TEST(AlwaysValidPointerTest, DefaultToLambda) { EXPECT_EQ(*ptr, "onkel skrue"); } +TEST(AlwaysValidPointerTest, NoDefaultObjectPassValidPointer) { + std::string str("foo"); + AlwaysValidPointerNoDefault ptr(&str); + EXPECT_EQ(*ptr, "foo"); + EXPECT_EQ(ptr, &str); +} + +TEST(AlwaysValidPointerTest, NoDefaultObjectWithTakeOverOwnership) { + std::unique_ptr str = std::make_unique("yum"); + AlwaysValidPointerNoDefault ptr(std::move(str)); + EXPECT_EQ(*ptr, "yum"); + std::unique_ptr str2 = std::make_unique("fun"); + AlwaysValidPointerNoDefault ptr2(std::move(str), str2.get()); + EXPECT_EQ(*ptr2, "fun"); + EXPECT_EQ(ptr2, str2.get()); +} + +#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) + +TEST(AlwaysValidPointerTest, NoDefaultObjectPassNullPointer) { + auto pass_null = []() { + AlwaysValidPointerNoDefault ptr(nullptr); + }; + EXPECT_DEATH(pass_null(), ""); +} + +TEST(AlwaysValidPointerTest, NoDefaultObjectPassNullUniquePointer) { + auto pass_null = []() { + std::unique_ptr str; + AlwaysValidPointerNoDefault ptr(std::move(str)); + }; + EXPECT_DEATH(pass_null(), ""); +} + +#endif + } // namespace webrtc diff --git a/test/network/network_emulation_pc_unittest.cc b/test/network/network_emulation_pc_unittest.cc index cb446b42e8..7662b1cae8 100644 --- a/test/network/network_emulation_pc_unittest.cc +++ b/test/network/network_emulation_pc_unittest.cc @@ -21,6 +21,7 @@ #include "media/engine/webrtc_media_engine.h" #include "media/engine/webrtc_media_engine_defaults.h" #include "modules/audio_device/include/test_audio_device.h" +#include "p2p/base/basic_packet_socket_factory.h" #include "p2p/client/basic_port_allocator.h" #include "pc/peer_connection_wrapper.h" #include "pc/test/mock_peer_connection_observers.h" @@ -78,11 +79,12 @@ rtc::scoped_refptr CreatePeerConnectionFactory( rtc::scoped_refptr CreatePeerConnection( const rtc::scoped_refptr& pcf, PeerConnectionObserver* observer, + rtc::PacketSocketFactory* packet_socket_factory, rtc::NetworkManager* network_manager, EmulatedTURNServerInterface* turn_server = nullptr) { PeerConnectionDependencies pc_deps(observer); - auto port_allocator = - std::make_unique(network_manager); + auto port_allocator = std::make_unique( + network_manager, packet_socket_factory); // This test does not support TCP int flags = cricket::PORTALLOCATOR_DISABLE_TCP; @@ -148,11 +150,13 @@ TEST(NetworkEmulationManagerPCTest, Run) { alice_pcf = CreatePeerConnectionFactory(signaling_thread.get(), alice_network->network_thread()); alice_pc = CreatePeerConnection(alice_pcf, alice_observer.get(), + alice_network->packet_socket_factory(), alice_network->network_manager()); bob_pcf = CreatePeerConnectionFactory(signaling_thread.get(), bob_network->network_thread()); bob_pc = CreatePeerConnection(bob_pcf, bob_observer.get(), + bob_network->packet_socket_factory(), bob_network->network_manager()); }); @@ -255,13 +259,14 @@ TEST(NetworkEmulationManagerPCTest, RunTURN) { signaling_thread->Invoke(RTC_FROM_HERE, [&]() { alice_pcf = CreatePeerConnectionFactory(signaling_thread.get(), alice_network->network_thread()); - alice_pc = - CreatePeerConnection(alice_pcf, alice_observer.get(), - alice_network->network_manager(), alice_turn); + alice_pc = CreatePeerConnection( + alice_pcf, alice_observer.get(), alice_network->packet_socket_factory(), + alice_network->network_manager(), alice_turn); bob_pcf = CreatePeerConnectionFactory(signaling_thread.get(), bob_network->network_thread()); bob_pc = CreatePeerConnection(bob_pcf, bob_observer.get(), + bob_network->packet_socket_factory(), bob_network->network_manager(), bob_turn); }); diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc index 7e1720c404..5d77f17561 100644 --- a/test/peer_scenario/peer_scenario_client.cc +++ b/test/peer_scenario/peer_scenario_client.cc @@ -281,8 +281,8 @@ PeerScenarioClient::PeerScenarioClient( pc_factory_->SetOptions(pc_options); PeerConnectionDependencies pc_deps(observer_.get()); - pc_deps.allocator = - std::make_unique(manager->network_manager()); + pc_deps.allocator = std::make_unique( + manager->network_manager(), manager->packet_socket_factory()); pc_deps.allocator->set_flags(pc_deps.allocator->flags() | cricket::PORTALLOCATOR_DISABLE_TCP); peer_connection_ = diff --git a/test/peer_scenario/scenario_connection.cc b/test/peer_scenario/scenario_connection.cc index 9b240b8387..bd95da028e 100644 --- a/test/peer_scenario/scenario_connection.cc +++ b/test/peer_scenario/scenario_connection.cc @@ -96,7 +96,8 @@ ScenarioIceConnectionImpl::ScenarioIceConnectionImpl( rtc::SSLFingerprint::CreateFromCertificate(*certificate_.get()) .get()), port_allocator_( - new cricket::BasicPortAllocator(manager_->network_manager())), + new cricket::BasicPortAllocator(manager_->network_manager(), + manager_->packet_socket_factory())), jsep_controller_( new JsepTransportController(network_thread_, port_allocator_.get(),