dtls_transport.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 PC_DTLS_TRANSPORT_H_
  11. #define PC_DTLS_TRANSPORT_H_
  12. #include <memory>
  13. #include "api/dtls_transport_interface.h"
  14. #include "api/ice_transport_interface.h"
  15. #include "api/scoped_refptr.h"
  16. #include "p2p/base/dtls_transport.h"
  17. #include "rtc_base/synchronization/mutex.h"
  18. namespace webrtc {
  19. class IceTransportWithPointer;
  20. // This implementation wraps a cricket::DtlsTransport, and takes
  21. // ownership of it.
  22. class DtlsTransport : public DtlsTransportInterface,
  23. public sigslot::has_slots<> {
  24. public:
  25. // This object must be constructed and updated on a consistent thread,
  26. // the same thread as the one the cricket::DtlsTransportInternal object
  27. // lives on.
  28. // The Information() function can be called from a different thread,
  29. // such as the signalling thread.
  30. explicit DtlsTransport(
  31. std::unique_ptr<cricket::DtlsTransportInternal> internal);
  32. rtc::scoped_refptr<IceTransportInterface> ice_transport() override;
  33. DtlsTransportInformation Information() override;
  34. void RegisterObserver(DtlsTransportObserverInterface* observer) override;
  35. void UnregisterObserver() override;
  36. void Clear();
  37. cricket::DtlsTransportInternal* internal() {
  38. MutexLock lock(&lock_);
  39. return internal_dtls_transport_.get();
  40. }
  41. const cricket::DtlsTransportInternal* internal() const {
  42. MutexLock lock(&lock_);
  43. return internal_dtls_transport_.get();
  44. }
  45. protected:
  46. ~DtlsTransport();
  47. private:
  48. void OnInternalDtlsState(cricket::DtlsTransportInternal* transport,
  49. cricket::DtlsTransportState state);
  50. void UpdateInformation();
  51. DtlsTransportObserverInterface* observer_ = nullptr;
  52. rtc::Thread* owner_thread_;
  53. mutable Mutex lock_;
  54. DtlsTransportInformation info_ RTC_GUARDED_BY(lock_);
  55. std::unique_ptr<cricket::DtlsTransportInternal> internal_dtls_transport_
  56. RTC_GUARDED_BY(lock_);
  57. const rtc::scoped_refptr<IceTransportWithPointer> ice_transport_;
  58. };
  59. } // namespace webrtc
  60. #endif // PC_DTLS_TRANSPORT_H_