packet_socket_factory.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef API_PACKET_SOCKET_FACTORY_H_
  11. #define API_PACKET_SOCKET_FACTORY_H_
  12. #include <string>
  13. #include <vector>
  14. #include "rtc_base/async_packet_socket.h"
  15. #include "rtc_base/proxy_info.h"
  16. #include "rtc_base/system/rtc_export.h"
  17. namespace rtc {
  18. class SSLCertificateVerifier;
  19. class AsyncResolverInterface;
  20. struct PacketSocketTcpOptions {
  21. PacketSocketTcpOptions() = default;
  22. ~PacketSocketTcpOptions() = default;
  23. int opts = 0;
  24. std::vector<std::string> tls_alpn_protocols;
  25. std::vector<std::string> tls_elliptic_curves;
  26. // An optional custom SSL certificate verifier that an API user can provide to
  27. // inject their own certificate verification logic (not available to users
  28. // outside of the WebRTC repo).
  29. SSLCertificateVerifier* tls_cert_verifier = nullptr;
  30. };
  31. class RTC_EXPORT PacketSocketFactory {
  32. public:
  33. enum Options {
  34. OPT_STUN = 0x04,
  35. // The TLS options below are mutually exclusive.
  36. OPT_TLS = 0x02, // Real and secure TLS.
  37. OPT_TLS_FAKE = 0x01, // Fake TLS with a dummy SSL handshake.
  38. OPT_TLS_INSECURE = 0x08, // Insecure TLS without certificate validation.
  39. // Deprecated, use OPT_TLS_FAKE.
  40. OPT_SSLTCP = OPT_TLS_FAKE,
  41. };
  42. PacketSocketFactory() = default;
  43. virtual ~PacketSocketFactory() = default;
  44. virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
  45. uint16_t min_port,
  46. uint16_t max_port) = 0;
  47. virtual AsyncPacketSocket* CreateServerTcpSocket(
  48. const SocketAddress& local_address,
  49. uint16_t min_port,
  50. uint16_t max_port,
  51. int opts) = 0;
  52. virtual AsyncPacketSocket* CreateClientTcpSocket(
  53. const SocketAddress& local_address,
  54. const SocketAddress& remote_address,
  55. const ProxyInfo& proxy_info,
  56. const std::string& user_agent,
  57. const PacketSocketTcpOptions& tcp_options) = 0;
  58. virtual AsyncResolverInterface* CreateAsyncResolver() = 0;
  59. private:
  60. PacketSocketFactory(const PacketSocketFactory&) = delete;
  61. PacketSocketFactory& operator=(const PacketSocketFactory&) = delete;
  62. };
  63. } // namespace rtc
  64. #endif // API_PACKET_SOCKET_FACTORY_H_