Adding CreateTcpClientSocket without user_agent and proxy_info.

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 <nisse@webrtc.org>
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29026}
This commit is contained in:
Patrik Höglund 2019-08-30 15:31:55 +02:00 committed by Commit Bot
parent 8b14b0dea6
commit a42b63267c
4 changed files with 59 additions and 27 deletions

View File

@ -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();
}

View File

@ -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,

View File

@ -12,6 +12,8 @@
#include <string>
#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

View File

@ -14,14 +14,16 @@
#include <string>
#include <vector>
#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<std::string> tls_alpn_protocols;
std::vector<std::string> 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