blob: cca4cc980a7fe4a461cb18180a76d128f3abd5e0 [file] [log] [blame]
Harald Alvestrandad88c882018-11-28 15:47:461/*
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 Anton10542f22019-01-11 17:11:0011#ifndef PC_DTLS_TRANSPORT_H_
12#define PC_DTLS_TRANSPORT_H_
Harald Alvestrandad88c882018-11-28 15:47:4613
14#include <memory>
15
Steve Anton10542f22019-01-11 17:11:0016#include "api/dtls_transport_interface.h"
Harald Alvestrand98462622019-01-30 13:57:0317#include "api/ice_transport_interface.h"
18#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 17:11:0019#include "p2p/base/dtls_transport.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0820#include "p2p/base/dtls_transport_internal.h"
21#include "pc/ice_transport.h"
Markus Handell6fcd0f82020-07-07 17:08:5322#include "rtc_base/synchronization/mutex.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0823#include "rtc_base/thread.h"
24#include "rtc_base/thread_annotations.h"
Harald Alvestrandad88c882018-11-28 15:47:4625
26namespace webrtc {
27
Harald Alvestrand98462622019-01-30 13:57:0328class IceTransportWithPointer;
29
Harald Alvestrandad88c882018-11-28 15:47:4630// This implementation wraps a cricket::DtlsTransport, and takes
31// ownership of it.
Mirko Bonadei6a55e732021-02-27 08:19:3232class DtlsTransport : public DtlsTransportInterface {
Harald Alvestrandad88c882018-11-28 15:47:4633 public:
Harald Alvestrand69fb6c82019-02-13 18:40:1134 // This object must be constructed and updated on a consistent thread,
35 // the same thread as the one the cricket::DtlsTransportInternal object
36 // lives on.
37 // The Information() function can be called from a different thread,
38 // such as the signalling thread.
Harald Alvestrandad88c882018-11-28 15:47:4639 explicit DtlsTransport(
40 std::unique_ptr<cricket::DtlsTransportInternal> internal);
Harald Alvestrandd02541e2019-01-03 11:43:2841
Harald Alvestrand98462622019-01-30 13:57:0342 rtc::scoped_refptr<IceTransportInterface> ice_transport() override;
Harald Alvestrandd02541e2019-01-03 11:43:2843 DtlsTransportInformation Information() override;
44 void RegisterObserver(DtlsTransportObserverInterface* observer) override;
45 void UnregisterObserver() override;
46 void Clear();
47
Harald Alvestrandad88c882018-11-28 15:47:4648 cricket::DtlsTransportInternal* internal() {
Markus Handell6fcd0f82020-07-07 17:08:5349 MutexLock lock(&lock_);
Harald Alvestrandad88c882018-11-28 15:47:4650 return internal_dtls_transport_.get();
51 }
Harald Alvestrandd02541e2019-01-03 11:43:2852
53 const cricket::DtlsTransportInternal* internal() const {
Markus Handell6fcd0f82020-07-07 17:08:5354 MutexLock lock(&lock_);
Harald Alvestrandd02541e2019-01-03 11:43:2855 return internal_dtls_transport_.get();
56 }
57
58 protected:
59 ~DtlsTransport();
Harald Alvestrandad88c882018-11-28 15:47:4660
61 private:
Harald Alvestrandd02541e2019-01-03 11:43:2862 void OnInternalDtlsState(cricket::DtlsTransportInternal* transport,
Mirko Bonadei9f6808b2021-05-21 18:46:0963 DtlsTransportState state);
Harald Alvestrand69fb6c82019-02-13 18:40:1164 void UpdateInformation();
Harald Alvestrandd02541e2019-01-03 11:43:2865
66 DtlsTransportObserverInterface* observer_ = nullptr;
Harald Alvestrand69fb6c82019-02-13 18:40:1167 rtc::Thread* owner_thread_;
Markus Handell6fcd0f82020-07-07 17:08:5368 mutable Mutex lock_;
Harald Alvestrand69fb6c82019-02-13 18:40:1169 DtlsTransportInformation info_ RTC_GUARDED_BY(lock_);
70 std::unique_ptr<cricket::DtlsTransportInternal> internal_dtls_transport_
71 RTC_GUARDED_BY(lock_);
Harald Alvestrand26451932019-02-21 10:27:1572 const rtc::scoped_refptr<IceTransportWithPointer> ice_transport_;
Harald Alvestrandad88c882018-11-28 15:47:4673};
74
75} // namespace webrtc
Steve Anton10542f22019-01-11 17:11:0076#endif // PC_DTLS_TRANSPORT_H_