henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef P2P_BASE_PACKETSOCKETFACTORY_H_ |
| 12 | #define P2P_BASE_PACKETSOCKETFACTORY_H_ |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 13 | |
Steve Anton | 6c38cc7 | 2017-11-29 10:25:58 -0800 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/constructormagic.h" |
| 18 | #include "rtc_base/proxyinfo.h" |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 19 | #include "rtc_base/sslcertificate.h" |
Mirko Bonadei | 3b56ee7 | 2018-10-15 17:15:12 +0200 | [diff] [blame^] | 20 | #include "rtc_base/system/rtc_export.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 21 | |
| 22 | namespace rtc { |
| 23 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 24 | // This structure contains options required to create TCP packet sockets. |
| 25 | struct PacketSocketTcpOptions { |
Steve Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 26 | PacketSocketTcpOptions(); |
| 27 | ~PacketSocketTcpOptions(); |
| 28 | |
Steve Anton | 9d4a2e6 | 2017-10-26 11:23:08 -0700 | [diff] [blame] | 29 | int opts = 0; |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 30 | std::vector<std::string> tls_alpn_protocols; |
| 31 | std::vector<std::string> tls_elliptic_curves; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 32 | // 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 Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 37 | class AsyncPacketSocket; |
| 38 | class AsyncResolverInterface; |
| 39 | |
Mirko Bonadei | 3b56ee7 | 2018-10-15 17:15:12 +0200 | [diff] [blame^] | 40 | class RTC_EXPORT PacketSocketFactory { |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 41 | public: |
| 42 | enum Options { |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 43 | OPT_STUN = 0x04, |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 44 | |
| 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.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 54 | PacketSocketFactory() {} |
Steve Anton | 9d4a2e6 | 2017-10-26 11:23:08 -0700 | [diff] [blame] | 55 | virtual ~PacketSocketFactory() = default; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 56 | |
pkasting@chromium.org | 332331f | 2014-11-06 20:19:22 +0000 | [diff] [blame] | 57 | virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 58 | uint16_t min_port, |
| 59 | uint16_t max_port) = 0; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 60 | virtual AsyncPacketSocket* CreateServerTcpSocket( |
pkasting@chromium.org | 332331f | 2014-11-06 20:19:22 +0000 | [diff] [blame] | 61 | const SocketAddress& local_address, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 62 | uint16_t min_port, |
| 63 | uint16_t max_port, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 64 | int opts) = 0; |
| 65 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 66 | // TODO(deadbeef): |proxy_info| and |user_agent| should be set |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 67 | // per-factory and not when socket is created. |
| 68 | virtual AsyncPacketSocket* CreateClientTcpSocket( |
pkasting@chromium.org | 332331f | 2014-11-06 20:19:22 +0000 | [diff] [blame] | 69 | 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.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 74 | |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 75 | // 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 Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 84 | const PacketSocketTcpOptions& tcp_options); |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 85 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 86 | virtual AsyncResolverInterface* CreateAsyncResolver() = 0; |
| 87 | |
| 88 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 89 | RTC_DISALLOW_COPY_AND_ASSIGN(PacketSocketFactory); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } // namespace rtc |
| 93 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 94 | #endif // P2P_BASE_PACKETSOCKETFACTORY_H_ |