blob: c903df06c8a98dd45653cd4e03fa4f050c1be575 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef P2P_BASE_PACKETSOCKETFACTORY_H_
12#define P2P_BASE_PACKETSOCKETFACTORY_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
Steve Anton6c38cc72017-11-29 10:25:58 -080014#include <string>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/constructormagic.h"
18#include "rtc_base/proxyinfo.h"
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070019#include "rtc_base/sslcertificate.h"
Mirko Bonadei3b56ee72018-10-15 17:15:12 +020020#include "rtc_base/system/rtc_export.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000021
22namespace rtc {
23
Diogo Real1dca9d52017-08-29 12:18:32 -070024// This structure contains options required to create TCP packet sockets.
25struct PacketSocketTcpOptions {
Steve Antoneae3e652017-10-25 14:46:18 -070026 PacketSocketTcpOptions();
27 ~PacketSocketTcpOptions();
28
Steve Anton9d4a2e62017-10-26 11:23:08 -070029 int opts = 0;
Sergey Silkin9c147dd2018-09-12 10:45:38 +000030 std::vector<std::string> tls_alpn_protocols;
31 std::vector<std::string> tls_elliptic_curves;
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070032 // An optional custom SSL certificate verifier that an API user can provide to
33 // inject their own certificate verification logic.
34 SSLCertificateVerifier* tls_cert_verifier = nullptr;
Diogo Real1dca9d52017-08-29 12:18:32 -070035};
36
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000037class AsyncPacketSocket;
38class AsyncResolverInterface;
39
Mirko Bonadei3b56ee72018-10-15 17:15:12 +020040class RTC_EXPORT PacketSocketFactory {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000041 public:
42 enum Options {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043 OPT_STUN = 0x04,
hnsl04833622017-01-09 08:35:45 -080044
45 // The TLS options below are mutually exclusive.
46 OPT_TLS = 0x02, // Real and secure TLS.
47 OPT_TLS_FAKE = 0x01, // Fake TLS with a dummy SSL handshake.
48 OPT_TLS_INSECURE = 0x08, // Insecure TLS without certificate validation.
49
50 // Deprecated, use OPT_TLS_FAKE.
51 OPT_SSLTCP = OPT_TLS_FAKE,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000052 };
53
Yves Gerey665174f2018-06-19 15:03:05 +020054 PacketSocketFactory() {}
Steve Anton9d4a2e62017-10-26 11:23:08 -070055 virtual ~PacketSocketFactory() = default;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000056
pkasting@chromium.org332331f2014-11-06 20:19:22 +000057 virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
Peter Boström0c4e06b2015-10-07 12:23:21 +020058 uint16_t min_port,
59 uint16_t max_port) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000060 virtual AsyncPacketSocket* CreateServerTcpSocket(
pkasting@chromium.org332331f2014-11-06 20:19:22 +000061 const SocketAddress& local_address,
Peter Boström0c4e06b2015-10-07 12:23:21 +020062 uint16_t min_port,
63 uint16_t max_port,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000064 int opts) = 0;
65
Diogo Real1dca9d52017-08-29 12:18:32 -070066 // TODO(deadbeef): |proxy_info| and |user_agent| should be set
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000067 // per-factory and not when socket is created.
68 virtual AsyncPacketSocket* CreateClientTcpSocket(
pkasting@chromium.org332331f2014-11-06 20:19:22 +000069 const SocketAddress& local_address,
70 const SocketAddress& remote_address,
71 const ProxyInfo& proxy_info,
72 const std::string& user_agent,
73 int opts) = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000074
Diogo Real1dca9d52017-08-29 12:18:32 -070075 // TODO(deadbeef): |proxy_info|, |user_agent| and |tcp_options| should
76 // be set per-factory and not when socket is created.
77 // TODO(deadbeef): Implement this method in all subclasses (namely those in
78 // Chromium), make pure virtual, and remove the old CreateClientTcpSocket.
79 virtual AsyncPacketSocket* CreateClientTcpSocket(
80 const SocketAddress& local_address,
81 const SocketAddress& remote_address,
82 const ProxyInfo& proxy_info,
83 const std::string& user_agent,
Steve Antoneae3e652017-10-25 14:46:18 -070084 const PacketSocketTcpOptions& tcp_options);
Diogo Real1dca9d52017-08-29 12:18:32 -070085
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000086 virtual AsyncResolverInterface* CreateAsyncResolver() = 0;
87
88 private:
henrikg3c089d72015-09-16 05:37:44 -070089 RTC_DISALLOW_COPY_AND_ASSIGN(PacketSocketFactory);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000090};
91
92} // namespace rtc
93
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020094#endif // P2P_BASE_PACKETSOCKETFACTORY_H_