diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index 6d04468790..8a1ec0ddf5 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -265,7 +265,7 @@ class P2PTransportChannelTestBase : public ::testing::Test, ss_(new rtc::FirewallSocketServer(nss_.get())), main_(ss_.get()), stun_server_(TestStunServer::Create(ss_.get(), kStunAddr)), - turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), + turn_server_(&main_, ss_.get(), kTurnUdpIntAddr, kTurnUdpExtAddr), socks_server1_(ss_.get(), kSocksProxyAddrs[0], ss_.get(), @@ -3498,6 +3498,8 @@ class P2PTransportChannelPingTest : public ::testing::Test, } } + rtc::SocketServer* ss() const { return vss_.get(); } + private: std::unique_ptr vss_; rtc::AutoSocketServerThread thread_; @@ -4825,7 +4827,10 @@ class P2PTransportChannelMostLikelyToWorkFirstTest : public P2PTransportChannelPingTest { public: P2PTransportChannelMostLikelyToWorkFirstTest() - : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { + : turn_server_(rtc::Thread::Current(), + ss(), + kTurnUdpIntAddr, + kTurnUdpExtAddr) { network_manager_.AddInterface(kPublicAddrs[0]); allocator_.reset( CreateBasicPortAllocator(&network_manager_, ServerAddresses(), diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index dc32463dab..129c71c88b 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc @@ -402,7 +402,7 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { nat_socket_factory1_(&nat_factory1_), nat_socket_factory2_(&nat_factory2_), stun_server_(TestStunServer::Create(ss_.get(), kStunAddr)), - turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), + turn_server_(&main_, ss_.get(), kTurnUdpIntAddr, kTurnUdpExtAddr), username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), role_conflict_(false), @@ -2591,7 +2591,7 @@ TEST_F(PortTest, TestCandidateFoundation) { // Running a second turn server, to get different base IP address. SocketAddress kTurnUdpIntAddr2("99.99.98.4", STUN_SERVER_PORT); SocketAddress kTurnUdpExtAddr2("99.99.98.5", 0); - TestTurnServer turn_server2(rtc::Thread::Current(), kTurnUdpIntAddr2, + TestTurnServer turn_server2(rtc::Thread::Current(), vss(), kTurnUdpIntAddr2, kTurnUdpExtAddr2); auto turnport3 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP, kTurnUdpIntAddr2); @@ -2602,7 +2602,7 @@ TEST_F(PortTest, TestCandidateFoundation) { // Start a TCP turn server, and check that two turn candidates have // different foundations if their relay protocols are different. - TestTurnServer turn_server3(rtc::Thread::Current(), kTurnTcpIntAddr, + TestTurnServer turn_server3(rtc::Thread::Current(), vss(), kTurnTcpIntAddr, kTurnUdpExtAddr, PROTO_TCP); auto turnport4 = CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_TCP, PROTO_UDP); diff --git a/p2p/base/test_turn_server.h b/p2p/base/test_turn_server.h index bbdc5663b0..7110a8a5a0 100644 --- a/p2p/base/test_turn_server.h +++ b/p2p/base/test_turn_server.h @@ -53,18 +53,16 @@ class TestTurnRedirector : public TurnRedirectInterface { class TestTurnServer : public TurnAuthInterface { public: TestTurnServer(rtc::Thread* thread, + rtc::SocketFactory* socket_factory, const rtc::SocketAddress& int_addr, const rtc::SocketAddress& udp_ext_addr, ProtocolType int_protocol = PROTO_UDP, bool ignore_bad_cert = true, const std::string& common_name = "test turn server") - : server_(thread), thread_(thread) { + : server_(thread), socket_factory_(socket_factory) { AddInternalSocket(int_addr, int_protocol, ignore_bad_cert, common_name); - // TODO(bugs.webrtc.org/13145): Take a SocketFactory as argument, so we - // don't need thread_->socketserver(). server_.SetExternalSocketFactory( - new rtc::BasicPacketSocketFactory(thread_->socketserver()), - udp_ext_addr); + new rtc::BasicPacketSocketFactory(socket_factory), udp_ext_addr); server_.set_realm(kTestRealm); server_.set_software(kTestSoftware); server_.set_auth_hook(this); @@ -99,13 +97,11 @@ class TestTurnServer : public TurnAuthInterface { RTC_DCHECK(thread_checker_.IsCurrent()); if (proto == cricket::PROTO_UDP) { server_.AddInternalSocket( - rtc::AsyncUDPSocket::Create(thread_->socketserver(), int_addr), - proto); + rtc::AsyncUDPSocket::Create(socket_factory_, int_addr), proto); } else if (proto == cricket::PROTO_TCP || proto == cricket::PROTO_TLS) { // For TCP we need to create a server socket which can listen for incoming // new connections. - rtc::Socket* socket = - thread_->socketserver()->CreateSocket(AF_INET, SOCK_STREAM); + rtc::Socket* socket = socket_factory_->CreateSocket(AF_INET, SOCK_STREAM); socket->Bind(int_addr); socket->Listen(5); if (proto == cricket::PROTO_TLS) { @@ -154,7 +150,7 @@ class TestTurnServer : public TurnAuthInterface { } TurnServer server_; - rtc::Thread* thread_; + rtc::SocketFactory* socket_factory_; webrtc::SequenceChecker thread_checker_; }; diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index f16a5b8dd3..a625d60e0f 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc @@ -172,7 +172,7 @@ class TurnPortTest : public ::testing::Test, : ss_(new TurnPortTestVirtualSocketServer()), main_(ss_.get()), socket_factory_(ss_.get()), - turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), + turn_server_(&main_, ss_.get(), kTurnUdpIntAddr, kTurnUdpExtAddr), turn_ready_(false), turn_error_(false), turn_unknown_address_(false), diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc index 52ba168cbc..6db82d2e30 100644 --- a/p2p/client/basic_port_allocator_unittest.cc +++ b/p2p/client/basic_port_allocator_unittest.cc @@ -153,7 +153,10 @@ class BasicPortAllocatorTestBase : public ::testing::Test, nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), stun_server_(TestStunServer::Create(fss_.get(), kStunAddr)), - turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), + turn_server_(rtc::Thread::Current(), + fss_.get(), + kTurnUdpIntAddr, + kTurnUdpExtAddr), candidate_allocation_done_(false) { ServerAddresses stun_servers; stun_servers.insert(kStunAddr); diff --git a/pc/peer_connection_rampup_tests.cc b/pc/peer_connection_rampup_tests.cc index 5cf30d83a7..d845b57cb3 100644 --- a/pc/peer_connection_rampup_tests.cc +++ b/pc/peer_connection_rampup_tests.cc @@ -233,15 +233,16 @@ class PeerConnectionRampUpTest : public ::testing::Test { void CreateTurnServer(cricket::ProtocolType type, const std::string& common_name = "test turn server") { rtc::Thread* thread = network_thread(); + rtc::SocketFactory* factory = firewall_socket_server_.get(); std::unique_ptr turn_server = network_thread_->Invoke>( - RTC_FROM_HERE, [thread, type, common_name] { + RTC_FROM_HERE, [thread, factory, type, common_name] { static const rtc::SocketAddress turn_server_internal_address{ kTurnInternalAddress, kTurnInternalPort}; static const rtc::SocketAddress turn_server_external_address{ kTurnExternalAddress, kTurnExternalPort}; return std::make_unique( - thread, turn_server_internal_address, + thread, factory, turn_server_internal_address, turn_server_external_address, type, true /*ignore_bad_certs=*/, common_name); }); diff --git a/pc/test/integration_test_helpers.h b/pc/test/integration_test_helpers.h index 6c60ba81ab..fb59092496 100644 --- a/pc/test/integration_test_helpers.h +++ b/pc/test/integration_test_helpers.h @@ -1548,12 +1548,14 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP, const std::string& common_name = "test turn server") { rtc::Thread* thread = network_thread(); + rtc::SocketFactory* socket_factory = fss_.get(); std::unique_ptr turn_server = network_thread()->Invoke>( - RTC_FROM_HERE, - [thread, internal_address, external_address, type, common_name] { + RTC_FROM_HERE, [thread, socket_factory, internal_address, + external_address, type, common_name] { return std::make_unique( - thread, internal_address, external_address, type, + thread, socket_factory, internal_address, external_address, + type, /*ignore_bad_certs=*/true, common_name); }); turn_servers_.push_back(std::move(turn_server));