| 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 |
| 11 | #ifndef PC_DTLS_TRANSPORT_H_ |
| 12 | #define PC_DTLS_TRANSPORT_H_ |
| 13 |
| 14 | #include <memory> |
| 15 | #include <utility> |
| 16 |
| 17 | #include "api/dtls_transport_interface.h" |
| 18 | #include "api/ice_transport_interface.h" |
| 19 | #include "api/scoped_refptr.h" |
| 20 | #include "p2p/base/dtls_transport.h" |
| 21 | #include "p2p/base/dtls_transport_internal.h" |
| 22 | #include "pc/ice_transport.h" |
| 23 | #include "rtc_base/synchronization/mutex.h" |
| 24 | #include "rtc_base/thread.h" |
| 25 | #include "rtc_base/thread_annotations.h" |
| 26 |
| 27 | namespace webrtc { |
| 28 |
| 29 | class IceTransportWithPointer; |
| 30 |
| 31 | // This implementation wraps a cricket::DtlsTransport, and takes |
| 32 | // ownership of it. |
| 33 | class DtlsTransport : public DtlsTransportInterface { |
| 34 | public: |
| 35 | // This object must be constructed and updated on a consistent thread, |
| 36 | // the same thread as the one the cricket::DtlsTransportInternal object |
| 37 | // lives on. |
| 38 | // The Information() function can be called from a different thread, |
| 39 | // such as the signalling thread. |
| 40 | explicit DtlsTransport( |
| 41 | std::unique_ptr<cricket::DtlsTransportInternal> internal); |
| 42 |
| 43 | rtc::scoped_refptr<IceTransportInterface> ice_transport() override; |
| 44 |
| 45 | // Currently called from the signaling thread and potentially Chromium's |
| 46 | // JS thread. |
| 47 | DtlsTransportInformation Information() override; |
| 48 |
| 49 | void RegisterObserver(DtlsTransportObserverInterface* observer) override; |
| 50 | void UnregisterObserver() override; |
| 51 | void Clear(); |
| 52 |
| 53 | cricket::DtlsTransportInternal* internal() { |
| 54 | RTC_DCHECK_RUN_ON(owner_thread_); |
| 55 | return internal_dtls_transport_.get(); |
| 56 | } |
| 57 |
| 58 | const cricket::DtlsTransportInternal* internal() const { |
| 59 | RTC_DCHECK_RUN_ON(owner_thread_); |
| 60 | return internal_dtls_transport_.get(); |
| 61 | } |
| 62 |
| 63 | protected: |
| 64 | ~DtlsTransport(); |
| 65 |
| 66 | private: |
| 67 | void OnInternalDtlsState(cricket::DtlsTransportInternal* transport, |
| 68 | DtlsTransportState state); |
| 69 | void UpdateInformation(); |
| 70 |
| 71 | // Called when changing `info_`. We only change the values from the |
| 72 | // `owner_thread_` (a.k.a. the network thread). |
| 73 | void set_info(DtlsTransportInformation&& info) RTC_RUN_ON(owner_thread_) { |
| 74 | MutexLock lock(&lock_); |
| 75 | info_ = std::move(info); |
| 76 | } |
| 77 |
| 78 | DtlsTransportObserverInterface* observer_ = nullptr; |
| 79 | rtc::Thread* owner_thread_; |
| 80 | mutable Mutex lock_; |
| 81 | DtlsTransportInformation info_ RTC_GUARDED_BY(lock_); |
| 82 | std::unique_ptr<cricket::DtlsTransportInternal> internal_dtls_transport_ |
| 83 | RTC_GUARDED_BY(owner_thread_); |
| 84 | const rtc::scoped_refptr<IceTransportWithPointer> ice_transport_; |
| 85 | }; |
| 86 |
| 87 | } // namespace webrtc |
| 88 | #endif // PC_DTLS_TRANSPORT_H_ |
| 89 |