From 25361a89dd3da30fb14e0d81853189791b2978dc Mon Sep 17 00:00:00 2001 From: Christoffer Jansson Date: Thu, 2 Jun 2022 09:44:03 +0000 Subject: [PATCH] Revert "Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession"" This reverts commit a8be79ce27f10a698bdb46e490c2bbcbb2300e52. Reason for revert: Downstream projects were not fixed and I was to eager to reland this, sorry about this. Original change's description: > Reland "Don't create PacketSocketFactory inside BasicPortAllocatorSession" > > This is a reland of commit 7d4634cef76a1ac244d4b83faaf4c617bf236b71 > > Original change's description: > > Don't create PacketSocketFactory inside BasicPortAllocatorSession > > > > This extends AlwaysValidPointer to avoid creating a unique_ptr inside it. > > > > Bug: webrtc:13145 > > Change-Id: I73a4f18d0a7037b57f575b04b134e4f7eadceb79 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/263240 > > Reviewed-by: Jonas Oreland > > Commit-Queue: Daniel.L (Byoungchan) Lee > > Reviewed-by: Harald Alvestrand > > Cr-Commit-Position: refs/heads/main@{#37048} > > Bug: webrtc:13145 > Change-Id: I7d64c25b2942b392a1c35ff2fe1edc83d7b03746 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264503 > Reviewed-by: Harald Alvestrand > Reviewed-by: Christoffer Jansson > Commit-Queue: Christoffer Jansson > Reviewed-by: Daniel.L (Byoungchan) Lee > Cr-Commit-Position: refs/heads/main@{#37088} Bug: webrtc:13145 Change-Id: Ie7990bae9a7c864ffaa4eb5b637618caad509633 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264823 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com Commit-Queue: Christoffer Jansson Owners-Override: Christoffer Jansson Cr-Commit-Position: refs/heads/main@{#37089} --- p2p/base/p2p_transport_channel_unittest.cc | 23 ++- p2p/client/basic_port_allocator.cc | 34 ++--- p2p/client/basic_port_allocator.h | 22 ++- p2p/client/basic_port_allocator_unittest.cc | 30 +--- pc/peer_connection_bundle_unittest.cc | 5 +- pc/peer_connection_histogram_unittest.cc | 19 +-- pc/peer_connection_ice_unittest.cc | 6 +- pc/peer_connection_rampup_tests.cc | 5 +- pc/test/integration_test_helpers.h | 7 +- rtc_base/memory/always_valid_pointer.h | 138 ------------------ .../memory/always_valid_pointer_unittest.cc | 36 ----- test/network/network_emulation_pc_unittest.cc | 15 +- test/peer_scenario/peer_scenario_client.cc | 4 +- test/peer_scenario/scenario_connection.cc | 3 +- 14 files changed, 63 insertions(+), 284 deletions(-) diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index 1203972010..082f4853b2 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -157,7 +157,6 @@ 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) { @@ -173,13 +172,11 @@ cricket::BasicPortAllocator* CreateBasicPortAllocator( } std::vector turn_servers(1, turn_server); - std::unique_ptr allocator = - std::make_unique( - network_manager, - std::make_unique(socket_server)); + cricket::BasicPortAllocator* allocator = + new cricket::BasicPortAllocator(network_manager); allocator->Initialize(); allocator->SetConfiguration(stun_servers, turn_servers, 0, webrtc::NO_PRUNE); - return allocator.release(); + return allocator; } class MockIceControllerFactory : public cricket::IceControllerFactoryInterface { @@ -283,12 +280,12 @@ class P2PTransportChannelTestBase : public ::testing::Test, ServerAddresses stun_servers; stun_servers.insert(kStunAddr); - 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())); + ep1_.allocator_.reset( + CreateBasicPortAllocator(&ep1_.network_manager_, stun_servers, + kTurnUdpIntAddr, rtc::SocketAddress())); + ep2_.allocator_.reset( + CreateBasicPortAllocator(&ep2_.network_manager_, stun_servers, + kTurnUdpIntAddr, rtc::SocketAddress())); webrtc::metrics::Reset(); } @@ -4918,7 +4915,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest kTurnUdpExtAddr) { network_manager_.AddInterface(kPublicAddrs[0]); allocator_.reset( - CreateBasicPortAllocator(&network_manager_, ss(), ServerAddresses(), + CreateBasicPortAllocator(&network_manager_, 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 3a1488e66b..f4306f1798 100644 --- a/p2p/client/basic_port_allocator.cc +++ b/p2p/client/basic_port_allocator.cc @@ -165,35 +165,23 @@ BasicPortAllocator::BasicPortAllocator( Init(relay_port_factory, nullptr); RTC_DCHECK(relay_port_factory_ != nullptr); RTC_DCHECK(network_manager_ != nullptr); - RTC_CHECK(socket_factory_ != nullptr); + RTC_DCHECK(socket_factory_ != nullptr); SetConfiguration(ServerAddresses(), std::vector(), 0, webrtc::NO_PRUNE, customizer); } -BasicPortAllocator::BasicPortAllocator( - rtc::NetworkManager* network_manager, - std::unique_ptr owned_socket_factory) - : network_manager_(network_manager), - socket_factory_(std::move(owned_socket_factory)) { +BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager) + : network_manager_(network_manager), socket_factory_(nullptr) { 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, - 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, + const ServerAddresses& stun_servers) + : BasicPortAllocator(network_manager, + /*socket_factory=*/nullptr, + stun_servers) {} BasicPortAllocator::BasicPortAllocator(rtc::NetworkManager* network_manager, rtc::PacketSocketFactory* socket_factory, @@ -202,7 +190,6 @@ 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); } @@ -407,6 +394,11 @@ 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 048b52749a..01d07e76b3 100644 --- a/p2p/client/basic_port_allocator.h +++ b/p2p/client/basic_port_allocator.h @@ -21,7 +21,6 @@ #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" @@ -33,19 +32,18 @@ namespace cricket { class RTC_EXPORT BasicPortAllocator : public PortAllocator { public: // The NetworkManager is a mandatory argument. The other arguments are - // optional. All pointers are owned by caller and must have a life time + // optional. All these objects 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); - 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); + explicit BasicPortAllocator(rtc::NetworkManager* network_manager); + BasicPortAllocator(rtc::NetworkManager* network_manager, + const ServerAddresses& stun_servers); BasicPortAllocator(rtc::NetworkManager* network_manager, rtc::PacketSocketFactory* socket_factory, const ServerAddresses& stun_servers); @@ -64,7 +62,7 @@ class RTC_EXPORT BasicPortAllocator : public PortAllocator { // creates its own socket factory. rtc::PacketSocketFactory* socket_factory() { CheckRunOnValidThreadIfInitialized(); - return socket_factory_.get(); + return socket_factory_; } PortAllocatorSession* CreateSessionInternal( @@ -99,8 +97,7 @@ class RTC_EXPORT BasicPortAllocator : public PortAllocator { const webrtc::FieldTrialsView* field_trials_; std::unique_ptr owned_field_trials_; rtc::NetworkManager* network_manager_; - const webrtc::AlwaysValidPointerNoDefault - socket_factory_; + rtc::PacketSocketFactory* socket_factory_; int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask; // This is the factory being used. @@ -276,6 +273,7 @@ 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 8fc40a6c3a..aa04b78855 100644 --- a/p2p/client/basic_port_allocator_unittest.cc +++ b/p2p/client/basic_port_allocator_unittest.cc @@ -161,10 +161,8 @@ class BasicPortAllocatorTestBase : public ::testing::Test, ServerAddresses stun_servers; stun_servers.insert(kStunAddr); - allocator_ = std::make_unique( - &network_manager_, - std::make_unique(fss_.get()), - stun_servers); + allocator_ = + std::make_unique(&network_manager_, stun_servers); allocator_->Initialize(); allocator_->set_step_delay(kMinimumStepDelay); webrtc::metrics::Reset(); @@ -201,9 +199,7 @@ class BasicPortAllocatorTestBase : public ::testing::Test, } // Endpoint is on the public network. No STUN or TURN. void ResetWithNoServersOrNat() { - allocator_.reset(new BasicPortAllocator( - &network_manager_, - std::make_unique(fss_.get()))); + allocator_.reset(new BasicPortAllocator(&network_manager_)); allocator_->Initialize(); allocator_->set_step_delay(kMinimumStepDelay); } @@ -582,9 +578,7 @@ class BasicPortAllocatorTest : public FakeClockBase, // Add two IP addresses on the same interface. AddInterface(kClientAddr, "net1"); AddInterface(kClientIPv6Addr, "net1"); - allocator_.reset(new BasicPortAllocator( - &network_manager_, - std::make_unique(fss_.get()))); + allocator_.reset(new BasicPortAllocator(&network_manager_)); allocator_->Initialize(); allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), 0, @@ -625,9 +619,7 @@ class BasicPortAllocatorTest : public FakeClockBase, bool tcp_pruned) { turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); - allocator_.reset(new BasicPortAllocator( - &network_manager_, - std::make_unique(fss_.get()))); + allocator_.reset(new BasicPortAllocator(&network_manager_)); allocator_->Initialize(); allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), 0, prune_policy); @@ -679,9 +671,7 @@ 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_, - std::make_unique(fss_.get()))); + allocator_.reset(new BasicPortAllocator(&network_manager_)); allocator_->Initialize(); allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), 0, @@ -1647,9 +1637,7 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); - allocator_.reset(new BasicPortAllocator( - &network_manager_, - std::make_unique(fss_.get()))); + allocator_.reset(new BasicPortAllocator(&network_manager_)); allocator_->Initialize(); AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); @@ -1784,9 +1772,7 @@ TEST_F(BasicPortAllocatorTestWithRealClock, turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), PROTO_UDP); AddInterface(kClientAddr); - allocator_.reset(new BasicPortAllocator( - &network_manager_, - std::make_unique(fss_.get()))); + allocator_.reset(new BasicPortAllocator(&network_manager_)); 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 ad3d118510..fed4930f43 100644 --- a/pc/peer_connection_bundle_unittest.cc +++ b/pc/peer_connection_bundle_unittest.cc @@ -224,9 +224,8 @@ class PeerConnectionBundleBaseTest : public ::testing::Test { WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { auto* fake_network = NewFakeNetwork(); - auto port_allocator = std::make_unique( - fake_network, - std::make_unique(vss_.get())); + auto port_allocator = + std::make_unique(fake_network); 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 da2ff40190..4a3c6794c4 100644 --- a/pc/peer_connection_histogram_unittest.cc +++ b/pc/peer_connection_histogram_unittest.cc @@ -270,9 +270,7 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { fake_network->AddInterface(NextLocalAddress()); std::unique_ptr port_allocator( - new cricket::BasicPortAllocator( - fake_network, - std::make_unique(vss_.get()))); + new cricket::BasicPortAllocator(fake_network)); deps.async_resolver_factory = std::move(resolver_factory); deps.allocator = std::move(port_allocator); @@ -294,9 +292,8 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(kPrivateLocalAddress); - auto port_allocator = std::make_unique( - fake_network, - std::make_unique(vss_.get())); + auto port_allocator = + std::make_unique(fake_network); RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; return CreatePeerConnection(config, @@ -309,9 +306,8 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(kPrivateIpv6LocalAddress); - auto port_allocator = std::make_unique( - fake_network, - std::make_unique(vss_.get())); + auto port_allocator = + std::make_unique(fake_network); RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; @@ -343,9 +339,8 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { if (!deps.allocator) { auto fake_network = NewFakeNetwork(); fake_network->AddInterface(NextLocalAddress()); - deps.allocator = std::make_unique( - fake_network, - std::make_unique(vss_.get())); + deps.allocator = + std::make_unique(fake_network); } auto observer = std::make_unique(); diff --git a/pc/peer_connection_ice_unittest.cc b/pc/peer_connection_ice_unittest.cc index c7eecc901f..c51970eb22 100644 --- a/pc/peer_connection_ice_unittest.cc +++ b/pc/peer_connection_ice_unittest.cc @@ -46,7 +46,6 @@ #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" @@ -159,9 +158,8 @@ class PeerConnectionIceBaseTest : public ::testing::Test { WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { auto* fake_network = NewFakeNetwork(); - auto port_allocator = std::make_unique( - fake_network, - std::make_unique(vss_.get())); + auto port_allocator = + std::make_unique(fake_network); 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 ff28906f00..e1ebebb8dd 100644 --- a/pc/peer_connection_rampup_tests.cc +++ b/pc/peer_connection_rampup_tests.cc @@ -184,10 +184,7 @@ 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, - std::make_unique( - firewall_socket_server_.get())); + new cricket::BasicPortAllocator(fake_network_manager); 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 d9042eab31..a1d3a548e5 100644 --- a/pc/test/integration_test_helpers.h +++ b/pc/test/integration_test_helpers.h @@ -744,7 +744,6 @@ 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, @@ -759,9 +758,7 @@ class PeerConnectionIntegrationWrapper : public webrtc::PeerConnectionObserver, fake_network_manager_->AddInterface(kDefaultLocalAddress); std::unique_ptr port_allocator( - new cricket::BasicPortAllocator( - fake_network_manager_.get(), - std::make_unique(socket_server))); + new cricket::BasicPortAllocator(fake_network_manager_.get())); port_allocator_ = port_allocator.get(); fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); if (!fake_audio_capture_module_) { @@ -1472,7 +1469,7 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { new PeerConnectionIntegrationWrapper(debug_name)); if (!client->Init(options, &modified_config, std::move(dependencies), - fss_.get(), network_thread_.get(), worker_thread_.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 4e68104b55..db7d0a1cb4 100644 --- a/rtc_base/memory/always_valid_pointer.h +++ b/rtc_base/memory/always_valid_pointer.h @@ -105,144 +105,6 @@ 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 a228c102d0..30110c7969 100644 --- a/rtc_base/memory/always_valid_pointer_unittest.cc +++ b/rtc_base/memory/always_valid_pointer_unittest.cc @@ -90,40 +90,4 @@ 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 7662b1cae8..cb446b42e8 100644 --- a/test/network/network_emulation_pc_unittest.cc +++ b/test/network/network_emulation_pc_unittest.cc @@ -21,7 +21,6 @@ #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" @@ -79,12 +78,11 @@ 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, packet_socket_factory); + auto port_allocator = + std::make_unique(network_manager); // This test does not support TCP int flags = cricket::PORTALLOCATOR_DISABLE_TCP; @@ -150,13 +148,11 @@ 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()); }); @@ -259,14 +255,13 @@ 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->packet_socket_factory(), - alice_network->network_manager(), alice_turn); + alice_pc = + CreatePeerConnection(alice_pcf, alice_observer.get(), + 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 5d77f17561..7e1720c404 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(), manager->packet_socket_factory()); + pc_deps.allocator = + std::make_unique(manager->network_manager()); 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 bd95da028e..9b240b8387 100644 --- a/test/peer_scenario/scenario_connection.cc +++ b/test/peer_scenario/scenario_connection.cc @@ -96,8 +96,7 @@ ScenarioIceConnectionImpl::ScenarioIceConnectionImpl( rtc::SSLFingerprint::CreateFromCertificate(*certificate_.get()) .get()), port_allocator_( - new cricket::BasicPortAllocator(manager_->network_manager(), - manager_->packet_socket_factory())), + new cricket::BasicPortAllocator(manager_->network_manager())), jsep_controller_( new JsepTransportController(network_thread_, port_allocator_.get(),