From a42b63267c831ec1948d15577ba5006fff789478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20H=C3=B6glund?= Date: Fri, 30 Aug 2019 15:31:55 +0200 Subject: [PATCH] Adding CreateTcpClientSocket without user_agent and proxy_info. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is part of a larger refactoring: 1) Add new method and provide default implementations for the other Create* methods (this CL) so they can be removed downstream. 2) Implement new method in Chromium and remove the overrides of the other Create* methods from subclasses of PacketSocketFactory. 3) Remove other Create* methods from PacketSocketFactory and make the new Create method pure virtual. Make BasicPacketSocketFactory take user_agent and proxy_info in the constructor. 4) Move the slimmed-down packet_socket_factory into api/. Bug: webrtc:7447 Change-Id: I961fcc4451c9fb2bc7a049b8f57d5894209fd262 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150941 Reviewed-by: Niels Moller Commit-Queue: Patrik Höglund Cr-Commit-Position: refs/heads/master@{#29026} --- p2p/base/basic_packet_socket_factory.cc | 31 ++++++++++++++--------- p2p/base/basic_packet_socket_factory.h | 3 +++ p2p/base/packet_socket_factory.cc | 19 ++++++++++++++ p2p/base/packet_socket_factory.h | 33 ++++++++++++++----------- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/p2p/base/basic_packet_socket_factory.cc b/p2p/base/basic_packet_socket_factory.cc index 1e3f585313..3204092412 100644 --- a/p2p/base/basic_packet_socket_factory.cc +++ b/p2p/base/basic_packet_socket_factory.cc @@ -97,18 +97,6 @@ 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, @@ -200,6 +188,25 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket( return tcp_socket; } +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) { + return CreateClientTcpSocket(local_address, remote_address, ProxyInfo(), "", + PacketSocketTcpOptions()); +} + AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() { return new AsyncResolver(); } diff --git a/p2p/base/basic_packet_socket_factory.h b/p2p/base/basic_packet_socket_factory.h index 266c638bb5..ba6c59ddb5 100644 --- a/p2p/base/basic_packet_socket_factory.h +++ b/p2p/base/basic_packet_socket_factory.h @@ -35,6 +35,9 @@ class BasicPacketSocketFactory : public PacketSocketFactory { uint16_t min_port, uint16_t max_port, int opts) override; + AsyncPacketSocket* CreateClientTcpSocket( + const SocketAddress& local_address, + const SocketAddress& remote_address) override; AsyncPacketSocket* CreateClientTcpSocket(const SocketAddress& local_address, const SocketAddress& remote_address, const ProxyInfo& proxy_info, diff --git a/p2p/base/packet_socket_factory.cc b/p2p/base/packet_socket_factory.cc index c11869d70f..403dc26e99 100644 --- a/p2p/base/packet_socket_factory.cc +++ b/p2p/base/packet_socket_factory.cc @@ -12,6 +12,8 @@ #include +#include "rtc_base/checks.h" + namespace rtc { PacketSocketTcpOptions::PacketSocketTcpOptions() = default; @@ -28,4 +30,21 @@ AsyncPacketSocket* PacketSocketFactory::CreateClientTcpSocket( user_agent, tcp_options.opts); } +AsyncPacketSocket* PacketSocketFactory::CreateClientTcpSocket( + const SocketAddress& local_address, + const SocketAddress& remote_address, + const ProxyInfo& proxy_info, + const std::string& user_agent, + int opts) { + RTC_NOTREACHED(); + return nullptr; +} + +AsyncPacketSocket* PacketSocketFactory::CreateClientTcpSocket( + const SocketAddress& local_address, + const SocketAddress& remote_address) { + RTC_NOTREACHED(); + return nullptr; +} + } // namespace rtc diff --git a/p2p/base/packet_socket_factory.h b/p2p/base/packet_socket_factory.h index a430d2ee3c..5c90d6da47 100644 --- a/p2p/base/packet_socket_factory.h +++ b/p2p/base/packet_socket_factory.h @@ -14,14 +14,16 @@ #include #include -#include "rtc_base/constructor_magic.h" #include "rtc_base/proxy_info.h" -#include "rtc_base/ssl_certificate.h" #include "rtc_base/system/rtc_export.h" namespace rtc { -// This structure contains options required to create TCP packet sockets. +class SSLCertificateVerifier; +class AsyncPacketSocket; +class AsyncResolverInterface; + +// TODO(bugs.webrtc.org/7447): move this to basic_packet_socket_factory. struct PacketSocketTcpOptions { PacketSocketTcpOptions(); ~PacketSocketTcpOptions(); @@ -30,13 +32,11 @@ struct PacketSocketTcpOptions { std::vector tls_alpn_protocols; std::vector tls_elliptic_curves; // An optional custom SSL certificate verifier that an API user can provide to - // inject their own certificate verification logic. + // inject their own certificate verification logic (not available to users + // outside of the WebRTC repo). SSLCertificateVerifier* tls_cert_verifier = nullptr; }; -class AsyncPacketSocket; -class AsyncResolverInterface; - class RTC_EXPORT PacketSocketFactory { public: enum Options { @@ -63,19 +63,21 @@ class RTC_EXPORT PacketSocketFactory { uint16_t max_port, int opts) = 0; - // TODO(deadbeef): |proxy_info| and |user_agent| should be set - // per-factory and not when socket is created. + // TODO(bugs.webrtc.org/7447): This should be the only CreateClientTcpSocket + // implementation left; the two other are deprecated. + virtual AsyncPacketSocket* CreateClientTcpSocket( + const SocketAddress& local_address, + const SocketAddress& remote_address); + + // TODO(bugs.webrtc.org/7447): Deprecated, about to be removed. virtual AsyncPacketSocket* CreateClientTcpSocket( const SocketAddress& local_address, const SocketAddress& remote_address, const ProxyInfo& proxy_info, const std::string& user_agent, - int opts) = 0; + int opts); - // TODO(deadbeef): |proxy_info|, |user_agent| and |tcp_options| should - // be set per-factory and not when socket is created. - // TODO(deadbeef): Implement this method in all subclasses (namely those in - // Chromium), make pure virtual, and remove the old CreateClientTcpSocket. + // TODO(bugs.webrtc.org/7447): Deprecated, about to be removed. virtual AsyncPacketSocket* CreateClientTcpSocket( const SocketAddress& local_address, const SocketAddress& remote_address, @@ -86,7 +88,8 @@ class RTC_EXPORT PacketSocketFactory { virtual AsyncResolverInterface* CreateAsyncResolver() = 0; private: - RTC_DISALLOW_COPY_AND_ASSIGN(PacketSocketFactory); + PacketSocketFactory(const PacketSocketFactory&) = delete; + PacketSocketFactory& operator=(const PacketSocketFactory&) = delete; }; } // namespace rtc