xref: /aosp_15_r20/external/webrtc/net/dcsctp/socket/dcsctp_socket.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2021 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 #ifndef NET_DCSCTP_SOCKET_DCSCTP_SOCKET_H_
11*d9f75844SAndroid Build Coastguard Worker #define NET_DCSCTP_SOCKET_DCSCTP_SOCKET_H_
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <cstdint>
14*d9f75844SAndroid Build Coastguard Worker #include <memory>
15*d9f75844SAndroid Build Coastguard Worker #include <string>
16*d9f75844SAndroid Build Coastguard Worker #include <utility>
17*d9f75844SAndroid Build Coastguard Worker 
18*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
19*d9f75844SAndroid Build Coastguard Worker #include "api/array_view.h"
20*d9f75844SAndroid Build Coastguard Worker #include "api/sequence_checker.h"
21*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/abort_chunk.h"
22*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/chunk.h"
23*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/cookie_ack_chunk.h"
24*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/cookie_echo_chunk.h"
25*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/data_chunk.h"
26*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/data_common.h"
27*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/error_chunk.h"
28*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/forward_tsn_chunk.h"
29*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/forward_tsn_common.h"
30*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/heartbeat_ack_chunk.h"
31*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/heartbeat_request_chunk.h"
32*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/idata_chunk.h"
33*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/iforward_tsn_chunk.h"
34*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/init_ack_chunk.h"
35*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/init_chunk.h"
36*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/reconfig_chunk.h"
37*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/sack_chunk.h"
38*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/shutdown_ack_chunk.h"
39*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/shutdown_chunk.h"
40*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/chunk/shutdown_complete_chunk.h"
41*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/data.h"
42*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/packet/sctp_packet.h"
43*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/public/dcsctp_message.h"
44*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/public/dcsctp_options.h"
45*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/public/dcsctp_socket.h"
46*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/public/packet_observer.h"
47*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/rx/data_tracker.h"
48*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/rx/reassembly_queue.h"
49*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/socket/callback_deferrer.h"
50*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/socket/packet_sender.h"
51*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/socket/state_cookie.h"
52*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/socket/transmission_control_block.h"
53*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/timer/timer.h"
54*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/tx/retransmission_error_counter.h"
55*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/tx/retransmission_queue.h"
56*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/tx/retransmission_timeout.h"
57*d9f75844SAndroid Build Coastguard Worker #include "net/dcsctp/tx/rr_send_queue.h"
58*d9f75844SAndroid Build Coastguard Worker 
59*d9f75844SAndroid Build Coastguard Worker namespace dcsctp {
60*d9f75844SAndroid Build Coastguard Worker 
61*d9f75844SAndroid Build Coastguard Worker // DcSctpSocket represents a single SCTP socket, to be used over DTLS.
62*d9f75844SAndroid Build Coastguard Worker //
63*d9f75844SAndroid Build Coastguard Worker // Every dcSCTP is completely isolated from any other socket.
64*d9f75844SAndroid Build Coastguard Worker //
65*d9f75844SAndroid Build Coastguard Worker // This class manages all packet and chunk dispatching and mainly handles the
66*d9f75844SAndroid Build Coastguard Worker // connection sequences (connect, close, shutdown, etc) as well as managing
67*d9f75844SAndroid Build Coastguard Worker // the Transmission Control Block (tcb).
68*d9f75844SAndroid Build Coastguard Worker //
69*d9f75844SAndroid Build Coastguard Worker // This class is thread-compatible.
70*d9f75844SAndroid Build Coastguard Worker class DcSctpSocket : public DcSctpSocketInterface {
71*d9f75844SAndroid Build Coastguard Worker  public:
72*d9f75844SAndroid Build Coastguard Worker   // Instantiates a DcSctpSocket, which interacts with the world through the
73*d9f75844SAndroid Build Coastguard Worker   // `callbacks` interface and is configured using `options`.
74*d9f75844SAndroid Build Coastguard Worker   //
75*d9f75844SAndroid Build Coastguard Worker   // For debugging, `log_prefix` will prefix all debug logs, and a
76*d9f75844SAndroid Build Coastguard Worker   // `packet_observer` can be attached to e.g. dump sent and received packets.
77*d9f75844SAndroid Build Coastguard Worker   DcSctpSocket(absl::string_view log_prefix,
78*d9f75844SAndroid Build Coastguard Worker                DcSctpSocketCallbacks& callbacks,
79*d9f75844SAndroid Build Coastguard Worker                std::unique_ptr<PacketObserver> packet_observer,
80*d9f75844SAndroid Build Coastguard Worker                const DcSctpOptions& options);
81*d9f75844SAndroid Build Coastguard Worker 
82*d9f75844SAndroid Build Coastguard Worker   DcSctpSocket(const DcSctpSocket&) = delete;
83*d9f75844SAndroid Build Coastguard Worker   DcSctpSocket& operator=(const DcSctpSocket&) = delete;
84*d9f75844SAndroid Build Coastguard Worker 
85*d9f75844SAndroid Build Coastguard Worker   // Implementation of `DcSctpSocketInterface`.
86*d9f75844SAndroid Build Coastguard Worker   void ReceivePacket(rtc::ArrayView<const uint8_t> data) override;
87*d9f75844SAndroid Build Coastguard Worker   void HandleTimeout(TimeoutID timeout_id) override;
88*d9f75844SAndroid Build Coastguard Worker   void Connect() override;
89*d9f75844SAndroid Build Coastguard Worker   void RestoreFromState(const DcSctpSocketHandoverState& state) override;
90*d9f75844SAndroid Build Coastguard Worker   void Shutdown() override;
91*d9f75844SAndroid Build Coastguard Worker   void Close() override;
92*d9f75844SAndroid Build Coastguard Worker   SendStatus Send(DcSctpMessage message,
93*d9f75844SAndroid Build Coastguard Worker                   const SendOptions& send_options) override;
94*d9f75844SAndroid Build Coastguard Worker   ResetStreamsStatus ResetStreams(
95*d9f75844SAndroid Build Coastguard Worker       rtc::ArrayView<const StreamID> outgoing_streams) override;
96*d9f75844SAndroid Build Coastguard Worker   SocketState state() const override;
options()97*d9f75844SAndroid Build Coastguard Worker   const DcSctpOptions& options() const override { return options_; }
98*d9f75844SAndroid Build Coastguard Worker   void SetMaxMessageSize(size_t max_message_size) override;
99*d9f75844SAndroid Build Coastguard Worker   void SetStreamPriority(StreamID stream_id, StreamPriority priority) override;
100*d9f75844SAndroid Build Coastguard Worker   StreamPriority GetStreamPriority(StreamID stream_id) const override;
101*d9f75844SAndroid Build Coastguard Worker   size_t buffered_amount(StreamID stream_id) const override;
102*d9f75844SAndroid Build Coastguard Worker   size_t buffered_amount_low_threshold(StreamID stream_id) const override;
103*d9f75844SAndroid Build Coastguard Worker   void SetBufferedAmountLowThreshold(StreamID stream_id, size_t bytes) override;
104*d9f75844SAndroid Build Coastguard Worker   absl::optional<Metrics> GetMetrics() const override;
105*d9f75844SAndroid Build Coastguard Worker   HandoverReadinessStatus GetHandoverReadiness() const override;
106*d9f75844SAndroid Build Coastguard Worker   absl::optional<DcSctpSocketHandoverState> GetHandoverStateAndClose() override;
peer_implementation()107*d9f75844SAndroid Build Coastguard Worker   SctpImplementation peer_implementation() const override {
108*d9f75844SAndroid Build Coastguard Worker     return metrics_.peer_implementation;
109*d9f75844SAndroid Build Coastguard Worker   }
110*d9f75844SAndroid Build Coastguard Worker   // Returns this socket's verification tag, or zero if not yet connected.
verification_tag()111*d9f75844SAndroid Build Coastguard Worker   VerificationTag verification_tag() const {
112*d9f75844SAndroid Build Coastguard Worker     return tcb_ != nullptr ? tcb_->my_verification_tag() : VerificationTag(0);
113*d9f75844SAndroid Build Coastguard Worker   }
114*d9f75844SAndroid Build Coastguard Worker 
115*d9f75844SAndroid Build Coastguard Worker  private:
116*d9f75844SAndroid Build Coastguard Worker   // Parameter proposals valid during the connect phase.
117*d9f75844SAndroid Build Coastguard Worker   struct ConnectParameters {
118*d9f75844SAndroid Build Coastguard Worker     TSN initial_tsn = TSN(0);
119*d9f75844SAndroid Build Coastguard Worker     VerificationTag verification_tag = VerificationTag(0);
120*d9f75844SAndroid Build Coastguard Worker   };
121*d9f75844SAndroid Build Coastguard Worker 
122*d9f75844SAndroid Build Coastguard Worker   // Detailed state (separate from SocketState, which is the public state).
123*d9f75844SAndroid Build Coastguard Worker   enum class State {
124*d9f75844SAndroid Build Coastguard Worker     kClosed,
125*d9f75844SAndroid Build Coastguard Worker     kCookieWait,
126*d9f75844SAndroid Build Coastguard Worker     // TCB valid in these:
127*d9f75844SAndroid Build Coastguard Worker     kCookieEchoed,
128*d9f75844SAndroid Build Coastguard Worker     kEstablished,
129*d9f75844SAndroid Build Coastguard Worker     kShutdownPending,
130*d9f75844SAndroid Build Coastguard Worker     kShutdownSent,
131*d9f75844SAndroid Build Coastguard Worker     kShutdownReceived,
132*d9f75844SAndroid Build Coastguard Worker     kShutdownAckSent,
133*d9f75844SAndroid Build Coastguard Worker   };
134*d9f75844SAndroid Build Coastguard Worker 
135*d9f75844SAndroid Build Coastguard Worker   // Returns the log prefix used for debug logging.
136*d9f75844SAndroid Build Coastguard Worker   std::string log_prefix() const;
137*d9f75844SAndroid Build Coastguard Worker 
138*d9f75844SAndroid Build Coastguard Worker   bool IsConsistent() const;
139*d9f75844SAndroid Build Coastguard Worker   static constexpr absl::string_view ToString(DcSctpSocket::State state);
140*d9f75844SAndroid Build Coastguard Worker 
141*d9f75844SAndroid Build Coastguard Worker   void CreateTransmissionControlBlock(const Capabilities& capabilities,
142*d9f75844SAndroid Build Coastguard Worker                                       VerificationTag my_verification_tag,
143*d9f75844SAndroid Build Coastguard Worker                                       TSN my_initial_tsn,
144*d9f75844SAndroid Build Coastguard Worker                                       VerificationTag peer_verification_tag,
145*d9f75844SAndroid Build Coastguard Worker                                       TSN peer_initial_tsn,
146*d9f75844SAndroid Build Coastguard Worker                                       size_t a_rwnd,
147*d9f75844SAndroid Build Coastguard Worker                                       TieTag tie_tag);
148*d9f75844SAndroid Build Coastguard Worker 
149*d9f75844SAndroid Build Coastguard Worker   // Changes the socket state, given a `reason` (for debugging/logging).
150*d9f75844SAndroid Build Coastguard Worker   void SetState(State state, absl::string_view reason);
151*d9f75844SAndroid Build Coastguard Worker   // Fills in `connect_params` with random verification tag and initial TSN.
152*d9f75844SAndroid Build Coastguard Worker   void MakeConnectionParameters();
153*d9f75844SAndroid Build Coastguard Worker   // Closes the association. Note that the TCB will not be valid past this call.
154*d9f75844SAndroid Build Coastguard Worker   void InternalClose(ErrorKind error, absl::string_view message);
155*d9f75844SAndroid Build Coastguard Worker   // Closes the association, because of too many retransmission errors.
156*d9f75844SAndroid Build Coastguard Worker   void CloseConnectionBecauseOfTooManyTransmissionErrors();
157*d9f75844SAndroid Build Coastguard Worker   // Timer expiration handlers
158*d9f75844SAndroid Build Coastguard Worker   absl::optional<DurationMs> OnInitTimerExpiry();
159*d9f75844SAndroid Build Coastguard Worker   absl::optional<DurationMs> OnCookieTimerExpiry();
160*d9f75844SAndroid Build Coastguard Worker   absl::optional<DurationMs> OnShutdownTimerExpiry();
161*d9f75844SAndroid Build Coastguard Worker   void OnSentPacket(rtc::ArrayView<const uint8_t> packet,
162*d9f75844SAndroid Build Coastguard Worker                     SendPacketStatus status);
163*d9f75844SAndroid Build Coastguard Worker   // Sends SHUTDOWN or SHUTDOWN-ACK if the socket is shutting down and if all
164*d9f75844SAndroid Build Coastguard Worker   // outstanding data has been acknowledged.
165*d9f75844SAndroid Build Coastguard Worker   void MaybeSendShutdownOrAck();
166*d9f75844SAndroid Build Coastguard Worker   // If the socket is shutting down, responds SHUTDOWN to any incoming DATA.
167*d9f75844SAndroid Build Coastguard Worker   void MaybeSendShutdownOnPacketReceived(const SctpPacket& packet);
168*d9f75844SAndroid Build Coastguard Worker   // If there are streams pending to be reset, send a request to reset them.
169*d9f75844SAndroid Build Coastguard Worker   void MaybeSendResetStreamsRequest();
170*d9f75844SAndroid Build Coastguard Worker   // Sends a INIT chunk.
171*d9f75844SAndroid Build Coastguard Worker   void SendInit();
172*d9f75844SAndroid Build Coastguard Worker   // Sends a SHUTDOWN chunk.
173*d9f75844SAndroid Build Coastguard Worker   void SendShutdown();
174*d9f75844SAndroid Build Coastguard Worker   // Sends a SHUTDOWN-ACK chunk.
175*d9f75844SAndroid Build Coastguard Worker   void SendShutdownAck();
176*d9f75844SAndroid Build Coastguard Worker   // Validates the SCTP packet, as a whole - not the validity of individual
177*d9f75844SAndroid Build Coastguard Worker   // chunks within it, as that's done in the different chunk handlers.
178*d9f75844SAndroid Build Coastguard Worker   bool ValidatePacket(const SctpPacket& packet);
179*d9f75844SAndroid Build Coastguard Worker   // Parses `payload`, which is a serialized packet that is just going to be
180*d9f75844SAndroid Build Coastguard Worker   // sent and prints all chunks.
181*d9f75844SAndroid Build Coastguard Worker   void DebugPrintOutgoing(rtc::ArrayView<const uint8_t> payload);
182*d9f75844SAndroid Build Coastguard Worker   // Called whenever there may be reassembled messages, and delivers those.
183*d9f75844SAndroid Build Coastguard Worker   void DeliverReassembledMessages();
184*d9f75844SAndroid Build Coastguard Worker   // Returns true if there is a TCB, and false otherwise (and reports an error).
185*d9f75844SAndroid Build Coastguard Worker   bool ValidateHasTCB();
186*d9f75844SAndroid Build Coastguard Worker 
187*d9f75844SAndroid Build Coastguard Worker   // Returns true if the parsing of a chunk of type `T` succeeded. If it didn't,
188*d9f75844SAndroid Build Coastguard Worker   // it reports an error and returns false.
189*d9f75844SAndroid Build Coastguard Worker   template <class T>
ValidateParseSuccess(const absl::optional<T> & c)190*d9f75844SAndroid Build Coastguard Worker   bool ValidateParseSuccess(const absl::optional<T>& c) {
191*d9f75844SAndroid Build Coastguard Worker     if (c.has_value()) {
192*d9f75844SAndroid Build Coastguard Worker       return true;
193*d9f75844SAndroid Build Coastguard Worker     }
194*d9f75844SAndroid Build Coastguard Worker 
195*d9f75844SAndroid Build Coastguard Worker     ReportFailedToParseChunk(T::kType);
196*d9f75844SAndroid Build Coastguard Worker     return false;
197*d9f75844SAndroid Build Coastguard Worker   }
198*d9f75844SAndroid Build Coastguard Worker 
199*d9f75844SAndroid Build Coastguard Worker   // Reports failing to have parsed a chunk with the provided `chunk_type`.
200*d9f75844SAndroid Build Coastguard Worker   void ReportFailedToParseChunk(int chunk_type);
201*d9f75844SAndroid Build Coastguard Worker   // Called when unknown chunks are received. May report an error.
202*d9f75844SAndroid Build Coastguard Worker   bool HandleUnrecognizedChunk(const SctpPacket::ChunkDescriptor& descriptor);
203*d9f75844SAndroid Build Coastguard Worker 
204*d9f75844SAndroid Build Coastguard Worker   // Will dispatch more specific chunk handlers.
205*d9f75844SAndroid Build Coastguard Worker   bool Dispatch(const CommonHeader& header,
206*d9f75844SAndroid Build Coastguard Worker                 const SctpPacket::ChunkDescriptor& descriptor);
207*d9f75844SAndroid Build Coastguard Worker   // Handles incoming DATA chunks.
208*d9f75844SAndroid Build Coastguard Worker   void HandleData(const CommonHeader& header,
209*d9f75844SAndroid Build Coastguard Worker                   const SctpPacket::ChunkDescriptor& descriptor);
210*d9f75844SAndroid Build Coastguard Worker   // Handles incoming I-DATA chunks.
211*d9f75844SAndroid Build Coastguard Worker   void HandleIData(const CommonHeader& header,
212*d9f75844SAndroid Build Coastguard Worker                    const SctpPacket::ChunkDescriptor& descriptor);
213*d9f75844SAndroid Build Coastguard Worker   // Common handler for DATA and I-DATA chunks.
214*d9f75844SAndroid Build Coastguard Worker   void HandleDataCommon(AnyDataChunk& chunk);
215*d9f75844SAndroid Build Coastguard Worker   // Handles incoming INIT chunks.
216*d9f75844SAndroid Build Coastguard Worker   void HandleInit(const CommonHeader& header,
217*d9f75844SAndroid Build Coastguard Worker                   const SctpPacket::ChunkDescriptor& descriptor);
218*d9f75844SAndroid Build Coastguard Worker   // Handles incoming INIT-ACK chunks.
219*d9f75844SAndroid Build Coastguard Worker   void HandleInitAck(const CommonHeader& header,
220*d9f75844SAndroid Build Coastguard Worker                      const SctpPacket::ChunkDescriptor& descriptor);
221*d9f75844SAndroid Build Coastguard Worker   // Handles incoming SACK chunks.
222*d9f75844SAndroid Build Coastguard Worker   void HandleSack(const CommonHeader& header,
223*d9f75844SAndroid Build Coastguard Worker                   const SctpPacket::ChunkDescriptor& descriptor);
224*d9f75844SAndroid Build Coastguard Worker   // Handles incoming HEARTBEAT chunks.
225*d9f75844SAndroid Build Coastguard Worker   void HandleHeartbeatRequest(const CommonHeader& header,
226*d9f75844SAndroid Build Coastguard Worker                               const SctpPacket::ChunkDescriptor& descriptor);
227*d9f75844SAndroid Build Coastguard Worker   // Handles incoming HEARTBEAT-ACK chunks.
228*d9f75844SAndroid Build Coastguard Worker   void HandleHeartbeatAck(const CommonHeader& header,
229*d9f75844SAndroid Build Coastguard Worker                           const SctpPacket::ChunkDescriptor& descriptor);
230*d9f75844SAndroid Build Coastguard Worker   // Handles incoming ABORT chunks.
231*d9f75844SAndroid Build Coastguard Worker   void HandleAbort(const CommonHeader& header,
232*d9f75844SAndroid Build Coastguard Worker                    const SctpPacket::ChunkDescriptor& descriptor);
233*d9f75844SAndroid Build Coastguard Worker   // Handles incoming ERROR chunks.
234*d9f75844SAndroid Build Coastguard Worker   void HandleError(const CommonHeader& header,
235*d9f75844SAndroid Build Coastguard Worker                    const SctpPacket::ChunkDescriptor& descriptor);
236*d9f75844SAndroid Build Coastguard Worker   // Handles incoming COOKIE-ECHO chunks.
237*d9f75844SAndroid Build Coastguard Worker   void HandleCookieEcho(const CommonHeader& header,
238*d9f75844SAndroid Build Coastguard Worker                         const SctpPacket::ChunkDescriptor& descriptor);
239*d9f75844SAndroid Build Coastguard Worker   // Handles receiving COOKIE-ECHO when there already is a TCB. The return value
240*d9f75844SAndroid Build Coastguard Worker   // indicates if the processing should continue.
241*d9f75844SAndroid Build Coastguard Worker   bool HandleCookieEchoWithTCB(const CommonHeader& header,
242*d9f75844SAndroid Build Coastguard Worker                                const StateCookie& cookie);
243*d9f75844SAndroid Build Coastguard Worker   // Handles incoming COOKIE-ACK chunks.
244*d9f75844SAndroid Build Coastguard Worker   void HandleCookieAck(const CommonHeader& header,
245*d9f75844SAndroid Build Coastguard Worker                        const SctpPacket::ChunkDescriptor& descriptor);
246*d9f75844SAndroid Build Coastguard Worker   // Handles incoming SHUTDOWN chunks.
247*d9f75844SAndroid Build Coastguard Worker   void HandleShutdown(const CommonHeader& header,
248*d9f75844SAndroid Build Coastguard Worker                       const SctpPacket::ChunkDescriptor& descriptor);
249*d9f75844SAndroid Build Coastguard Worker   // Handles incoming SHUTDOWN-ACK chunks.
250*d9f75844SAndroid Build Coastguard Worker   void HandleShutdownAck(const CommonHeader& header,
251*d9f75844SAndroid Build Coastguard Worker                          const SctpPacket::ChunkDescriptor& descriptor);
252*d9f75844SAndroid Build Coastguard Worker   // Handles incoming FORWARD-TSN chunks.
253*d9f75844SAndroid Build Coastguard Worker   void HandleForwardTsn(const CommonHeader& header,
254*d9f75844SAndroid Build Coastguard Worker                         const SctpPacket::ChunkDescriptor& descriptor);
255*d9f75844SAndroid Build Coastguard Worker   // Handles incoming I-FORWARD-TSN chunks.
256*d9f75844SAndroid Build Coastguard Worker   void HandleIForwardTsn(const CommonHeader& header,
257*d9f75844SAndroid Build Coastguard Worker                          const SctpPacket::ChunkDescriptor& descriptor);
258*d9f75844SAndroid Build Coastguard Worker   // Handles incoming RE-CONFIG chunks.
259*d9f75844SAndroid Build Coastguard Worker   void HandleReconfig(const CommonHeader& header,
260*d9f75844SAndroid Build Coastguard Worker                       const SctpPacket::ChunkDescriptor& descriptor);
261*d9f75844SAndroid Build Coastguard Worker   // Common handled for FORWARD-TSN/I-FORWARD-TSN.
262*d9f75844SAndroid Build Coastguard Worker   void HandleForwardTsnCommon(const AnyForwardTsnChunk& chunk);
263*d9f75844SAndroid Build Coastguard Worker   // Handles incoming SHUTDOWN-COMPLETE chunks
264*d9f75844SAndroid Build Coastguard Worker   void HandleShutdownComplete(const CommonHeader& header,
265*d9f75844SAndroid Build Coastguard Worker                               const SctpPacket::ChunkDescriptor& descriptor);
266*d9f75844SAndroid Build Coastguard Worker 
267*d9f75844SAndroid Build Coastguard Worker   const std::string log_prefix_;
268*d9f75844SAndroid Build Coastguard Worker   const std::unique_ptr<PacketObserver> packet_observer_;
269*d9f75844SAndroid Build Coastguard Worker   RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker thread_checker_;
270*d9f75844SAndroid Build Coastguard Worker   Metrics metrics_;
271*d9f75844SAndroid Build Coastguard Worker   DcSctpOptions options_;
272*d9f75844SAndroid Build Coastguard Worker 
273*d9f75844SAndroid Build Coastguard Worker   // Enqueues callbacks and dispatches them just before returning to the caller.
274*d9f75844SAndroid Build Coastguard Worker   CallbackDeferrer callbacks_;
275*d9f75844SAndroid Build Coastguard Worker 
276*d9f75844SAndroid Build Coastguard Worker   TimerManager timer_manager_;
277*d9f75844SAndroid Build Coastguard Worker   const std::unique_ptr<Timer> t1_init_;
278*d9f75844SAndroid Build Coastguard Worker   const std::unique_ptr<Timer> t1_cookie_;
279*d9f75844SAndroid Build Coastguard Worker   const std::unique_ptr<Timer> t2_shutdown_;
280*d9f75844SAndroid Build Coastguard Worker 
281*d9f75844SAndroid Build Coastguard Worker   // Packets that failed to be sent, but should be retried.
282*d9f75844SAndroid Build Coastguard Worker   PacketSender packet_sender_;
283*d9f75844SAndroid Build Coastguard Worker 
284*d9f75844SAndroid Build Coastguard Worker   // The actual SendQueue implementation. As data can be sent on a socket before
285*d9f75844SAndroid Build Coastguard Worker   // the connection is established, this component is not in the TCB.
286*d9f75844SAndroid Build Coastguard Worker   RRSendQueue send_queue_;
287*d9f75844SAndroid Build Coastguard Worker 
288*d9f75844SAndroid Build Coastguard Worker   // Contains verification tag and initial TSN between having sent the INIT
289*d9f75844SAndroid Build Coastguard Worker   // until the connection is established (there is no TCB at this point).
290*d9f75844SAndroid Build Coastguard Worker   ConnectParameters connect_params_;
291*d9f75844SAndroid Build Coastguard Worker   // The socket state.
292*d9f75844SAndroid Build Coastguard Worker   State state_ = State::kClosed;
293*d9f75844SAndroid Build Coastguard Worker   // If the connection is established, contains a transmission control block.
294*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<TransmissionControlBlock> tcb_;
295*d9f75844SAndroid Build Coastguard Worker };
296*d9f75844SAndroid Build Coastguard Worker }  // namespace dcsctp
297*d9f75844SAndroid Build Coastguard Worker 
298*d9f75844SAndroid Build Coastguard Worker #endif  // NET_DCSCTP_SOCKET_DCSCTP_SOCKET_H_
299