1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2019 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef API_SCTP_TRANSPORT_INTERFACE_H_ 12*d9f75844SAndroid Build Coastguard Worker #define API_SCTP_TRANSPORT_INTERFACE_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h" 15*d9f75844SAndroid Build Coastguard Worker #include "api/dtls_transport_interface.h" 16*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_error.h" 17*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h" 18*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ref_count.h" 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 21*d9f75844SAndroid Build Coastguard Worker 22*d9f75844SAndroid Build Coastguard Worker // States of a SCTP transport, corresponding to the JS API specification. 23*d9f75844SAndroid Build Coastguard Worker // http://w3c.github.io/webrtc-pc/#dom-rtcsctptransportstate 24*d9f75844SAndroid Build Coastguard Worker enum class SctpTransportState { 25*d9f75844SAndroid Build Coastguard Worker kNew, // Has not started negotiating yet. Non-standard state. 26*d9f75844SAndroid Build Coastguard Worker kConnecting, // In the process of negotiating an association. 27*d9f75844SAndroid Build Coastguard Worker kConnected, // Completed negotiation of an association. 28*d9f75844SAndroid Build Coastguard Worker kClosed, // Closed by local or remote party. 29*d9f75844SAndroid Build Coastguard Worker kNumValues 30*d9f75844SAndroid Build Coastguard Worker }; 31*d9f75844SAndroid Build Coastguard Worker 32*d9f75844SAndroid Build Coastguard Worker // This object gives snapshot information about the changeable state of a 33*d9f75844SAndroid Build Coastguard Worker // SctpTransport. 34*d9f75844SAndroid Build Coastguard Worker // It reflects the readonly attributes of the object in the specification. 35*d9f75844SAndroid Build Coastguard Worker // http://w3c.github.io/webrtc-pc/#rtcsctptransport-interface 36*d9f75844SAndroid Build Coastguard Worker class RTC_EXPORT SctpTransportInformation { 37*d9f75844SAndroid Build Coastguard Worker public: 38*d9f75844SAndroid Build Coastguard Worker SctpTransportInformation() = default; 39*d9f75844SAndroid Build Coastguard Worker SctpTransportInformation(const SctpTransportInformation&) = default; 40*d9f75844SAndroid Build Coastguard Worker explicit SctpTransportInformation(SctpTransportState state); 41*d9f75844SAndroid Build Coastguard Worker SctpTransportInformation( 42*d9f75844SAndroid Build Coastguard Worker SctpTransportState state, 43*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<DtlsTransportInterface> dtls_transport, 44*d9f75844SAndroid Build Coastguard Worker absl::optional<double> max_message_size, 45*d9f75844SAndroid Build Coastguard Worker absl::optional<int> max_channels); 46*d9f75844SAndroid Build Coastguard Worker ~SctpTransportInformation(); 47*d9f75844SAndroid Build Coastguard Worker // The DTLS transport that supports this SCTP transport. dtls_transport()48*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const { 49*d9f75844SAndroid Build Coastguard Worker return dtls_transport_; 50*d9f75844SAndroid Build Coastguard Worker } state()51*d9f75844SAndroid Build Coastguard Worker SctpTransportState state() const { return state_; } MaxMessageSize()52*d9f75844SAndroid Build Coastguard Worker absl::optional<double> MaxMessageSize() const { return max_message_size_; } MaxChannels()53*d9f75844SAndroid Build Coastguard Worker absl::optional<int> MaxChannels() const { return max_channels_; } 54*d9f75844SAndroid Build Coastguard Worker 55*d9f75844SAndroid Build Coastguard Worker private: 56*d9f75844SAndroid Build Coastguard Worker SctpTransportState state_; 57*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_; 58*d9f75844SAndroid Build Coastguard Worker absl::optional<double> max_message_size_; 59*d9f75844SAndroid Build Coastguard Worker absl::optional<int> max_channels_; 60*d9f75844SAndroid Build Coastguard Worker }; 61*d9f75844SAndroid Build Coastguard Worker 62*d9f75844SAndroid Build Coastguard Worker class SctpTransportObserverInterface { 63*d9f75844SAndroid Build Coastguard Worker public: 64*d9f75844SAndroid Build Coastguard Worker // This callback carries information about the state of the transport. 65*d9f75844SAndroid Build Coastguard Worker // The argument is a pass-by-value snapshot of the state. 66*d9f75844SAndroid Build Coastguard Worker // The callback will be called on the network thread. 67*d9f75844SAndroid Build Coastguard Worker virtual void OnStateChange(SctpTransportInformation info) = 0; 68*d9f75844SAndroid Build Coastguard Worker 69*d9f75844SAndroid Build Coastguard Worker protected: 70*d9f75844SAndroid Build Coastguard Worker virtual ~SctpTransportObserverInterface() = default; 71*d9f75844SAndroid Build Coastguard Worker }; 72*d9f75844SAndroid Build Coastguard Worker 73*d9f75844SAndroid Build Coastguard Worker // A SCTP transport, as represented to the outside world. 74*d9f75844SAndroid Build Coastguard Worker // This object is created on the network thread, and can only be 75*d9f75844SAndroid Build Coastguard Worker // accessed on that thread, except for functions explicitly marked otherwise. 76*d9f75844SAndroid Build Coastguard Worker // References can be held by other threads, and destruction can therefore 77*d9f75844SAndroid Build Coastguard Worker // be initiated by other threads. 78*d9f75844SAndroid Build Coastguard Worker class SctpTransportInterface : public rtc::RefCountInterface { 79*d9f75844SAndroid Build Coastguard Worker public: 80*d9f75844SAndroid Build Coastguard Worker // This function can be called from other threads. 81*d9f75844SAndroid Build Coastguard Worker virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0; 82*d9f75844SAndroid Build Coastguard Worker // Returns information on the state of the SctpTransport. 83*d9f75844SAndroid Build Coastguard Worker // This function can be called from other threads. 84*d9f75844SAndroid Build Coastguard Worker virtual SctpTransportInformation Information() const = 0; 85*d9f75844SAndroid Build Coastguard Worker // Observer management. 86*d9f75844SAndroid Build Coastguard Worker virtual void RegisterObserver(SctpTransportObserverInterface* observer) = 0; 87*d9f75844SAndroid Build Coastguard Worker virtual void UnregisterObserver() = 0; 88*d9f75844SAndroid Build Coastguard Worker }; 89*d9f75844SAndroid Build Coastguard Worker 90*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 91*d9f75844SAndroid Build Coastguard Worker 92*d9f75844SAndroid Build Coastguard Worker #endif // API_SCTP_TRANSPORT_INTERFACE_H_ 93