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