blob: b5caae52129cb565ece95b9430c4fb3a186304dc [file] [log] [blame]
Harald Alvestrandad88c882018-11-28 16:47:46 +01001/*
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 09:11:00 -080011#ifndef PC_DTLS_TRANSPORT_H_
12#define PC_DTLS_TRANSPORT_H_
Harald Alvestrandad88c882018-11-28 16:47:46 +010013
14#include <memory>
15
Steve Anton10542f22019-01-11 09:11:00 -080016#include "api/dtls_transport_interface.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010017#include "api/ice_transport_interface.h"
18#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "p2p/base/dtls_transport.h"
Harald Alvestrandad88c882018-11-28 16:47:46 +010020
21namespace webrtc {
22
Harald Alvestrand98462622019-01-30 14:57:03 +010023class IceTransportWithPointer;
24
Harald Alvestrandad88c882018-11-28 16:47:46 +010025// This implementation wraps a cricket::DtlsTransport, and takes
26// ownership of it.
Harald Alvestrandd02541e2019-01-03 12:43:28 +010027class DtlsTransport : public DtlsTransportInterface,
28 public sigslot::has_slots<> {
Harald Alvestrandad88c882018-11-28 16:47:46 +010029 public:
Harald Alvestrand69fb6c82019-02-13 19:40:11 +010030 // 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 Alvestrandad88c882018-11-28 16:47:46 +010035 explicit DtlsTransport(
36 std::unique_ptr<cricket::DtlsTransportInternal> internal);
Harald Alvestrandd02541e2019-01-03 12:43:28 +010037
Harald Alvestrand98462622019-01-30 14:57:03 +010038 rtc::scoped_refptr<IceTransportInterface> ice_transport() override;
Harald Alvestrandd02541e2019-01-03 12:43:28 +010039 DtlsTransportInformation Information() override;
40 void RegisterObserver(DtlsTransportObserverInterface* observer) override;
41 void UnregisterObserver() override;
42 void Clear();
43
Harald Alvestrandad88c882018-11-28 16:47:46 +010044 cricket::DtlsTransportInternal* internal() {
Harald Alvestrand69fb6c82019-02-13 19:40:11 +010045 rtc::CritScope scope(&lock_);
Harald Alvestrandad88c882018-11-28 16:47:46 +010046 return internal_dtls_transport_.get();
47 }
Harald Alvestrandd02541e2019-01-03 12:43:28 +010048
49 const cricket::DtlsTransportInternal* internal() const {
Harald Alvestrand69fb6c82019-02-13 19:40:11 +010050 rtc::CritScope scope(&lock_);
Harald Alvestrandd02541e2019-01-03 12:43:28 +010051 return internal_dtls_transport_.get();
52 }
53
54 protected:
55 ~DtlsTransport();
Harald Alvestrandad88c882018-11-28 16:47:46 +010056
57 private:
Harald Alvestrandd02541e2019-01-03 12:43:28 +010058 void OnInternalDtlsState(cricket::DtlsTransportInternal* transport,
59 cricket::DtlsTransportState state);
Harald Alvestrand69fb6c82019-02-13 19:40:11 +010060 void UpdateInformation();
Harald Alvestrandd02541e2019-01-03 12:43:28 +010061
62 DtlsTransportObserverInterface* observer_ = nullptr;
Harald Alvestrand69fb6c82019-02-13 19:40:11 +010063 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 Alvestrand26451932019-02-21 11:27:15 +010068 const rtc::scoped_refptr<IceTransportWithPointer> ice_transport_;
Harald Alvestrandad88c882018-11-28 16:47:46 +010069};
70
71} // namespace webrtc
Steve Anton10542f22019-01-11 09:11:00 -080072#endif // PC_DTLS_TRANSPORT_H_