blob: a13a58c68e6619d6d5469c893bdb9a8135f9ddbb [file] [log] [blame]
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001/*
2 * Copyright 2019 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_SCTP_TRANSPORT_H_
12#define PC_SCTP_TRANSPORT_H_
13
14#include <memory>
15
16#include "api/scoped_refptr.h"
17#include "api/sctp_transport_interface.h"
18#include "media/sctp/sctp_transport.h"
19#include "pc/dtls_transport.h"
20
21namespace webrtc {
22
23// This implementation wraps a cricket::SctpTransport, and takes
24// ownership of it.
25// This object must be constructed and updated on the networking thread,
26// the same thread as the one the cricket::SctpTransportInternal object
27// lives on.
28class SctpTransport : public SctpTransportInterface,
29 public sigslot::has_slots<> {
30 public:
31 explicit SctpTransport(
32 std::unique_ptr<cricket::SctpTransportInternal> internal);
33
34 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override;
35 SctpTransportInformation Information() const override;
36 void RegisterObserver(SctpTransportObserverInterface* observer) override;
37 void UnregisterObserver() override;
38
Harald Alvestrand8d3d6cf2019-05-16 11:49:17 +020039 // Internal functions
Harald Alvestrandc85328f2019-02-28 07:51:00 +010040 void Clear();
41 void SetDtlsTransport(rtc::scoped_refptr<DtlsTransport>);
Harald Alvestrand8d3d6cf2019-05-16 11:49:17 +020042 // Initialize the cricket::SctpTransport. This can be called from
43 // the signaling thread.
44 void Start(int local_port, int remote_port, int max_message_size);
Harald Alvestrandc85328f2019-02-28 07:51:00 +010045
Harald Alvestrand8d3d6cf2019-05-16 11:49:17 +020046 // TODO(https://bugs.webrtc.org/10629): Move functions that need
47 // internal() to be functions on the webrtc::SctpTransport interface,
48 // and make the internal() function private.
Harald Alvestrandc85328f2019-02-28 07:51:00 +010049 cricket::SctpTransportInternal* internal() {
50 rtc::CritScope scope(&lock_);
51 return internal_sctp_transport_.get();
52 }
53
54 const cricket::SctpTransportInternal* internal() const {
55 rtc::CritScope scope(&lock_);
56 return internal_sctp_transport_.get();
57 }
58
59 protected:
60 ~SctpTransport() override;
61
62 private:
63 void UpdateInformation(SctpTransportState state);
64 void OnInternalReadyToSendData();
Harald Alvestrand97716c02019-05-21 10:52:59 +020065 void OnAssociationChangeCommunicationUp();
Harald Alvestrandc85328f2019-02-28 07:51:00 +010066 void OnInternalClosingProcedureStartedRemotely(int sid);
67 void OnInternalClosingProcedureComplete(int sid);
Harald Alvestrand408cb4b2019-11-16 12:09:08 +010068 void OnDtlsStateChange(cricket::DtlsTransportInternal* transport,
69 cricket::DtlsTransportState state);
Harald Alvestrandc85328f2019-02-28 07:51:00 +010070
Harald Alvestrand8d3d6cf2019-05-16 11:49:17 +020071 // Note - owner_thread never changes, but can't be const if we do
72 // Invoke() on it.
73 rtc::Thread* owner_thread_;
Harald Alvestrandc85328f2019-02-28 07:51:00 +010074 rtc::CriticalSection lock_;
75 // Variables accessible off-thread, guarded by lock_
76 SctpTransportInformation info_ RTC_GUARDED_BY(lock_);
77 std::unique_ptr<cricket::SctpTransportInternal> internal_sctp_transport_
78 RTC_GUARDED_BY(lock_);
79 // Variables only accessed on-thread
80 SctpTransportObserverInterface* observer_ RTC_GUARDED_BY(owner_thread_) =
81 nullptr;
82 rtc::scoped_refptr<DtlsTransport> dtls_transport_
83 RTC_GUARDED_BY(owner_thread_);
84};
85
86} // namespace webrtc
87#endif // PC_SCTP_TRANSPORT_H_