diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn index ff558a9ac4..22286c4860 100644 --- a/p2p/BUILD.gn +++ b/p2p/BUILD.gn @@ -129,6 +129,7 @@ if (rtc_include_tests) { "base/fakeportallocator.h", "base/mockicetransport.h", "base/testrelayserver.h", + "base/teststunserver.cc", "base/teststunserver.h", "base/testturncustomizer.h", "base/testturnserver.h", @@ -201,12 +202,6 @@ rtc_static_library("libstunprober") { "stunprober/stunprober.h", ] - if (!build_with_chromium && is_clang) { - # Suppress warnings from Chrome's Clang plugins. - # See http://code.google.com/p/webrtc/issues/detail?id=163 for details. - suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] - } - deps = [ ":rtc_p2p", "..:webrtc_common", @@ -236,10 +231,6 @@ if (rtc_include_tests) { "//testing/gmock", "//testing/gtest", ] - if (!build_with_chromium && is_clang) { - # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163). - suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] - } defines = [ "GTEST_RELATIVE_PATH" ] } } diff --git a/p2p/base/basicpacketsocketfactory.cc b/p2p/base/basicpacketsocketfactory.cc index eb36bc2dd7..7438a9b22f 100644 --- a/p2p/base/basicpacketsocketfactory.cc +++ b/p2p/base/basicpacketsocketfactory.cc @@ -104,6 +104,18 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket( return new AsyncTCPSocket(socket, true); } +AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket( + const SocketAddress& local_address, + const SocketAddress& remote_address, + const ProxyInfo& proxy_info, + const std::string& user_agent, + int opts) { + PacketSocketTcpOptions tcp_options; + tcp_options.opts = opts; + return CreateClientTcpSocket(local_address, remote_address, proxy_info, + user_agent, tcp_options); +} + AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket( const SocketAddress& local_address, const SocketAddress& remote_address, diff --git a/p2p/base/basicpacketsocketfactory.h b/p2p/base/basicpacketsocketfactory.h index b3ae2f05ed..08f525e90a 100644 --- a/p2p/base/basicpacketsocketfactory.h +++ b/p2p/base/basicpacketsocketfactory.h @@ -37,12 +37,7 @@ class BasicPacketSocketFactory : public PacketSocketFactory { const SocketAddress& remote_address, const ProxyInfo& proxy_info, const std::string& user_agent, - int opts) override { - PacketSocketTcpOptions tcp_options; - tcp_options.opts = opts; - return CreateClientTcpSocket(local_address, remote_address, proxy_info, - user_agent, tcp_options); - } + int opts) override; AsyncPacketSocket* CreateClientTcpSocket( const SocketAddress& local_address, const SocketAddress& remote_address, diff --git a/p2p/base/packetsocketfactory.h b/p2p/base/packetsocketfactory.h index 9e43e9aefe..df4a19d399 100644 --- a/p2p/base/packetsocketfactory.h +++ b/p2p/base/packetsocketfactory.h @@ -18,11 +18,17 @@ namespace rtc { // This structure contains options required to create TCP packet sockets. struct PacketSocketTcpOptions { + PacketSocketTcpOptions(); + ~PacketSocketTcpOptions(); + int opts; std::vector tls_alpn_protocols; std::vector tls_elliptic_curves; }; +inline PacketSocketTcpOptions::PacketSocketTcpOptions() = default; +inline PacketSocketTcpOptions::~PacketSocketTcpOptions() = default; + class AsyncPacketSocket; class AsyncResolverInterface; @@ -70,10 +76,7 @@ class PacketSocketFactory { const SocketAddress& remote_address, const ProxyInfo& proxy_info, const std::string& user_agent, - const PacketSocketTcpOptions& tcp_options) { - return CreateClientTcpSocket(local_address, remote_address, proxy_info, - user_agent, tcp_options.opts); - } + const PacketSocketTcpOptions& tcp_options); virtual AsyncResolverInterface* CreateAsyncResolver() = 0; @@ -81,6 +84,16 @@ class PacketSocketFactory { RTC_DISALLOW_COPY_AND_ASSIGN(PacketSocketFactory); }; +inline AsyncPacketSocket* PacketSocketFactory::CreateClientTcpSocket( + const SocketAddress& local_address, + const SocketAddress& remote_address, + const ProxyInfo& proxy_info, + const std::string& user_agent, + const PacketSocketTcpOptions& tcp_options) { + return CreateClientTcpSocket(local_address, remote_address, proxy_info, + user_agent, tcp_options.opts); +} + } // namespace rtc #endif // P2P_BASE_PACKETSOCKETFACTORY_H_ diff --git a/p2p/base/teststunserver.cc b/p2p/base/teststunserver.cc new file mode 100644 index 0000000000..13bc5773d9 --- /dev/null +++ b/p2p/base/teststunserver.cc @@ -0,0 +1,35 @@ +/* + * Copyright 2017 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "p2p/base/teststunserver.h" + +namespace cricket { + +TestStunServer* TestStunServer::Create(rtc::Thread* thread, + const rtc::SocketAddress& addr) { + rtc::AsyncSocket* socket = + thread->socketserver()->CreateAsyncSocket(addr.family(), SOCK_DGRAM); + rtc::AsyncUDPSocket* udp_socket = rtc::AsyncUDPSocket::Create(socket, addr); + + return new TestStunServer(udp_socket); +} + +void TestStunServer::OnBindingRequest(StunMessage* msg, + const rtc::SocketAddress& remote_addr) { + if (fake_stun_addr_.IsNil()) { + StunServer::OnBindingRequest(msg, remote_addr); + } else { + StunMessage response; + GetStunBindReqponse(msg, fake_stun_addr_, &response); + SendResponse(response, remote_addr); + } +} + +} // namespace cricket diff --git a/p2p/base/teststunserver.h b/p2p/base/teststunserver.h index 7b3f098614..4992640dcc 100644 --- a/p2p/base/teststunserver.h +++ b/p2p/base/teststunserver.h @@ -21,14 +21,7 @@ namespace cricket { class TestStunServer : StunServer { public: static TestStunServer* Create(rtc::Thread* thread, - const rtc::SocketAddress& addr) { - rtc::AsyncSocket* socket = - thread->socketserver()->CreateAsyncSocket(addr.family(), SOCK_DGRAM); - rtc::AsyncUDPSocket* udp_socket = - rtc::AsyncUDPSocket::Create(socket, addr); - - return new TestStunServer(udp_socket); - } + const rtc::SocketAddress& addr); // Set a fake STUN address to return to the client. void set_fake_stun_addr(const rtc::SocketAddress& addr) { @@ -39,15 +32,7 @@ class TestStunServer : StunServer { explicit TestStunServer(rtc::AsyncUDPSocket* socket) : StunServer(socket) {} void OnBindingRequest(StunMessage* msg, - const rtc::SocketAddress& remote_addr) override { - if (fake_stun_addr_.IsNil()) { - StunServer::OnBindingRequest(msg, remote_addr); - } else { - StunMessage response; - GetStunBindReqponse(msg, fake_stun_addr_, &response); - SendResponse(response, remote_addr); - } - } + const rtc::SocketAddress& remote_addr) override; private: rtc::SocketAddress fake_stun_addr_; diff --git a/p2p/stunprober/stunprober.cc b/p2p/stunprober/stunprober.cc index 47e0bbe13b..a302d47d8f 100644 --- a/p2p/stunprober/stunprober.cc +++ b/p2p/stunprober/stunprober.cc @@ -65,7 +65,7 @@ class StunProber::Requester : public sigslot::has_slots<> { Requester(StunProber* prober, rtc::AsyncPacketSocket* socket, const std::vector& server_ips); - virtual ~Requester(); + ~Requester() override; // There is no callback for SendStunRequest as the underneath socket send is // expected to be completed immediately. Otherwise, it'll skip this request @@ -124,7 +124,7 @@ StunProber::Requester::~Requester() { if (socket_) { socket_->Close(); } - for (auto req : requests_) { + for (auto* req : requests_) { if (req) { delete req; } @@ -220,7 +220,7 @@ void StunProber::Requester::OnStunResponseReceived( StunProber::Requester::Request* StunProber::Requester::GetRequestByAddress( const rtc::IPAddress& ipaddr) { RTC_DCHECK(thread_checker_.CalledOnValidThread()); - for (auto request : requests_) { + for (auto* request : requests_) { if (request->server_addr == ipaddr) { return request; } @@ -229,6 +229,28 @@ StunProber::Requester::Request* StunProber::Requester::GetRequestByAddress( return nullptr; } +StunProber::Stats::Stats() = default; + +StunProber::Stats::~Stats() = default; + +StunProber::ObserverAdapter::ObserverAdapter() = default; + +StunProber::ObserverAdapter::~ObserverAdapter() = default; + +void StunProber::ObserverAdapter::OnPrepared(StunProber* stunprober, + Status status) { + if (status == SUCCESS) { + stunprober->Start(this); + } else { + callback_(stunprober, status); + } +} + +void StunProber::ObserverAdapter::OnFinished(StunProber* stunprober, + Status status) { + callback_(stunprober, status); +} + StunProber::StunProber(rtc::PacketSocketFactory* socket_factory, rtc::Thread* thread, const rtc::NetworkManager::NetworkList& networks) @@ -239,12 +261,12 @@ StunProber::StunProber(rtc::PacketSocketFactory* socket_factory, } StunProber::~StunProber() { - for (auto req : requesters_) { + for (auto* req : requesters_) { if (req) { delete req; } } - for (auto s : sockets_) { + for (auto* s : sockets_) { if (s) { delete s; } @@ -475,7 +497,7 @@ bool StunProber::GetStats(StunProber::Stats* prob_stats) const { for (auto* requester : requesters_) { std::map num_response_per_srflx_addr; - for (auto request : requester->requests()) { + for (auto* request : requester->requests()) { if (request->sent_time_ms <= 0) { continue; } @@ -539,7 +561,7 @@ bool StunProber::GetStats(StunProber::Stats* prob_stats) const { !srflx_addr.FromString(*(stats.srflx_addrs.begin()))) { return false; } - for (const auto& net : networks_) { + for (const auto* net : networks_) { if (srflx_addr.ipaddr() == net->GetBestIP()) { nat_type = stunprober::NATTYPE_NONE; stats.host_ip = net->GetBestIP().ToString(); diff --git a/p2p/stunprober/stunprober.h b/p2p/stunprober/stunprober.h index 4cb0f4d9a7..718e202f01 100644 --- a/p2p/stunprober/stunprober.h +++ b/p2p/stunprober/stunprober.h @@ -69,7 +69,8 @@ class StunProber : public sigslot::has_slots<> { }; struct Stats { - Stats() {} + Stats(); + ~Stats(); // |raw_num_request_sent| is the total number of requests // sent. |num_request_sent| is the count of requests against a server where @@ -100,7 +101,7 @@ class StunProber : public sigslot::has_slots<> { StunProber(rtc::PacketSocketFactory* socket_factory, rtc::Thread* thread, const rtc::NetworkManager::NetworkList& networks); - virtual ~StunProber(); + ~StunProber() override; // Begin performing the probe test against the |servers|. If // |shared_socket_mode| is false, each request will be done with a new socket. @@ -153,17 +154,12 @@ class StunProber : public sigslot::has_slots<> { // AsyncCallback. class ObserverAdapter : public Observer { public: + ObserverAdapter(); + ~ObserverAdapter() override; + void set_callback(AsyncCallback callback) { callback_ = callback; } - void OnPrepared(StunProber* stunprober, Status status) { - if (status == SUCCESS) { - stunprober->Start(this); - } else { - callback_(stunprober, status); - } - } - void OnFinished(StunProber* stunprober, Status status) { - callback_(stunprober, status); - } + void OnPrepared(StunProber* stunprober, Status status) override; + void OnFinished(StunProber* stunprober, Status status) override; private: AsyncCallback callback_;