From 9806d64c46755f9330dce99318de8fde4096104e Mon Sep 17 00:00:00 2001 From: "Byron Campen [:bwc]" Date: Thu, 9 Jul 2020 15:36:07 +0000 Subject: [PATCH] Bug 1193437: Use config structs in NrIceCtx, and centralize pref lookups some. r=mjf Differential Revision: https://phabricator.services.mozilla.com/D82549 --- media/mtransport/nricectx.cpp | 111 +--- media/mtransport/nricectx.h | 44 +- media/mtransport/test/ice_unittest.cpp | 501 +++++++++++++++--- .../test/multi_tcp_socket_unittest.cpp | 3 +- .../test/test_nr_socket_ice_unittest.cpp | 2 +- media/mtransport/test/transport_unittests.cpp | 4 +- media/mtransport/test/turn_unittest.cpp | 2 +- .../peerconnection/MediaTransportHandler.cpp | 180 ++++--- 8 files changed, 614 insertions(+), 233 deletions(-) diff --git a/media/mtransport/nricectx.cpp b/media/mtransport/nricectx.cpp index 586f2388d3c9..0a7e976a39c9 100644 --- a/media/mtransport/nricectx.cpp +++ b/media/mtransport/nricectx.cpp @@ -265,7 +265,7 @@ nsresult NrIceTurnServer::ToNicerTurnStruct(nr_ice_turn_server* server) const { return NS_OK; } -NrIceCtx::NrIceCtx(const std::string& name, Policy policy) +NrIceCtx::NrIceCtx(const std::string& name, const Config& aConfig) : connection_state_(ICE_CTX_INIT), gathering_state_(ICE_CTX_GATHER_INIT), name_(name), @@ -276,19 +276,15 @@ NrIceCtx::NrIceCtx(const std::string& name, Policy policy) ice_handler_vtbl_(nullptr), ice_handler_(nullptr), trickle_(true), - policy_(policy), + config_(aConfig), nat_(nullptr), proxy_config_(nullptr), obfuscate_host_addresses_(false) {} /* static */ -RefPtr NrIceCtx::Create(const std::string& name, bool allow_loopback, - bool tcp_enabled, bool allow_link_local, - Policy policy) { - // InitializeGlobals only executes once - NrIceCtx::InitializeGlobals(allow_loopback, tcp_enabled, allow_link_local); - - RefPtr ctx = new NrIceCtx(name, policy); +RefPtr NrIceCtx::Create(const std::string& aName, + const Config& aConfig) { + RefPtr ctx = new NrIceCtx(aName, aConfig); if (!ctx->Initialize()) { return nullptr; @@ -457,8 +453,7 @@ void NrIceCtx::trickle_cb(void* arg, nr_ice_ctx* ice_ctx, s->SignalCandidate(s, candidate_str, stream->ufrag, mdns_addr, actual_addr); } -void NrIceCtx::InitializeGlobals(bool allow_loopback, bool tcp_enabled, - bool allow_link_local) { +void NrIceCtx::InitializeGlobals(const GlobalConfig& aConfig) { RLogConnector::CreateInstance(); // Initialize the crypto callbacks and logging stuff if (!initialized) { @@ -476,57 +471,27 @@ void NrIceCtx::InitializeGlobals(bool allow_loopback, bool tcp_enabled, NR_reg_set_uchar((char*)NR_ICE_REG_PREF_TYPE_PEER_RFLX_TCP, 109); NR_reg_set_uchar((char*)NR_ICE_REG_PREF_TYPE_HOST_TCP, 125); NR_reg_set_uchar((char*)NR_ICE_REG_PREF_TYPE_RELAYED_TCP, 0); - - int32_t stun_client_maximum_transmits = 7; - int32_t ice_trickle_grace_period = 5000; - int32_t ice_tcp_so_sock_count = 3; - int32_t ice_tcp_listen_backlog = 10; - nsAutoCString force_net_interface; - nsresult res; - nsCOMPtr prefs = - do_GetService("@mozilla.org/preferences-service;1", &res); - - if (NS_SUCCEEDED(res)) { - nsCOMPtr branch = do_QueryInterface(prefs); - if (branch) { - branch->GetIntPref( - "media.peerconnection.ice.stun_client_maximum_transmits", - &stun_client_maximum_transmits); - branch->GetIntPref("media.peerconnection.ice.trickle_grace_period", - &ice_trickle_grace_period); - branch->GetIntPref("media.peerconnection.ice.tcp_so_sock_count", - &ice_tcp_so_sock_count); - branch->GetIntPref("media.peerconnection.ice.tcp_listen_backlog", - &ice_tcp_listen_backlog); - branch->GetCharPref("media.peerconnection.ice.force_interface", - force_net_interface); - } - } - NR_reg_set_uint4((char*)"stun.client.maximum_transmits", - stun_client_maximum_transmits); + aConfig.mStunClientMaxTransmits); NR_reg_set_uint4((char*)NR_ICE_REG_TRICKLE_GRACE_PERIOD, - ice_trickle_grace_period); + aConfig.mTrickleIceGracePeriod); NR_reg_set_int4((char*)NR_ICE_REG_ICE_TCP_SO_SOCK_COUNT, - ice_tcp_so_sock_count); + aConfig.mIceTcpSoSockCount); NR_reg_set_int4((char*)NR_ICE_REG_ICE_TCP_LISTEN_BACKLOG, - ice_tcp_listen_backlog); + aConfig.mIceTcpListenBacklog); - NR_reg_set_char((char*)NR_ICE_REG_ICE_TCP_DISABLE, !tcp_enabled); + NR_reg_set_char((char*)NR_ICE_REG_ICE_TCP_DISABLE, !aConfig.mTcpEnabled); - if (allow_loopback) { + if (aConfig.mAllowLoopback) { NR_reg_set_char((char*)NR_STUN_REG_PREF_ALLOW_LOOPBACK_ADDRS, 1); } - if (allow_link_local) { + if (aConfig.mAllowLinkLocal) { NR_reg_set_char((char*)NR_STUN_REG_PREF_ALLOW_LINK_LOCAL_ADDRS, 1); } - if (force_net_interface.Length() > 0) { - // Stupid cast.... but needed - const nsCString& flat = - PromiseFlatCString(static_cast(force_net_interface)); + if (!aConfig.mForceNetInterface.Length()) { NR_reg_set_string((char*)NR_ICE_REG_PREF_FORCE_INTERFACE_NAME, - const_cast(flat.get())); + const_cast(aConfig.mForceNetInterface.get())); } } } @@ -583,7 +548,7 @@ bool NrIceCtx::Initialize() { int r; UINT4 flags = NR_ICE_CTX_FLAGS_AGGRESSIVE_NOMINATION; - switch (policy_) { + switch (config_.mPolicy) { case ICE_POLICY_RELAY: flags |= NR_ICE_CTX_FLAGS_RELAY_ONLY; break; @@ -632,38 +597,14 @@ bool NrIceCtx::Initialize() { } } - nsAutoCString mapping_type; - nsAutoCString filtering_type; - bool block_udp = false; - bool block_tcp = false; - - nsresult rv; - nsCOMPtr pref_service = - do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - - if (NS_SUCCEEDED(rv)) { - nsCOMPtr pref_branch; - rv = pref_service->GetBranch(nullptr, getter_AddRefs(pref_branch)); - if (NS_SUCCEEDED(rv)) { - Unused << pref_branch->GetCharPref( - "media.peerconnection.nat_simulator.mapping_type", mapping_type); - Unused << pref_branch->GetCharPref( - "media.peerconnection.nat_simulator.filtering_type", filtering_type); - Unused << pref_branch->GetBoolPref( - "media.peerconnection.nat_simulator.block_udp", &block_udp); - Unused << pref_branch->GetBoolPref( - "media.peerconnection.nat_simulator.block_tcp", &block_tcp); - } - } - - if (!mapping_type.IsEmpty() && !filtering_type.IsEmpty()) { - MOZ_MTLOG(ML_DEBUG, "NAT filtering type: " << filtering_type.get()); - MOZ_MTLOG(ML_DEBUG, "NAT mapping type: " << mapping_type.get()); + if (config_.mNatSimulatorConfig.isSome()) { TestNat* test_nat = new TestNat; - test_nat->filtering_type_ = TestNat::ToNatBehavior(filtering_type.get()); - test_nat->mapping_type_ = TestNat::ToNatBehavior(mapping_type.get()); - test_nat->block_udp_ = block_udp; - test_nat->block_tcp_ = block_tcp; + test_nat->filtering_type_ = TestNat::ToNatBehavior( + config_.mNatSimulatorConfig->mFilteringType.get()); + test_nat->mapping_type_ = + TestNat::ToNatBehavior(config_.mNatSimulatorConfig->mMappingType.get()); + test_nat->block_udp_ = config_.mNatSimulatorConfig->mBlockUdp; + test_nat->block_tcp_ = config_.mNatSimulatorConfig->mBlockTcp; test_nat->enabled_ = true; SetNat(test_nat); } @@ -692,6 +633,7 @@ bool NrIceCtx::Initialize() { return false; } + nsresult rv; sts_target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); if (!NS_SUCCEEDED(rv)) return false; @@ -784,11 +726,6 @@ NrIceCtx::Controlling NrIceCtx::GetControlling() { return (peer_->controlling) ? ICE_CONTROLLING : ICE_CONTROLLED; } -nsresult NrIceCtx::SetPolicy(Policy policy) { - policy_ = policy; - return NS_OK; -} - nsresult NrIceCtx::SetStunServers( const std::vector& stun_servers) { if (stun_servers.empty()) return NS_OK; diff --git a/media/mtransport/nricectx.h b/media/mtransport/nricectx.h index 4616a6ab6928..cbc82faa0779 100644 --- a/media/mtransport/nricectx.h +++ b/media/mtransport/nricectx.h @@ -63,6 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "mozilla/UniquePtr.h" #include "nsIEventTarget.h" #include "nsTArray.h" +#include "mozilla/Maybe.h" #include "m_cpp_utils.h" #include "nricestunaddr.h" @@ -201,20 +202,39 @@ class NrIceCtx { enum Policy { ICE_POLICY_RELAY, ICE_POLICY_NO_HOST, ICE_POLICY_ALL }; - static RefPtr Create( - const std::string& name, bool allow_loopback = false, - bool tcp_enabled = true, bool allow_link_local = false, - NrIceCtx::Policy policy = NrIceCtx::ICE_POLICY_ALL); + struct NatSimulatorConfig { + bool mBlockTcp = false; + bool mBlockUdp = false; + nsCString mMappingType = "ENDPOINT_INDEPENDENT"_ns; + nsCString mFilteringType = "ENDPOINT_INDEPENDENT"_ns; + }; + + struct Config { + NrIceCtx::Policy mPolicy = NrIceCtx::ICE_POLICY_ALL; + Maybe mNatSimulatorConfig; + }; + + static RefPtr Create(const std::string& aName, + const Config& aConfig); RefPtr CreateStream(const std::string& id, const std::string& name, int components); void DestroyStream(const std::string& id); + struct GlobalConfig { + bool mAllowLinkLocal = false; + bool mAllowLoopback = false; + bool mTcpEnabled = true; + int mStunClientMaxTransmits = 7; + int mTrickleIceGracePeriod = 5000; + int mIceTcpSoSockCount = 3; + int mIceTcpListenBacklog = 10; + nsCString mForceNetInterface; + }; + // initialize ICE globals, crypto, and logging - static void InitializeGlobals(bool allow_loopback = false, - bool tcp_enabled = true, - bool allow_link_local = false); + static void InitializeGlobals(const GlobalConfig& aConfig); void SetTargetForDefaultLocalAddressLookup(const std::string& target_ip, uint16_t target_port); @@ -278,12 +298,6 @@ class NrIceCtx { Controlling GetControlling(); - // Set whether we're allowed to produce none, relay or all candidates. - // TODO(jib@mozilla.com): Work out what change means mid-connection (1181768) - nsresult SetPolicy(Policy policy); - - Policy policy() const { return policy_; } - // Set the STUN servers. Must be called before StartGathering // (if at all). nsresult SetStunServers(const std::vector& stun_servers); @@ -339,7 +353,7 @@ class NrIceCtx { NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceCtx) private: - NrIceCtx(const std::string& name, Policy policy); + NrIceCtx(const std::string& name, const Config& aConfig); virtual ~NrIceCtx(); @@ -388,7 +402,7 @@ class NrIceCtx { nr_ice_handler* ice_handler_; // Must be pointer bool trickle_; nsCOMPtr sts_target_; // The thread to run on - Policy policy_; + Config config_; RefPtr nat_; std::shared_ptr proxy_config_; bool obfuscate_host_addresses_; diff --git a/media/mtransport/test/ice_unittest.cpp b/media/mtransport/test/ice_unittest.cpp index 96b44e622d6b..eef1ce204a52 100644 --- a/media/mtransport/test/ice_unittest.cpp +++ b/media/mtransport/test/ice_unittest.cpp @@ -174,11 +174,6 @@ enum TrickleMode { TRICKLE_NONE, TRICKLE_SIMULATE, TRICKLE_REAL }; enum ConsentStatus { CONSENT_FRESH, CONSENT_STALE, CONSENT_EXPIRED }; -const unsigned int ICE_TEST_PEER_OFFERER = (1 << 0); -const unsigned int ICE_TEST_PEER_ALLOW_LOOPBACK = (1 << 1); -const unsigned int ICE_TEST_PEER_ENABLED_TCP = (1 << 2); -const unsigned int ICE_TEST_PEER_ALLOW_LINK_LOCAL = (1 << 3); - typedef std::string (*CandidateFilter)(const std::string& candidate); std::vector split(const std::string& s, char delim) { @@ -361,15 +356,10 @@ class SchedulableTrickleCandidate { class IceTestPeer : public sigslot::has_slots<> { public: - // TODO(ekr@rtfm.com): Convert to flags when NrIceCtx::Create() does. - // Bug 1193437. IceTestPeer(const std::string& name, MtransportTestUtils* utils, bool offerer, - bool allow_loopback = false, bool enable_tcp = true, - bool allow_link_local = false, - NrIceCtx::Policy ice_policy = NrIceCtx::ICE_POLICY_ALL) + const NrIceCtx::Config& config) : name_(name), - ice_ctx_(NrIceCtx::Create(name, allow_loopback, enable_tcp, - allow_link_local, ice_policy)), + ice_ctx_(NrIceCtx::Create(name, config)), offerer_(offerer), candidates_(), stream_counter_(0), @@ -1421,13 +1411,10 @@ class WebRtcIceGatherTest : public StunTest { StunTest::TearDown(); } - void EnsurePeer(const unsigned int flags = ICE_TEST_PEER_OFFERER) { + void EnsurePeer() { if (!peer_) { - peer_ = MakeUnique("P1", test_utils_, - flags & ICE_TEST_PEER_OFFERER, - flags & ICE_TEST_PEER_ALLOW_LOOPBACK, - flags & ICE_TEST_PEER_ENABLED_TCP, - flags & ICE_TEST_PEER_ALLOW_LINK_LOCAL); + peer_ = + MakeUnique("P1", test_utils_, true, NrIceCtx::Config()); peer_->AddStream(1); } } @@ -1493,7 +1480,7 @@ class WebRtcIceGatherTest : public StunTest { void UseFakeStunTcpServerWithResponse( const std::string& fake_addr, uint16_t fake_port, const std::string& fqdn = std::string()) { - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + EnsurePeer(); std::vector stun_servers; AddStunServerWithResponse(fake_addr, fake_port, fqdn, "tcp", &stun_servers); peer_->SetStunServers(stun_servers); @@ -1503,7 +1490,7 @@ class WebRtcIceGatherTest : public StunTest { uint16_t fake_udp_port, const std::string& fake_tcp_addr, uint16_t fake_tcp_port) { - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + EnsurePeer(); std::vector stun_servers; AddStunServerWithResponse(fake_udp_addr, fake_udp_port, "", // no fqdn @@ -1577,7 +1564,7 @@ class WebRtcIceConnectTest : public StunTest { } void AddStream(int components) { - Init(false, false); + Init(); p1_->AddStream(components); p2_->AddStream(components); } @@ -1587,17 +1574,17 @@ class WebRtcIceConnectTest : public StunTest { p2_->RemoveStream(index); } - void Init(bool allow_loopback, bool enable_tcp, - bool setup_stun_servers = true, + void Init(bool setup_stun_servers = true, NrIceCtx::Policy ice_policy = NrIceCtx::ICE_POLICY_ALL) { if (initted_) { return; } - p1_ = MakeUnique("P1", test_utils_, true, allow_loopback, - enable_tcp, false, ice_policy); - p2_ = MakeUnique("P2", test_utils_, false, allow_loopback, - enable_tcp, false, ice_policy); + NrIceCtx::Config config; + config.mPolicy = ice_policy; + + p1_ = MakeUnique("P1", test_utils_, true, config); + p2_ = MakeUnique("P2", test_utils_, false, config); InitPeer(p1_.get(), setup_stun_servers); InitPeer(p2_.get(), setup_stun_servers); @@ -1632,7 +1619,7 @@ class WebRtcIceConnectTest : public StunTest { bool Gather(unsigned int waitTime = kDefaultTimeout, bool default_route_only = false) { - Init(false, false); + Init(); return GatherCallerAndCallee(p1_.get(), p2_.get(), waitTime, default_route_only); @@ -1941,8 +1928,10 @@ class WebRtcIcePacketFilterTest : public StunTest { void SetUp() { StunTest::SetUp(); + NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig()); + // Set up enough of the ICE ctx to allow the packet filter to work - ice_ctx_ = NrIceCtx::Create("test", true); + ice_ctx_ = NrIceCtx::Create("test", NrIceCtx::Config()); nsCOMPtr udp_handler = do_GetService(NS_STUN_UDP_SOCKET_FILTER_HANDLER_CONTRACTID); @@ -2053,6 +2042,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherFakeStunServerHostnameNoResolver) { return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort); Gather(); @@ -2063,7 +2055,10 @@ TEST_F(WebRtcIceGatherTest, TestGatherFakeStunServerTcpHostnameNoResolver) { return; } - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort, kNrIceTransportTcp); Gather(); @@ -2075,6 +2070,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherFakeStunServerIpAddress) { return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort); peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_); @@ -2086,8 +2084,15 @@ TEST_F(WebRtcIceGatherTest, TestGatherStunServerIpAddressNoHost) { return; } - peer_ = MakeUnique("P1", test_utils_, true, false, false, false, - NrIceCtx::ICE_POLICY_NO_HOST); + { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + } + + NrIceCtx::Config config; + config.mPolicy = NrIceCtx::ICE_POLICY_NO_HOST; + peer_ = MakeUnique("P1", test_utils_, true, config); peer_->AddStream(1); peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort); peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_); @@ -2100,6 +2105,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherFakeStunServerHostname) { return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort); peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_); @@ -2107,6 +2115,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherFakeStunServerHostname) { } TEST_F(WebRtcIceGatherTest, TestGatherFakeStunBogusHostname) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(kBogusStunServerHostname, kDefaultStunServerPort); peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_); @@ -2118,6 +2129,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerIpAddress) { return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort); peer_->SetDNSResolver(); @@ -2131,7 +2145,10 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerIpAddressTcp) { return; } - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort, kNrIceTransportTcp); peer_->SetDNSResolver(); @@ -2148,6 +2165,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerHostname) { return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort); peer_->SetDNSResolver(); @@ -2157,7 +2177,10 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerHostname) { } TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerHostnameTcp) { - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort, kNrIceTransportTcp); peer_->SetDNSResolver(); @@ -2176,7 +2199,10 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerHostnameBothUdpTcp) { std::vector stun_servers; - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); stun_servers.push_back(*NrIceStunServer::Create( stun_server_hostname_, kDefaultStunServerPort, kNrIceTransportUdp)); stun_servers.push_back(*NrIceStunServer::Create( @@ -2195,7 +2221,10 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerIpAddressBothUdpTcp) { std::vector stun_servers; - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); stun_servers.push_back(*NrIceStunServer::Create( stun_server_address_, kDefaultStunServerPort, kNrIceTransportUdp)); stun_servers.push_back(*NrIceStunServer::Create( @@ -2208,6 +2237,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunServerIpAddressBothUdpTcp) { } TEST_F(WebRtcIceGatherTest, TestGatherDNSStunBogusHostname) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(kBogusStunServerHostname, kDefaultStunServerPort); peer_->SetDNSResolver(); @@ -2216,7 +2248,10 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunBogusHostname) { } TEST_F(WebRtcIceGatherTest, TestGatherDNSStunBogusHostnameTcp) { - EnsurePeer(ICE_TEST_PEER_OFFERER | ICE_TEST_PEER_ENABLED_TCP); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); peer_->SetStunServer(kBogusStunServerHostname, kDefaultStunServerPort, kNrIceTransportTcp); peer_->SetDNSResolver(); @@ -2225,6 +2260,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherDNSStunBogusHostnameTcp) { } TEST_F(WebRtcIceGatherTest, TestDefaultCandidate) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort); Gather(); @@ -2233,6 +2271,9 @@ TEST_F(WebRtcIceGatherTest, TestDefaultCandidate) { } TEST_F(WebRtcIceGatherTest, TestGatherTurn) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); if (turn_server_.empty()) return; peer_->SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, @@ -2241,6 +2282,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherTurn) { } TEST_F(WebRtcIceGatherTest, TestGatherTurnTcp) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); if (turn_server_.empty()) return; peer_->SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, @@ -2253,6 +2297,9 @@ TEST_F(WebRtcIceGatherTest, TestGatherDisableComponent) { return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetStunServer(stun_server_hostname_, kDefaultStunServerPort); peer_->AddStream(2); @@ -2269,34 +2316,49 @@ TEST_F(WebRtcIceGatherTest, TestGatherDisableComponent) { } TEST_F(WebRtcIceGatherTest, TestGatherVerifyNoLoopback) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); Gather(); ASSERT_FALSE(StreamHasMatchingCandidate(0, "127.0.0.1")); } TEST_F(WebRtcIceGatherTest, TestGatherAllowLoopback) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + config.mAllowLoopback = true; + NrIceCtx::InitializeGlobals(config); + // Set up peer with loopback allowed. - peer_ = MakeUnique("P1", test_utils_, true, true); + peer_ = MakeUnique("P1", test_utils_, true, NrIceCtx::Config()); peer_->AddStream(1); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, "127.0.0.1")); } -TEST_F(WebRtcIceGatherTest, TestGatherTcpDisabled) { - // Set up peer with tcp disabled. - peer_ = MakeUnique("P1", test_utils_, true, false, false); - peer_->AddStream(1); +TEST_F(WebRtcIceGatherTest, TestGatherTcpDisabledNoStun) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + EnsurePeer(); Gather(); ASSERT_FALSE(StreamHasMatchingCandidate(0, " TCP ")); ASSERT_TRUE(StreamHasMatchingCandidate(0, " UDP ")); } TEST_F(WebRtcIceGatherTest, VerifyTestStunServer) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("192.0.2.133", 3333); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.133 3333 ")); } TEST_F(WebRtcIceGatherTest, VerifyTestStunTcpServer) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); UseFakeStunTcpServerWithResponse("192.0.2.233", 3333); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.233 3333 typ srflx", @@ -2308,12 +2370,18 @@ TEST_F(WebRtcIceGatherTest, VerifyTestStunServerV6) { // No V6 addresses return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("beef::", 3333); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, " beef:: 3333 ")); } TEST_F(WebRtcIceGatherTest, VerifyTestStunServerFQDN) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("192.0.2.133", 3333, "stun.example.com"); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.2.133 3333 ")); @@ -2324,12 +2392,18 @@ TEST_F(WebRtcIceGatherTest, VerifyTestStunServerV6FQDN) { // No V6 addresses return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("beef::", 3333, "stun.example.com"); Gather(); ASSERT_TRUE(StreamHasMatchingCandidate(0, " beef:: 3333 ")); } TEST_F(WebRtcIceGatherTest, TestStunServerReturnsWildcardAddr) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("0.0.0.0", 3333); Gather(kDefaultTimeout * 3); ASSERT_FALSE(StreamHasMatchingCandidate(0, " 0.0.0.0 ")); @@ -2340,18 +2414,27 @@ TEST_F(WebRtcIceGatherTest, TestStunServerReturnsWildcardAddrV6) { // No V6 addresses return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("::", 3333); Gather(kDefaultTimeout * 3); ASSERT_FALSE(StreamHasMatchingCandidate(0, " :: ")); } TEST_F(WebRtcIceGatherTest, TestStunServerReturnsPort0) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("192.0.2.133", 0); Gather(kDefaultTimeout * 3); ASSERT_FALSE(StreamHasMatchingCandidate(0, " 192.0.2.133 0 ")); } TEST_F(WebRtcIceGatherTest, TestStunServerReturnsLoopbackAddr) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("127.0.0.133", 3333); Gather(kDefaultTimeout * 3); ASSERT_FALSE(StreamHasMatchingCandidate(0, " 127.0.0.133 ")); @@ -2362,12 +2445,18 @@ TEST_F(WebRtcIceGatherTest, TestStunServerReturnsLoopbackAddrV6) { // No V6 addresses return; } + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("::1", 3333); Gather(kDefaultTimeout * 3); ASSERT_FALSE(StreamHasMatchingCandidate(0, " ::1 ")); } TEST_F(WebRtcIceGatherTest, TestStunServerTrickle) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpServerWithResponse("192.0.2.1", 3333); TestStunServer::GetInstance(AF_INET)->SetDropInitialPackets(3); Gather(0); @@ -2378,8 +2467,15 @@ TEST_F(WebRtcIceGatherTest, TestStunServerTrickle) { // Test no host with our fake STUN server and apparently NATted. TEST_F(WebRtcIceGatherTest, TestFakeStunServerNatedNoHost) { - peer_ = MakeUnique("P1", test_utils_, true, false, false, false, - NrIceCtx::ICE_POLICY_NO_HOST); + { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + } + + NrIceCtx::Config config; + config.mPolicy = NrIceCtx::ICE_POLICY_NO_HOST; + peer_ = MakeUnique("P1", test_utils_, true, config); peer_->AddStream(1); UseFakeStunUdpServerWithResponse("192.0.2.1", 3333); Gather(0); @@ -2396,8 +2492,15 @@ TEST_F(WebRtcIceGatherTest, TestFakeStunServerNatedNoHost) { // Test no host with our fake STUN server and apparently non-NATted. TEST_F(WebRtcIceGatherTest, TestFakeStunServerNoNatNoHost) { - peer_ = MakeUnique("P1", test_utils_, true, false, false, false, - NrIceCtx::ICE_POLICY_NO_HOST); + { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + } + + NrIceCtx::Config config; + config.mPolicy = NrIceCtx::ICE_POLICY_NO_HOST; + peer_ = MakeUnique("P1", test_utils_, true, config); peer_->AddStream(1); UseTestStunServer(); Gather(0); @@ -2408,6 +2511,9 @@ TEST_F(WebRtcIceGatherTest, TestFakeStunServerNoNatNoHost) { } TEST_F(WebRtcIceGatherTest, TestStunTcpServerTrickle) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); UseFakeStunTcpServerWithResponse("192.0.3.1", 3333); TestStunTcpServer::GetInstance(AF_INET)->SetDelay(500); Gather(0); @@ -2417,6 +2523,9 @@ TEST_F(WebRtcIceGatherTest, TestStunTcpServerTrickle) { } TEST_F(WebRtcIceGatherTest, TestStunTcpAndUdpServerTrickle) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); UseFakeStunUdpTcpServersWithResponse("192.0.2.1", 3333, "192.0.3.1", 3333); TestStunServer::GetInstance(AF_INET)->SetDropInitialPackets(3); TestStunTcpServer::GetInstance(AF_INET)->SetDelay(500); @@ -2429,6 +2538,9 @@ TEST_F(WebRtcIceGatherTest, TestStunTcpAndUdpServerTrickle) { } TEST_F(WebRtcIceGatherTest, TestSetIceControlling) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetControlling(NrIceCtx::ICE_CONTROLLING); NrIceCtx::Controlling controlling = peer_->GetControlling(); @@ -2440,6 +2552,9 @@ TEST_F(WebRtcIceGatherTest, TestSetIceControlling) { } TEST_F(WebRtcIceGatherTest, TestSetIceControlled) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); EnsurePeer(); peer_->SetControlling(NrIceCtx::ICE_CONTROLLED); NrIceCtx::Controlling controlling = peer_->GetControlling(); @@ -2451,29 +2566,44 @@ TEST_F(WebRtcIceGatherTest, TestSetIceControlled) { } TEST_F(WebRtcIceConnectTest, TestGather) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); } TEST_F(WebRtcIceConnectTest, TestGatherTcp) { - Init(false, true); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); } TEST_F(WebRtcIceConnectTest, TestGatherAutoPrioritize) { - Init(false, false); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); } TEST_F(WebRtcIceConnectTest, TestConnect) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); Connect(); } TEST_F(WebRtcIceConnectTest, TestConnectRestartIce) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); Connect(); @@ -2486,7 +2616,7 @@ TEST_F(WebRtcIceConnectTest, TestConnectRestartIce) { SendReceive(p1_.get(), p2_.get()); mozilla::UniquePtr p3_; - p3_ = MakeUnique("P3", test_utils_, true, false, false, false); + p3_ = MakeUnique("P3", test_utils_, true, NrIceCtx::Config()); InitPeer(p3_.get()); p3_->AddStream(1); @@ -2504,6 +2634,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectRestartIce) { } TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); Connect(); @@ -2516,7 +2649,7 @@ TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) { SendReceive(p1_.get(), p2_.get()); mozilla::UniquePtr p3_; - p3_ = MakeUnique("P3", test_utils_, true, false, false, false); + p3_ = MakeUnique("P3", test_utils_, true, NrIceCtx::Config()); InitPeer(p3_.get()); p3_->AddStream(1); @@ -2529,6 +2662,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) { } TEST_F(WebRtcIceConnectTest, TestConnectIceRestartRoleConflict) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); // Just for fun lets do this with switched rolls @@ -2547,7 +2683,7 @@ TEST_F(WebRtcIceConnectTest, TestConnectIceRestartRoleConflict) { << "ICE restart should not allow role to change, unless ice-lite happens"; mozilla::UniquePtr p3_; - p3_ = MakeUnique("P3", test_utils_, true, false, false, false); + p3_ = MakeUnique("P3", test_utils_, true, NrIceCtx::Config()); InitPeer(p3_.get()); p3_->AddStream(1); // Set control role for p3 accordingly (with role conflict) @@ -2586,6 +2722,9 @@ TEST_F(WebRtcIceConnectTest, ASSERT_EQ(0, r); strncpy(wifi_addr.addr.ifname, FAKE_WIFI_IF_NAME, MAXIFNAME); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); // setup initial ICE connection between p1_ and p2_ UseNat(); AddStream(1); @@ -2617,7 +2756,10 @@ TEST_F(WebRtcIceConnectTest, } TEST_F(WebRtcIceConnectTest, TestConnectTcp) { - Init(false, true); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); SetCandidateFilter(IsTcpCandidate); @@ -2629,7 +2771,10 @@ TEST_F(WebRtcIceConnectTest, TestConnectTcp) { // TCP SO tests works on localhost only with delay applied: // tc qdisc add dev lo root netem delay 10ms TEST_F(WebRtcIceConnectTest, DISABLED_TestConnectTcpSo) { - Init(false, true); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); SetCandidateFilter(IsTcpSoCandidate); @@ -2640,7 +2785,10 @@ TEST_F(WebRtcIceConnectTest, DISABLED_TestConnectTcpSo) { // Disabled because this breaks with hairpinning. TEST_F(WebRtcIceConnectTest, DISABLED_TestConnectNoHost) { - Init(false, false, false, NrIceCtx::ICE_POLICY_NO_HOST); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + Init(false, NrIceCtx::ICE_POLICY_NO_HOST); AddStream(1); ASSERT_TRUE(Gather()); SetExpectedTypes(NrIceCandidate::Type::ICE_SERVER_REFLEXIVE, @@ -2650,7 +2798,11 @@ TEST_F(WebRtcIceConnectTest, DISABLED_TestConnectNoHost) { } TEST_F(WebRtcIceConnectTest, TestLoopbackOnlySortOf) { - Init(true, false, false); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + config.mAllowLoopback = true; + NrIceCtx::InitializeGlobals(config); + Init(false); AddStream(1); SetCandidateFilter(IsLoopbackCandidate); ASSERT_TRUE(Gather()); @@ -2659,6 +2811,9 @@ TEST_F(WebRtcIceConnectTest, TestLoopbackOnlySortOf) { } TEST_F(WebRtcIceConnectTest, TestConnectBothControllingP1Wins) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); p1_->SetTiebreaker(1); p2_->SetTiebreaker(0); @@ -2669,6 +2824,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectBothControllingP1Wins) { } TEST_F(WebRtcIceConnectTest, TestConnectBothControllingP2Wins) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); p1_->SetTiebreaker(0); p2_->SetTiebreaker(1); @@ -2679,6 +2837,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectBothControllingP2Wins) { } TEST_F(WebRtcIceConnectTest, TestConnectIceLiteOfferer) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); p1_->SimulateIceLite(); @@ -2686,6 +2847,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectIceLiteOfferer) { } TEST_F(WebRtcIceConnectTest, TestTrickleBothControllingP1Wins) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); p1_->SetTiebreaker(1); p2_->SetTiebreaker(0); @@ -2699,6 +2863,9 @@ TEST_F(WebRtcIceConnectTest, TestTrickleBothControllingP1Wins) { } TEST_F(WebRtcIceConnectTest, TestTrickleBothControllingP2Wins) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); p1_->SetTiebreaker(0); p2_->SetTiebreaker(1); @@ -2712,6 +2879,9 @@ TEST_F(WebRtcIceConnectTest, TestTrickleBothControllingP2Wins) { } TEST_F(WebRtcIceConnectTest, TestTrickleIceLiteOfferer) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); p1_->SimulateIceLite(); @@ -2722,19 +2892,28 @@ TEST_F(WebRtcIceConnectTest, TestTrickleIceLiteOfferer) { } TEST_F(WebRtcIceConnectTest, TestGatherFullCone) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); AddStream(1); ASSERT_TRUE(Gather()); } TEST_F(WebRtcIceConnectTest, TestGatherFullConeAutoPrioritize) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); - Init(true, false); + Init(); AddStream(1); ASSERT_TRUE(Gather()); } TEST_F(WebRtcIceConnectTest, TestConnectFullCone) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); AddStream(1); SetExpectedTypes(NrIceCandidate::Type::ICE_SERVER_REFLEXIVE, @@ -2744,7 +2923,10 @@ TEST_F(WebRtcIceConnectTest, TestConnectFullCone) { } TEST_F(WebRtcIceConnectTest, TestConnectNoNatNoHost) { - Init(false, false, false, NrIceCtx::ICE_POLICY_NO_HOST); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + Init(false, NrIceCtx::ICE_POLICY_NO_HOST); AddStream(1); UseTestStunServer(); // Because we are connecting from our host candidate to the @@ -2757,8 +2939,11 @@ TEST_F(WebRtcIceConnectTest, TestConnectNoNatNoHost) { } TEST_F(WebRtcIceConnectTest, TestConnectFullConeNoHost) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); - Init(false, false, false, NrIceCtx::ICE_POLICY_NO_HOST); + Init(false, NrIceCtx::ICE_POLICY_NO_HOST); AddStream(1); UseTestStunServer(); SetExpectedTypes(NrIceCandidate::Type::ICE_SERVER_REFLEXIVE, @@ -2768,6 +2953,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectFullConeNoHost) { } TEST_F(WebRtcIceConnectTest, TestGatherAddressRestrictedCone) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); SetFilteringType(TestNat::ADDRESS_DEPENDENT); SetMappingType(TestNat::ENDPOINT_INDEPENDENT); @@ -2776,6 +2964,9 @@ TEST_F(WebRtcIceConnectTest, TestGatherAddressRestrictedCone) { } TEST_F(WebRtcIceConnectTest, TestConnectAddressRestrictedCone) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); SetFilteringType(TestNat::ADDRESS_DEPENDENT); SetMappingType(TestNat::ENDPOINT_INDEPENDENT); @@ -2787,6 +2978,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectAddressRestrictedCone) { } TEST_F(WebRtcIceConnectTest, TestGatherPortRestrictedCone) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); SetFilteringType(TestNat::PORT_DEPENDENT); SetMappingType(TestNat::ENDPOINT_INDEPENDENT); @@ -2795,6 +2989,9 @@ TEST_F(WebRtcIceConnectTest, TestGatherPortRestrictedCone) { } TEST_F(WebRtcIceConnectTest, TestConnectPortRestrictedCone) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); SetFilteringType(TestNat::PORT_DEPENDENT); SetMappingType(TestNat::ENDPOINT_INDEPENDENT); @@ -2806,6 +3003,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectPortRestrictedCone) { } TEST_F(WebRtcIceConnectTest, TestGatherSymmetricNat) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); SetFilteringType(TestNat::PORT_DEPENDENT); SetMappingType(TestNat::PORT_DEPENDENT); @@ -2816,6 +3016,9 @@ TEST_F(WebRtcIceConnectTest, TestGatherSymmetricNat) { TEST_F(WebRtcIceConnectTest, TestConnectSymmetricNat) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); SetFilteringType(TestNat::PORT_DEPENDENT); SetMappingType(TestNat::PORT_DEPENDENT); @@ -2831,12 +3034,19 @@ TEST_F(WebRtcIceConnectTest, TestConnectSymmetricNat) { } TEST_F(WebRtcIceConnectTest, TestConnectSymmetricNatAndNoNat) { - p1_ = MakeUnique("P1", test_utils_, true, false, false); + { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + } + + NrIceCtx::Config config; + p1_ = MakeUnique("P1", test_utils_, true, config); p1_->UseNat(); p1_->SetFilteringType(TestNat::PORT_DEPENDENT); p1_->SetMappingType(TestNat::PORT_DEPENDENT); - p2_ = MakeUnique("P2", test_utils_, false, false, false); + p2_ = MakeUnique("P2", test_utils_, false, config); initted_ = true; AddStream(1); @@ -2851,6 +3061,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectSymmetricNatAndNoNat) { TEST_F(WebRtcIceConnectTest, TestGatherNatBlocksUDP) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); BlockUdp(); AddStream(1); @@ -2871,6 +3084,9 @@ TEST_F(WebRtcIceConnectTest, TestGatherNatBlocksUDP) { TEST_F(WebRtcIceConnectTest, TestConnectNatBlocksUDP) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); UseNat(); BlockUdp(); AddStream(1); @@ -2893,12 +3109,18 @@ TEST_F(WebRtcIceConnectTest, TestConnectNatBlocksUDP) { } TEST_F(WebRtcIceConnectTest, TestConnectTwoComponents) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(2); ASSERT_TRUE(Gather()); Connect(); } TEST_F(WebRtcIceConnectTest, TestConnectTwoComponentsDisableSecond) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(2); ASSERT_TRUE(Gather()); p1_->DisableComponent(0, 2); @@ -2907,6 +3129,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTwoComponentsDisableSecond) { } TEST_F(WebRtcIceConnectTest, TestConnectP2ThenP1) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectP2(); @@ -2916,6 +3141,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectP2ThenP1) { } TEST_F(WebRtcIceConnectTest, TestConnectP2ThenP1Trickle) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectP2(); @@ -2926,6 +3154,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectP2ThenP1Trickle) { } TEST_F(WebRtcIceConnectTest, TestConnectP2ThenP1TrickleTwoComponents) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(2); ASSERT_TRUE(Gather()); @@ -2941,13 +3172,19 @@ TEST_F(WebRtcIceConnectTest, TestConnectP2ThenP1TrickleTwoComponents) { } TEST_F(WebRtcIceConnectTest, TestConnectAutoPrioritize) { - Init(false, false); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); Connect(); } TEST_F(WebRtcIceConnectTest, TestConnectTrickleOneStreamOneComponent) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectTrickle(); @@ -2957,6 +3194,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTrickleOneStreamOneComponent) { } TEST_F(WebRtcIceConnectTest, TestConnectTrickleTwoStreamsOneComponent) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); ASSERT_TRUE(Gather()); @@ -3038,6 +3278,9 @@ void DropTrickleCandidates( std::vector& candidates) {} TEST_F(WebRtcIceConnectTest, TestConnectTrickleAddStreamDuringICE) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectTrickle(); @@ -3051,6 +3294,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTrickleAddStreamDuringICE) { } TEST_F(WebRtcIceConnectTest, TestConnectTrickleAddStreamAfterICE) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectTrickle(); @@ -3067,6 +3313,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTrickleAddStreamAfterICE) { } TEST_F(WebRtcIceConnectTest, RemoveStream) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); ASSERT_TRUE(Gather()); @@ -3083,6 +3332,9 @@ TEST_F(WebRtcIceConnectTest, RemoveStream) { } TEST_F(WebRtcIceConnectTest, P1NoTrickle) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectTrickle(); @@ -3092,6 +3344,9 @@ TEST_F(WebRtcIceConnectTest, P1NoTrickle) { } TEST_F(WebRtcIceConnectTest, P2NoTrickle) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectTrickle(); @@ -3101,6 +3356,9 @@ TEST_F(WebRtcIceConnectTest, P2NoTrickle) { } TEST_F(WebRtcIceConnectTest, RemoveAndAddStream) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); ASSERT_TRUE(Gather()); @@ -3121,6 +3379,9 @@ TEST_F(WebRtcIceConnectTest, RemoveAndAddStream) { } TEST_F(WebRtcIceConnectTest, RemoveStreamBeforeGather) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); ASSERT_TRUE(Gather(0)); @@ -3133,6 +3394,9 @@ TEST_F(WebRtcIceConnectTest, RemoveStreamBeforeGather) { } TEST_F(WebRtcIceConnectTest, RemoveStreamDuringGather) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); RemoveStream(0); @@ -3144,6 +3408,9 @@ TEST_F(WebRtcIceConnectTest, RemoveStreamDuringGather) { } TEST_F(WebRtcIceConnectTest, RemoveStreamDuringConnect) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); ASSERT_TRUE(Gather()); @@ -3157,6 +3424,9 @@ TEST_F(WebRtcIceConnectTest, RemoveStreamDuringConnect) { } TEST_F(WebRtcIceConnectTest, TestConnectRealTrickleOneStreamOneComponent) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); AddStream(1); ASSERT_TRUE(Gather(0)); @@ -3167,6 +3437,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectRealTrickleOneStreamOneComponent) { } TEST_F(WebRtcIceConnectTest, TestSendReceive) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); Connect(); @@ -3174,7 +3447,10 @@ TEST_F(WebRtcIceConnectTest, TestSendReceive) { } TEST_F(WebRtcIceConnectTest, TestSendReceiveTcp) { - Init(false, true); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); SetCandidateFilter(IsTcpCandidate); @@ -3187,7 +3463,10 @@ TEST_F(WebRtcIceConnectTest, TestSendReceiveTcp) { // TCP SO tests works on localhost only with delay applied: // tc qdisc add dev lo root netem delay 10ms TEST_F(WebRtcIceConnectTest, DISABLED_TestSendReceiveTcpSo) { - Init(false, true); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); ASSERT_TRUE(Gather()); SetCandidateFilter(IsTcpSoCandidate); @@ -3198,6 +3477,9 @@ TEST_F(WebRtcIceConnectTest, DISABLED_TestSendReceiveTcpSo) { } TEST_F(WebRtcIceConnectTest, TestConsent) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); PR_Sleep(1500); @@ -3206,7 +3488,10 @@ TEST_F(WebRtcIceConnectTest, TestConsent) { } TEST_F(WebRtcIceConnectTest, TestConsentTcp) { - Init(false, true); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = true; + NrIceCtx::InitializeGlobals(config); + Init(); AddStream(1); SetCandidateFilter(IsTcpCandidate); SetExpectedTypes(NrIceCandidate::Type::ICE_HOST, @@ -3218,6 +3503,9 @@ TEST_F(WebRtcIceConnectTest, TestConsentTcp) { } TEST_F(WebRtcIceConnectTest, TestConsentIntermittent) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); p1_->SetBlockStun(true); @@ -3242,6 +3530,9 @@ TEST_F(WebRtcIceConnectTest, TestConsentIntermittent) { } TEST_F(WebRtcIceConnectTest, TestConsentTimeout) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); p1_->SetBlockStun(true); @@ -3255,6 +3546,9 @@ TEST_F(WebRtcIceConnectTest, TestConsentTimeout) { } TEST_F(WebRtcIceConnectTest, TestConsentDelayed) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); /* Note: We don't have a list of STUN transaction IDs of the previously timed @@ -3268,6 +3562,9 @@ TEST_F(WebRtcIceConnectTest, TestConsentDelayed) { } TEST_F(WebRtcIceConnectTest, TestNetworkForcedOfflineAndRecovery) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); p1_->ChangeNetworkStateToOffline(); @@ -3277,6 +3574,9 @@ TEST_F(WebRtcIceConnectTest, TestNetworkForcedOfflineAndRecovery) { } TEST_F(WebRtcIceConnectTest, TestNetworkForcedOfflineTwice) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); p2_->ChangeNetworkStateToOffline(); @@ -3286,6 +3586,9 @@ TEST_F(WebRtcIceConnectTest, TestNetworkForcedOfflineTwice) { } TEST_F(WebRtcIceConnectTest, TestNetworkOnlineDoesntChangeState) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetupAndCheckConsent(); p2_->ChangeNetworkStateToOnline(); @@ -3296,6 +3599,9 @@ TEST_F(WebRtcIceConnectTest, TestNetworkOnlineDoesntChangeState) { } TEST_F(WebRtcIceConnectTest, TestNetworkOnlineTriggersConsent) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); // Let's emulate audio + video w/o rtcp-mux AddStream(2); AddStream(2); @@ -3313,6 +3619,9 @@ TEST_F(WebRtcIceConnectTest, TestNetworkOnlineTriggersConsent) { TEST_F(WebRtcIceConnectTest, TestConnectTurn) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3323,6 +3632,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurn) { TEST_F(WebRtcIceConnectTest, TestConnectTurnWithDelay) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3338,6 +3650,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnWithDelay) { TEST_F(WebRtcIceConnectTest, TestConnectTurnWithNormalTrickleDelay) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3353,6 +3668,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnWithNormalTrickleDelay) { TEST_F(WebRtcIceConnectTest, TestConnectTurnWithNormalTrickleDelayOneSided) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3368,6 +3686,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnWithNormalTrickleDelayOneSided) { TEST_F(WebRtcIceConnectTest, TestConnectTurnWithLargeTrickleDelay) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3385,6 +3706,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnWithLargeTrickleDelay) { TEST_F(WebRtcIceConnectTest, TestConnectTurnTcp) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_, kNrIceTransportTcp); @@ -3395,6 +3719,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnTcp) { TEST_F(WebRtcIceConnectTest, TestConnectTurnOnly) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3408,6 +3735,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnOnly) { TEST_F(WebRtcIceConnectTest, TestConnectTurnTcpOnly) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_, kNrIceTransportTcp); @@ -3421,6 +3751,9 @@ TEST_F(WebRtcIceConnectTest, TestConnectTurnTcpOnly) { TEST_F(WebRtcIceConnectTest, TestSendReceiveTurnOnly) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_); @@ -3435,6 +3768,9 @@ TEST_F(WebRtcIceConnectTest, TestSendReceiveTurnOnly) { TEST_F(WebRtcIceConnectTest, TestSendReceiveTurnTcpOnly) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); SetTurnServer(turn_server_, kDefaultStunServerPort, turn_user_, turn_password_, kNrIceTransportTcp); @@ -3449,6 +3785,9 @@ TEST_F(WebRtcIceConnectTest, TestSendReceiveTurnTcpOnly) { TEST_F(WebRtcIceConnectTest, TestSendReceiveTurnBothOnly) { if (turn_server_.empty()) return; + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); std::vector turn_servers; std::vector password_vec(turn_password_.begin(), @@ -3470,12 +3809,18 @@ TEST_F(WebRtcIceConnectTest, TestSendReceiveTurnBothOnly) { } TEST_F(WebRtcIceConnectTest, TestConnectShutdownOneSide) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); ConnectThenDelete(); } TEST_F(WebRtcIceConnectTest, TestPollCandPairsBeforeConnect) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); @@ -3491,6 +3836,9 @@ TEST_F(WebRtcIceConnectTest, TestPollCandPairsBeforeConnect) { } TEST_F(WebRtcIceConnectTest, TestPollCandPairsAfterConnect) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); Connect(); @@ -3516,7 +3864,10 @@ TEST_F(WebRtcIceConnectTest, TestPollCandPairsAfterConnect) { // TODO Bug 1259842 - disabled until we find a better way to handle two // candidates from different RFC1918 ranges TEST_F(WebRtcIceConnectTest, DISABLED_TestHostCandPairingFilter) { - Init(false, false, false); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + Init(false); AddStream(1); ASSERT_TRUE(Gather()); SetCandidateFilter(IsIpv4Candidate); @@ -3555,7 +3906,10 @@ TEST_F(WebRtcIceConnectTest, DISABLED_TestSrflxCandPairingFilter) { return; } - Init(false, false, false); + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); + Init(false); AddStream(1); ASSERT_TRUE(Gather()); SetCandidateFilter(IsSrflxCandidate); @@ -3599,6 +3953,9 @@ TEST_F(WebRtcIceConnectTest, DISABLED_TestSrflxCandPairingFilter) { } TEST_F(WebRtcIceConnectTest, TestPollCandPairsDuringConnect) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); @@ -3624,6 +3981,9 @@ TEST_F(WebRtcIceConnectTest, TestPollCandPairsDuringConnect) { } TEST_F(WebRtcIceConnectTest, TestRLogConnector) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); ASSERT_TRUE(Gather()); @@ -3667,6 +4027,9 @@ TEST_F(WebRtcIceConnectTest, TestRLogConnector) { // Verify that a bogus candidate doesn't cause crashes on the // main thread. See bug 856433. TEST_F(WebRtcIceConnectTest, TestBogusCandidate) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); Gather(); ConnectTrickle(); @@ -3679,6 +4042,9 @@ TEST_F(WebRtcIceConnectTest, TestBogusCandidate) { } TEST_F(WebRtcIceConnectTest, TestNonMDNSCandidate) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); Gather(); ConnectTrickle(); @@ -3692,6 +4058,9 @@ TEST_F(WebRtcIceConnectTest, TestNonMDNSCandidate) { } TEST_F(WebRtcIceConnectTest, TestMDNSCandidate) { + NrIceCtx::GlobalConfig config; + config.mTcpEnabled = false; + NrIceCtx::InitializeGlobals(config); AddStream(1); Gather(); ConnectTrickle(); diff --git a/media/mtransport/test/multi_tcp_socket_unittest.cpp b/media/mtransport/test/multi_tcp_socket_unittest.cpp index a242c8406695..720db1bca255 100644 --- a/media/mtransport/test/multi_tcp_socket_unittest.cpp +++ b/media/mtransport/test/multi_tcp_socket_unittest.cpp @@ -43,7 +43,8 @@ class MultiTcpSocketTest : public MtransportTest { void SetUp() { MtransportTest::SetUp(); - ice_ctx_ = NrIceCtx::Create("stun", true); + NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig()); + ice_ctx_ = NrIceCtx::Create("stun", NrIceCtx::Config()); test_utils_->sts_target()->Dispatch( WrapRunnableNM(&TestStunTcpServer::GetInstance, AF_INET), diff --git a/media/mtransport/test/test_nr_socket_ice_unittest.cpp b/media/mtransport/test/test_nr_socket_ice_unittest.cpp index b9036368da9b..84ee2e95863a 100644 --- a/media/mtransport/test/test_nr_socket_ice_unittest.cpp +++ b/media/mtransport/test/test_nr_socket_ice_unittest.cpp @@ -307,7 +307,7 @@ class TestNrSocketIceUnitTest : public ::testing::Test { test_utils_ = new MtransportTestUtils(); test_utils2_ = new MtransportTestUtils(); - NrIceCtx::InitializeGlobals(false, false, false); + NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig()); } void TearDown() override { diff --git a/media/mtransport/test/transport_unittests.cpp b/media/mtransport/test/transport_unittests.cpp index 311c62e68a4c..7427032d0f13 100644 --- a/media/mtransport/test/transport_unittests.cpp +++ b/media/mtransport/test/transport_unittests.cpp @@ -442,7 +442,7 @@ class TransportTestPeer : public sigslot::has_slots<> { lossy_(new TransportLayerLossy()), dtls_(new TransportLayerDtls()), identity_(DtlsIdentity::Generate()), - ice_ctx_(NrIceCtx::Create(name)), + ice_ctx_(), streams_(), peer_(nullptr), gathering_complete_(false), @@ -450,6 +450,8 @@ class TransportTestPeer : public sigslot::has_slots<> { enabled_cipersuites_(), disabled_cipersuites_(), test_utils_(utils) { + NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig()); + ice_ctx_ = NrIceCtx::Create(name, NrIceCtx::Config()); std::vector stun_servers; UniquePtr server(NrIceStunServer::Create( std::string((char*)"stun.services.mozilla.com"), 3478)); diff --git a/media/mtransport/test/turn_unittest.cpp b/media/mtransport/test/turn_unittest.cpp index 8157dce7ef46..8ba7b8db157a 100644 --- a/media/mtransport/test/turn_unittest.cpp +++ b/media/mtransport/test/turn_unittest.cpp @@ -96,7 +96,7 @@ class TurnClient : public MtransportTest { ~TurnClient() = default; static void SetUpTestCase() { - NrIceCtx::InitializeGlobals(false, false, false); + NrIceCtx::InitializeGlobals(NrIceCtx::GlobalConfig()); } void SetTcp() { protocol_ = IPPROTO_TCP; } diff --git a/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp b/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp index 29d8e5449e6b..7b814cdfb380 100644 --- a/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp +++ b/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp @@ -159,8 +159,8 @@ class MediaTransportHandlerSTS : public MediaTransportHandler, RefPtr mDNSResolver; std::map mTransports; bool mObfuscateHostAddresses = false; - uint32_t minDtlsVersion = 0; - uint32_t maxDtlsVersion = 0; + uint32_t mMinDtlsVersion = 0; + uint32_t mMaxDtlsVersion = 0; std::set mSignaledAddresses; @@ -340,6 +340,56 @@ nsresult MediaTransportHandler::ConvertIceServers( return NS_OK; } +static NrIceCtx::GlobalConfig GetGlobalConfig() { + NrIceCtx::GlobalConfig config; + config.mAllowLinkLocal = + Preferences::GetBool("media.peerconnection.ice.link_local", false); + config.mAllowLoopback = + Preferences::GetBool("media.peerconnection.ice.loopback", false); + config.mTcpEnabled = + Preferences::GetBool("media.peerconnection.ice.tcp", false); + config.mStunClientMaxTransmits = Preferences::GetInt( + "media.peerconnection.ice.stun_client_maximum_transmits", + config.mStunClientMaxTransmits); + config.mTrickleIceGracePeriod = + Preferences::GetInt("media.peerconnection.ice.trickle_grace_period", + config.mTrickleIceGracePeriod); + config.mIceTcpSoSockCount = Preferences::GetInt( + "media.peerconnection.ice.tcp_so_sock_count", config.mIceTcpSoSockCount); + config.mIceTcpListenBacklog = + Preferences::GetInt("media.peerconnection.ice.tcp_listen_backlog", + config.mIceTcpListenBacklog); + (void)Preferences::GetCString("media.peerconnection.ice.force_interface", + config.mForceNetInterface); + return config; +} + +static Maybe GetNatConfig() { + bool block_tcp = Preferences::GetBool( + "media.peerconnection.nat_simulator.block_tcp", false); + bool block_udp = Preferences::GetBool( + "media.peerconnection.nat_simulator.block_udp", false); + nsAutoCString mapping_type; + (void)Preferences::GetCString( + "media.peerconnection.nat_simulator.mapping_type", mapping_type); + nsAutoCString filtering_type; + (void)Preferences::GetCString( + "media.peerconnection.nat_simulator.filtering_type", filtering_type); + + if (block_udp || block_tcp || !mapping_type.IsEmpty() || + !filtering_type.IsEmpty()) { + CSFLogDebug(LOGTAG, "NAT filtering type: %s", filtering_type.get()); + CSFLogDebug(LOGTAG, "NAT mapping type: %s", mapping_type.get()); + NrIceCtx::NatSimulatorConfig natConfig; + natConfig.mBlockUdp = block_udp; + natConfig.mBlockTcp = block_tcp; + natConfig.mFilteringType = filtering_type; + natConfig.mMappingType = mapping_type; + return Some(natConfig); + } + return Nothing(); +} + nsresult MediaTransportHandlerSTS::CreateIceCtx( const std::string& aName, const nsTArray& aIceServers, dom::RTCIceTransportPolicy aIcePolicy) { @@ -371,72 +421,80 @@ nsresult MediaTransportHandlerSTS::CreateIceCtx( mozilla::psm::DisableMD5(); } - // This stuff will probably live on the other side of IPC; errors down - // here will either need to be ignored, or plumbed back in some way - // other than the return. - bool allowLoopback = - Preferences::GetBool("media.peerconnection.ice.loopback", false); - bool tcpEnabled = - Preferences::GetBool("media.peerconnection.ice.tcp", false); - bool allowLinkLocal = - Preferences::GetBool("media.peerconnection.ice.link_local", false); - - mIceCtx = NrIceCtx::Create(aName, allowLoopback, tcpEnabled, - allowLinkLocal, toNrIcePolicy(aIcePolicy)); - if (!mIceCtx) { - return InitPromise::CreateAndReject("NrIceCtx::Create failed", - __func__); + static bool globalInitDone = false; + if (!globalInitDone) { + mStsThread->Dispatch( + WrapRunnableNM(&NrIceCtx::InitializeGlobals, GetGlobalConfig()), + NS_DISPATCH_NORMAL); + globalInitDone = true; } - mIceCtx->SignalGatheringStateChange.connect( - this, &MediaTransportHandlerSTS::OnGatheringStateChange); - mIceCtx->SignalConnectionStateChange.connect( - this, &MediaTransportHandlerSTS::OnConnectionStateChange); - - nsresult rv; - - if (NS_FAILED(rv = mIceCtx->SetStunServers(stunServers))) { - CSFLogError(LOGTAG, "%s: Failed to set stun servers", __FUNCTION__); - return InitPromise::CreateAndReject("Failed to set stun servers", - __func__); - } // Give us a way to globally turn off TURN support - bool disabled = + bool turnDisabled = Preferences::GetBool("media.peerconnection.turn.disable", false); - if (!disabled) { - if (NS_FAILED(rv = mIceCtx->SetTurnServers(turnServers))) { - CSFLogError(LOGTAG, "%s: Failed to set turn servers", __FUNCTION__); - return InitPromise::CreateAndReject("Failed to set turn servers", - __func__); - } - } else if (!turnServers.empty()) { - CSFLogError(LOGTAG, "%s: Setting turn servers disabled", - __FUNCTION__); - } - - mDNSResolver = new NrIceResolver; - if (NS_FAILED(rv = mDNSResolver->Init())) { - CSFLogError(LOGTAG, "%s: Failed to initialize dns resolver", - __FUNCTION__); - return InitPromise::CreateAndReject( - "Failed to initialize dns resolver", __func__); - } - if (NS_FAILED( - rv = mIceCtx->SetResolver(mDNSResolver->AllocateResolver()))) { - CSFLogError(LOGTAG, "%s: Failed to get dns resolver", __FUNCTION__); - return InitPromise::CreateAndReject("Failed to get dns resolver", - __func__); - } - // We are reading these here, because when we setup the DTLS transport // we are on the wrong thread to read prefs - minDtlsVersion = + mMinDtlsVersion = Preferences::GetUint("media.peerconnection.dtls.version.min"); - maxDtlsVersion = + mMaxDtlsVersion = Preferences::GetUint("media.peerconnection.dtls.version.max"); - CSFLogDebug(LOGTAG, "%s done", __func__); - return InitPromise::CreateAndResolve(true, __func__); + NrIceCtx::Config config; + config.mPolicy = toNrIcePolicy(aIcePolicy); + config.mNatSimulatorConfig = GetNatConfig(); + + return InvokeAsync( + mStsThread, __func__, + [=, self = RefPtr(this)]() { + mIceCtx = NrIceCtx::Create(aName, config); + if (!mIceCtx) { + return InitPromise::CreateAndReject("NrIceCtx::Create failed", + __func__); + } + + mIceCtx->SignalGatheringStateChange.connect( + this, &MediaTransportHandlerSTS::OnGatheringStateChange); + mIceCtx->SignalConnectionStateChange.connect( + this, &MediaTransportHandlerSTS::OnConnectionStateChange); + + nsresult rv; + + if (NS_FAILED(rv = mIceCtx->SetStunServers(stunServers))) { + CSFLogError(LOGTAG, "%s: Failed to set stun servers", + __FUNCTION__); + return InitPromise::CreateAndReject( + "Failed to set stun servers", __func__); + } + if (!turnDisabled) { + if (NS_FAILED(rv = mIceCtx->SetTurnServers(turnServers))) { + CSFLogError(LOGTAG, "%s: Failed to set turn servers", + __FUNCTION__); + return InitPromise::CreateAndReject( + "Failed to set turn servers", __func__); + } + } else if (!turnServers.empty()) { + CSFLogError(LOGTAG, "%s: Setting turn servers disabled", + __FUNCTION__); + } + + mDNSResolver = new NrIceResolver; + if (NS_FAILED(rv = mDNSResolver->Init())) { + CSFLogError(LOGTAG, "%s: Failed to initialize dns resolver", + __FUNCTION__); + return InitPromise::CreateAndReject( + "Failed to initialize dns resolver", __func__); + } + if (NS_FAILED(rv = mIceCtx->SetResolver( + mDNSResolver->AllocateResolver()))) { + CSFLogError(LOGTAG, "%s: Failed to get dns resolver", + __FUNCTION__); + return InitPromise::CreateAndReject( + "Failed to get dns resolver", __func__); + } + + CSFLogDebug(LOGTAG, "%s done", __func__); + return InitPromise::CreateAndResolve(true, __func__); + }); }); return NS_OK; } @@ -1193,8 +1251,8 @@ RefPtr MediaTransportHandlerSTS::CreateTransportFlow( dtls->SetIdentity(aDtlsIdentity); dtls->SetMinMaxVersion( - static_cast(minDtlsVersion), - static_cast(maxDtlsVersion)); + static_cast(mMinDtlsVersion), + static_cast(mMaxDtlsVersion)); for (const auto& digest : aDigests) { rv = dtls->SetVerificationDigest(digest);