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