dtls_transport.h 2.3 KB

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