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); |
| 68 | |
Harald Alvestrand | 8d3d6cf | 2019-05-16 11:49:17 +0200 | [diff] [blame] | 69 | // Note - owner_thread never changes, but can't be const if we do |
| 70 | // Invoke() on it. |
| 71 | rtc::Thread* owner_thread_; |
Harald Alvestrand | c85328f | 2019-02-28 07:51:00 +0100 | [diff] [blame] | 72 | rtc::CriticalSection lock_; |
| 73 | // Variables accessible off-thread, guarded by lock_ |
| 74 | SctpTransportInformation info_ RTC_GUARDED_BY(lock_); |
| 75 | std::unique_ptr<cricket::SctpTransportInternal> internal_sctp_transport_ |
| 76 | RTC_GUARDED_BY(lock_); |
| 77 | // Variables only accessed on-thread |
| 78 | SctpTransportObserverInterface* observer_ RTC_GUARDED_BY(owner_thread_) = |
| 79 | nullptr; |
| 80 | rtc::scoped_refptr<DtlsTransport> dtls_transport_ |
| 81 | RTC_GUARDED_BY(owner_thread_); |
| 82 | }; |
| 83 | |
| 84 | } // namespace webrtc |
| 85 | #endif // PC_SCTP_TRANSPORT_H_ |