Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 1 | /* |
| 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 Hen | 28ce65c | 2024-09-04 11:55:22 | [diff] [blame] | 14 | #include <cstdint> |
Harald Alvestrand | 985310e | 2021-10-01 15:11:17 | [diff] [blame] | 15 | #include <memory> |
Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Harald Alvestrand | 985310e | 2021-10-01 15:11:17 | [diff] [blame] | 19 | #include "api/async_dns_resolver.h" |
Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 20 | #include "rtc_base/async_packet_socket.h" |
Dor Hen | 28ce65c | 2024-09-04 11:55:22 | [diff] [blame] | 21 | #include "rtc_base/socket_address.h" |
Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 22 | #include "rtc_base/system/rtc_export.h" |
| 23 | |
| 24 | namespace rtc { |
| 25 | |
| 26 | class SSLCertificateVerifier; |
| 27 | class AsyncResolverInterface; |
| 28 | |
| 29 | struct 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 | |
| 42 | class 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öller | 6d19d14 | 2021-10-06 09:19:03 | [diff] [blame] | 62 | virtual AsyncListenSocket* CreateServerTcpSocket( |
Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 63 | const SocketAddress& local_address, |
| 64 | uint16_t min_port, |
| 65 | uint16_t max_port, |
| 66 | int opts) = 0; |
| 67 | |
Tommi | db6767d | 2024-04-17 08:52:53 | [diff] [blame] | 68 | virtual AsyncPacketSocket* CreateClientTcpSocket( |
| 69 | const SocketAddress& local_address, |
| 70 | const SocketAddress& remote_address, |
Tommi | f54e013 | 2024-04-17 12:06:10 | [diff] [blame] | 71 | const PacketSocketTcpOptions& tcp_options) = 0; |
Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 72 | |
Harald Alvestrand | 985310e | 2021-10-01 15:11:17 | [diff] [blame] | 73 | virtual std::unique_ptr<webrtc::AsyncDnsResolverInterface> |
Harald Alvestrand | 24510d4 | 2023-11-13 11:52:16 | [diff] [blame] | 74 | CreateAsyncDnsResolver() = 0; |
Patrik Höglund | 662e31f | 2019-09-05 12:35:04 | [diff] [blame] | 75 | |
| 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_ |