1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2018 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef PC_DTLS_TRANSPORT_H_ 12*d9f75844SAndroid Build Coastguard Worker #define PC_DTLS_TRANSPORT_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <memory> 15*d9f75844SAndroid Build Coastguard Worker 16*d9f75844SAndroid Build Coastguard Worker #include "api/dtls_transport_interface.h" 17*d9f75844SAndroid Build Coastguard Worker #include "api/ice_transport_interface.h" 18*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h" 19*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/dtls_transport.h" 20*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/dtls_transport_internal.h" 21*d9f75844SAndroid Build Coastguard Worker #include "pc/ice_transport.h" 22*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/synchronization/mutex.h" 23*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread.h" 24*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread_annotations.h" 25*d9f75844SAndroid Build Coastguard Worker 26*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 27*d9f75844SAndroid Build Coastguard Worker 28*d9f75844SAndroid Build Coastguard Worker class IceTransportWithPointer; 29*d9f75844SAndroid Build Coastguard Worker 30*d9f75844SAndroid Build Coastguard Worker // This implementation wraps a cricket::DtlsTransport, and takes 31*d9f75844SAndroid Build Coastguard Worker // ownership of it. 32*d9f75844SAndroid Build Coastguard Worker class DtlsTransport : public DtlsTransportInterface { 33*d9f75844SAndroid Build Coastguard Worker public: 34*d9f75844SAndroid Build Coastguard Worker // This object must be constructed and updated on a consistent thread, 35*d9f75844SAndroid Build Coastguard Worker // the same thread as the one the cricket::DtlsTransportInternal object 36*d9f75844SAndroid Build Coastguard Worker // lives on. 37*d9f75844SAndroid Build Coastguard Worker // The Information() function can be called from a different thread, 38*d9f75844SAndroid Build Coastguard Worker // such as the signalling thread. 39*d9f75844SAndroid Build Coastguard Worker explicit DtlsTransport( 40*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<cricket::DtlsTransportInternal> internal); 41*d9f75844SAndroid Build Coastguard Worker 42*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<IceTransportInterface> ice_transport() override; 43*d9f75844SAndroid Build Coastguard Worker DtlsTransportInformation Information() override; 44*d9f75844SAndroid Build Coastguard Worker void RegisterObserver(DtlsTransportObserverInterface* observer) override; 45*d9f75844SAndroid Build Coastguard Worker void UnregisterObserver() override; 46*d9f75844SAndroid Build Coastguard Worker void Clear(); 47*d9f75844SAndroid Build Coastguard Worker internal()48*d9f75844SAndroid Build Coastguard Worker cricket::DtlsTransportInternal* internal() { 49*d9f75844SAndroid Build Coastguard Worker MutexLock lock(&lock_); 50*d9f75844SAndroid Build Coastguard Worker return internal_dtls_transport_.get(); 51*d9f75844SAndroid Build Coastguard Worker } 52*d9f75844SAndroid Build Coastguard Worker internal()53*d9f75844SAndroid Build Coastguard Worker const cricket::DtlsTransportInternal* internal() const { 54*d9f75844SAndroid Build Coastguard Worker MutexLock lock(&lock_); 55*d9f75844SAndroid Build Coastguard Worker return internal_dtls_transport_.get(); 56*d9f75844SAndroid Build Coastguard Worker } 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker protected: 59*d9f75844SAndroid Build Coastguard Worker ~DtlsTransport(); 60*d9f75844SAndroid Build Coastguard Worker 61*d9f75844SAndroid Build Coastguard Worker private: 62*d9f75844SAndroid Build Coastguard Worker void OnInternalDtlsState(cricket::DtlsTransportInternal* transport, 63*d9f75844SAndroid Build Coastguard Worker DtlsTransportState state); 64*d9f75844SAndroid Build Coastguard Worker void UpdateInformation(); 65*d9f75844SAndroid Build Coastguard Worker 66*d9f75844SAndroid Build Coastguard Worker DtlsTransportObserverInterface* observer_ = nullptr; 67*d9f75844SAndroid Build Coastguard Worker rtc::Thread* owner_thread_; 68*d9f75844SAndroid Build Coastguard Worker mutable Mutex lock_; 69*d9f75844SAndroid Build Coastguard Worker DtlsTransportInformation info_ RTC_GUARDED_BY(lock_); 70*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<cricket::DtlsTransportInternal> internal_dtls_transport_ 71*d9f75844SAndroid Build Coastguard Worker RTC_GUARDED_BY(lock_); 72*d9f75844SAndroid Build Coastguard Worker const rtc::scoped_refptr<IceTransportWithPointer> ice_transport_; 73*d9f75844SAndroid Build Coastguard Worker }; 74*d9f75844SAndroid Build Coastguard Worker 75*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 76*d9f75844SAndroid Build Coastguard Worker #endif // PC_DTLS_TRANSPORT_H_ 77