You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2018 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_DTLS_TRANSPORT_INTERFACE_H_
  11. #define API_DTLS_TRANSPORT_INTERFACE_H_
  12. #include <memory>
  13. #include <utility>
  14. #include "absl/types/optional.h"
  15. #include "api/ice_transport_interface.h"
  16. #include "api/rtc_error.h"
  17. #include "api/scoped_refptr.h"
  18. #include "rtc_base/ref_count.h"
  19. #include "rtc_base/ssl_certificate.h"
  20. #include "rtc_base/system/rtc_export.h"
  21. namespace webrtc {
  22. // States of a DTLS transport, corresponding to the JS API specification.
  23. // http://w3c.github.io/webrtc-pc/#dom-rtcdtlstransportstate
  24. enum class DtlsTransportState {
  25. kNew, // Has not started negotiating yet.
  26. kConnecting, // In the process of negotiating a secure connection.
  27. kConnected, // Completed negotiation and verified fingerprints.
  28. kClosed, // Intentionally closed.
  29. kFailed, // Failure due to an error or failing to verify a remote
  30. // fingerprint.
  31. kNumValues
  32. };
  33. // This object gives snapshot information about the changeable state of a
  34. // DTLSTransport.
  35. class RTC_EXPORT DtlsTransportInformation {
  36. public:
  37. DtlsTransportInformation();
  38. explicit DtlsTransportInformation(DtlsTransportState state);
  39. DtlsTransportInformation(
  40. DtlsTransportState state,
  41. absl::optional<int> ssl_cipher_suite,
  42. std::unique_ptr<rtc::SSLCertChain> remote_ssl_certificates);
  43. // Copy and assign
  44. DtlsTransportInformation(const DtlsTransportInformation& c);
  45. DtlsTransportInformation& operator=(const DtlsTransportInformation& c);
  46. // Move
  47. DtlsTransportInformation(DtlsTransportInformation&& other) = default;
  48. DtlsTransportInformation& operator=(DtlsTransportInformation&& other) =
  49. default;
  50. DtlsTransportState state() const { return state_; }
  51. absl::optional<int> ssl_cipher_suite() const { return ssl_cipher_suite_; }
  52. // The accessor returns a temporary pointer, it does not release ownership.
  53. const rtc::SSLCertChain* remote_ssl_certificates() const {
  54. return remote_ssl_certificates_.get();
  55. }
  56. private:
  57. DtlsTransportState state_;
  58. absl::optional<int> ssl_cipher_suite_;
  59. std::unique_ptr<rtc::SSLCertChain> remote_ssl_certificates_;
  60. };
  61. class DtlsTransportObserverInterface {
  62. public:
  63. // This callback carries information about the state of the transport.
  64. // The argument is a pass-by-value snapshot of the state.
  65. virtual void OnStateChange(DtlsTransportInformation info) = 0;
  66. // This callback is called when an error occurs, causing the transport
  67. // to go to the kFailed state.
  68. virtual void OnError(RTCError error) = 0;
  69. protected:
  70. virtual ~DtlsTransportObserverInterface() = default;
  71. };
  72. // A DTLS transport, as represented to the outside world.
  73. // This object is created on the network thread, and can only be
  74. // accessed on that thread, except for functions explicitly marked otherwise.
  75. // References can be held by other threads, and destruction can therefore
  76. // be initiated by other threads.
  77. class DtlsTransportInterface : public rtc::RefCountInterface {
  78. public:
  79. // Returns a pointer to the ICE transport that is owned by the DTLS transport.
  80. virtual rtc::scoped_refptr<IceTransportInterface> ice_transport() = 0;
  81. // Returns information on the state of the DtlsTransport.
  82. // This function can be called from other threads.
  83. virtual DtlsTransportInformation Information() = 0;
  84. // Observer management.
  85. virtual void RegisterObserver(DtlsTransportObserverInterface* observer) = 0;
  86. virtual void UnregisterObserver() = 0;
  87. };
  88. } // namespace webrtc
  89. #endif // API_DTLS_TRANSPORT_INTERFACE_H_