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/dtls_transport_interface.h" 17 #include "api/scoped_refptr.h" 18 #include "api/sctp_transport_interface.h" 19 #include "media/sctp/sctp_transport.h" 20 #include "media/sctp/sctp_transport_internal.h" 21 #include "p2p/base/dtls_transport_internal.h" 22 #include "pc/dtls_transport.h" 23 #include "rtc_base/third_party/sigslot/sigslot.h" 24 #include "rtc_base/thread.h" 25 #include "rtc_base/thread_annotations.h" 26 27 namespace webrtc { 28 29 // This implementation wraps a cricket::SctpTransport, and takes 30 // ownership of it. 31 // This object must be constructed and updated on the networking thread, 32 // the same thread as the one the cricket::SctpTransportInternal object 33 // lives on. 34 class SctpTransport : public SctpTransportInterface, 35 public sigslot::has_slots<> { 36 public: 37 explicit SctpTransport( 38 std::unique_ptr<cricket::SctpTransportInternal> internal); 39 40 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override; 41 SctpTransportInformation Information() const override; 42 void RegisterObserver(SctpTransportObserverInterface* observer) override; 43 void UnregisterObserver() override; 44 45 // Internal functions 46 void Clear(); 47 void SetDtlsTransport(rtc::scoped_refptr<DtlsTransport>); 48 // Initialize the cricket::SctpTransport. This can be called from 49 // the signaling thread. 50 void Start(int local_port, int remote_port, int max_message_size); 51 52 // TODO(https://bugs.webrtc.org/10629): Move functions that need 53 // internal() to be functions on the webrtc::SctpTransport interface, 54 // and make the internal() function private. internal()55 cricket::SctpTransportInternal* internal() { 56 RTC_DCHECK_RUN_ON(owner_thread_); 57 return internal_sctp_transport_.get(); 58 } 59 internal()60 const cricket::SctpTransportInternal* internal() const { 61 RTC_DCHECK_RUN_ON(owner_thread_); 62 return internal_sctp_transport_.get(); 63 } 64 65 protected: 66 ~SctpTransport() override; 67 68 private: 69 void UpdateInformation(SctpTransportState state); 70 void OnInternalReadyToSendData(); 71 void OnAssociationChangeCommunicationUp(); 72 void OnInternalClosingProcedureStartedRemotely(int sid); 73 void OnInternalClosingProcedureComplete(int sid); 74 void OnDtlsStateChange(cricket::DtlsTransportInternal* transport, 75 cricket::DtlsTransportState state); 76 77 // NOTE: |owner_thread_| is the thread that the SctpTransport object is 78 // constructed on. In the context of PeerConnection, it's the network thread. 79 rtc::Thread* const owner_thread_; 80 SctpTransportInformation info_ RTC_GUARDED_BY(owner_thread_); 81 std::unique_ptr<cricket::SctpTransportInternal> internal_sctp_transport_ 82 RTC_GUARDED_BY(owner_thread_); 83 SctpTransportObserverInterface* observer_ RTC_GUARDED_BY(owner_thread_) = 84 nullptr; 85 rtc::scoped_refptr<DtlsTransport> dtls_transport_ 86 RTC_GUARDED_BY(owner_thread_); 87 }; 88 89 } // namespace webrtc 90 #endif // PC_SCTP_TRANSPORT_H_ 91