blob: 29d2606b9b69bd054b8657ca6c83172918e82797 [file] [log] [blame]
Patrik Höglund662e31f2019-09-05 14:35:04 +02001/*
2 * Copyright 2019 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
11#ifndef API_PACKET_SOCKET_FACTORY_H_
12#define API_PACKET_SOCKET_FACTORY_H_
13
Harald Alvestrand985310e2021-10-01 15:11:17 +000014#include <memory>
Patrik Höglund662e31f2019-09-05 14:35:04 +020015#include <string>
16#include <vector>
17
Harald Alvestrand985310e2021-10-01 15:11:17 +000018#include "api/async_dns_resolver.h"
19#include "api/wrapping_async_dns_resolver.h"
Patrik Höglund662e31f2019-09-05 14:35:04 +020020#include "rtc_base/async_packet_socket.h"
21#include "rtc_base/proxy_info.h"
22#include "rtc_base/system/rtc_export.h"
23
24namespace rtc {
25
26class SSLCertificateVerifier;
27class AsyncResolverInterface;
28
29struct PacketSocketTcpOptions {
30 PacketSocketTcpOptions() = default;
31 ~PacketSocketTcpOptions() = default;
32
33 int opts = 0;
34 std::vector<std::string> tls_alpn_protocols;
35 std::vector<std::string> tls_elliptic_curves;
36 // An optional custom SSL certificate verifier that an API user can provide to
37 // inject their own certificate verification logic (not available to users
38 // outside of the WebRTC repo).
39 SSLCertificateVerifier* tls_cert_verifier = nullptr;
40};
41
42class RTC_EXPORT PacketSocketFactory {
43 public:
44 enum Options {
45 OPT_STUN = 0x04,
46
47 // The TLS options below are mutually exclusive.
48 OPT_TLS = 0x02, // Real and secure TLS.
49 OPT_TLS_FAKE = 0x01, // Fake TLS with a dummy SSL handshake.
50 OPT_TLS_INSECURE = 0x08, // Insecure TLS without certificate validation.
51
52 // Deprecated, use OPT_TLS_FAKE.
53 OPT_SSLTCP = OPT_TLS_FAKE,
54 };
55
56 PacketSocketFactory() = default;
57 virtual ~PacketSocketFactory() = default;
58
59 virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
60 uint16_t min_port,
61 uint16_t max_port) = 0;
Niels Möller6d19d142021-10-06 11:19:03 +020062 virtual AsyncListenSocket* CreateServerTcpSocket(
Patrik Höglund662e31f2019-09-05 14:35:04 +020063 const SocketAddress& local_address,
64 uint16_t min_port,
65 uint16_t max_port,
66 int opts) = 0;
67
68 virtual AsyncPacketSocket* CreateClientTcpSocket(
69 const SocketAddress& local_address,
70 const SocketAddress& remote_address,
71 const ProxyInfo& proxy_info,
72 const std::string& user_agent,
73 const PacketSocketTcpOptions& tcp_options) = 0;
74
Harald Alvestrand985310e2021-10-01 15:11:17 +000075 // The AsyncResolverInterface is deprecated; users are encouraged
76 // to switch to the AsyncDnsResolverInterface.
77 // TODO(bugs.webrtc.org/12598): Remove once all downstream users
78 // are converted.
79 virtual AsyncResolverInterface* CreateAsyncResolver() {
80 // Default implementation, so that downstream users can remove this
81 // immediately after changing to CreateAsyncDnsResolver
Artem Titovd3251962021-11-15 16:57:07 +010082 RTC_DCHECK_NOTREACHED();
Harald Alvestrand985310e2021-10-01 15:11:17 +000083 return nullptr;
84 }
85
86 virtual std::unique_ptr<webrtc::AsyncDnsResolverInterface>
87 CreateAsyncDnsResolver() {
88 // Default implementation, to aid in transition to AsyncDnsResolverInterface
89 return std::make_unique<webrtc::WrappingAsyncDnsResolver>(
90 CreateAsyncResolver());
91 }
Patrik Höglund662e31f2019-09-05 14:35:04 +020092
93 private:
94 PacketSocketFactory(const PacketSocketFactory&) = delete;
95 PacketSocketFactory& operator=(const PacketSocketFactory&) = delete;
96};
97
98} // namespace rtc
99
100#endif // API_PACKET_SOCKET_FACTORY_H_