blob: a73d3deaff979aa936e017ff7feeb5a99b88e9a6 [file] [log] [blame]
Patrik Höglund662e31f2019-09-05 12:35:041/*
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
Dor Hen28ce65c2024-09-04 11:55:2214#include <cstdint>
Harald Alvestrand985310e2021-10-01 15:11:1715#include <memory>
Patrik Höglund662e31f2019-09-05 12:35:0416#include <string>
17#include <vector>
18
Harald Alvestrand985310e2021-10-01 15:11:1719#include "api/async_dns_resolver.h"
Patrik Höglund662e31f2019-09-05 12:35:0420#include "rtc_base/async_packet_socket.h"
Dor Hen28ce65c2024-09-04 11:55:2221#include "rtc_base/socket_address.h"
Patrik Höglund662e31f2019-09-05 12:35:0422#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 09:19:0362 virtual AsyncListenSocket* CreateServerTcpSocket(
Patrik Höglund662e31f2019-09-05 12:35:0463 const SocketAddress& local_address,
64 uint16_t min_port,
65 uint16_t max_port,
66 int opts) = 0;
67
Tommidb6767d2024-04-17 08:52:5368 virtual AsyncPacketSocket* CreateClientTcpSocket(
69 const SocketAddress& local_address,
70 const SocketAddress& remote_address,
Tommif54e0132024-04-17 12:06:1071 const PacketSocketTcpOptions& tcp_options) = 0;
Patrik Höglund662e31f2019-09-05 12:35:0472
Harald Alvestrand985310e2021-10-01 15:11:1773 virtual std::unique_ptr<webrtc::AsyncDnsResolverInterface>
Harald Alvestrand24510d42023-11-13 11:52:1674 CreateAsyncDnsResolver() = 0;
Patrik Höglund662e31f2019-09-05 12:35:0475
76 private:
77 PacketSocketFactory(const PacketSocketFactory&) = delete;
78 PacketSocketFactory& operator=(const PacketSocketFactory&) = delete;
79};
80
81} // namespace rtc
82
83#endif // API_PACKET_SOCKET_FACTORY_H_