Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | namespace 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. |
| 28 | class 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 Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 39 | // Internal functions |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 40 | void Clear(); |
| 41 | void SetDtlsTransport(rtc::scoped_refptr<DtlsTransport>); |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 42 | // 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 Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 45 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 46 | // 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 Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 49 | 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 Alvestrand | 97716c0 | 2019-05-21 10:52:59 +0200 | [diff] [blame] | 65 | void OnAssociationChangeCommunicationUp(); |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 66 | void OnInternalClosingProcedureStartedRemotely(int sid); |
| 67 | void OnInternalClosingProcedureComplete(int sid); |
Harald Alvestrand | 408cb4b | 2019-11-16 12:09:08 +0100 | [diff] [blame] | 68 | void OnDtlsStateChange(cricket::DtlsTransportInternal* transport, |
| 69 | cricket::DtlsTransportState state); |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 70 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 71 | // Note - owner_thread never changes, but can't be const if we do |
| 72 | // Invoke() on it. |
| 73 | rtc::Thread* owner_thread_; |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 74 | 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_ |