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 #include "rtc_base/synchronization/mutex.h" 21 22 namespace webrtc { 23 24 // This implementation wraps a cricket::SctpTransport, and takes 25 // ownership of it. 26 // This object must be constructed and updated on the networking thread, 27 // the same thread as the one the cricket::SctpTransportInternal object 28 // lives on. 29 class SctpTransport : public SctpTransportInterface, 30 public sigslot::has_slots<> { 31 public: 32 explicit SctpTransport( 33 std::unique_ptr<cricket::SctpTransportInternal> internal); 34 35 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override; 36 SctpTransportInformation Information() const override; 37 void RegisterObserver(SctpTransportObserverInterface* observer) override; 38 void UnregisterObserver() override; 39 40 // Internal functions 41 void Clear(); 42 void SetDtlsTransport(rtc::scoped_refptr<DtlsTransport>); 43 // Initialize the cricket::SctpTransport. This can be called from 44 // the signaling thread. 45 void Start(int local_port, int remote_port, int max_message_size); 46 47 // TODO(https://bugs.webrtc.org/10629): Move functions that need 48 // internal() to be functions on the webrtc::SctpTransport interface, 49 // and make the internal() function private. internal()50 cricket::SctpTransportInternal* internal() { 51 MutexLock lock(&lock_); 52 return internal_sctp_transport_.get(); 53 } 54 internal()55 const cricket::SctpTransportInternal* internal() const { 56 MutexLock lock(&lock_); 57 return internal_sctp_transport_.get(); 58 } 59 60 protected: 61 ~SctpTransport() override; 62 63 private: 64 void UpdateInformation(SctpTransportState state); 65 void OnInternalReadyToSendData(); 66 void OnAssociationChangeCommunicationUp(); 67 void OnInternalClosingProcedureStartedRemotely(int sid); 68 void OnInternalClosingProcedureComplete(int sid); 69 void OnDtlsStateChange(cricket::DtlsTransportInternal* transport, 70 cricket::DtlsTransportState state); 71 72 // Note - owner_thread never changes, but can't be const if we do 73 // Invoke() on it. 74 rtc::Thread* owner_thread_; 75 mutable Mutex lock_; 76 // Variables accessible off-thread, guarded by lock_ 77 SctpTransportInformation info_ RTC_GUARDED_BY(lock_); 78 std::unique_ptr<cricket::SctpTransportInternal> internal_sctp_transport_ 79 RTC_GUARDED_BY(lock_); 80 // Variables only accessed on-thread 81 SctpTransportObserverInterface* observer_ RTC_GUARDED_BY(owner_thread_) = 82 nullptr; 83 rtc::scoped_refptr<DtlsTransport> dtls_transport_ 84 RTC_GUARDED_BY(owner_thread_); 85 }; 86 87 } // namespace webrtc 88 #endif // PC_SCTP_TRANSPORT_H_ 89