blob: 8f669ca95bcb20855bc5e4f8d860f7e832bc4f27 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// The base class for client/server QUIC streams.
6
7// It does not contain the entire interface needed by an application to interact
8// with a QUIC stream. Some parts of the interface must be obtained by
9// accessing the owning session object. A subclass of QuicStream
10// connects the object and the application that generates and consumes the data
11// of the stream.
12
13// The QuicStream object has a dependent QuicStreamSequencer object,
14// which is given the stream frames as they arrive, and provides stream data in
15// order by invoking ProcessRawData().
16
17#ifndef QUICHE_QUIC_CORE_QUIC_STREAM_H_
18#define QUICHE_QUIC_CORE_QUIC_STREAM_H_
19
20#include <cstddef>
21#include <cstdint>
22#include <list>
vasilvv872e7a32019-03-12 16:42:44 -070023#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050024
QUICHE teama6ef0a62019-03-07 20:34:33 -050025#include "net/third_party/quiche/src/quic/core/quic_flow_controller.h"
26#include "net/third_party/quiche/src/quic/core/quic_packets.h"
27#include "net/third_party/quiche/src/quic/core/quic_stream_send_buffer.h"
28#include "net/third_party/quiche/src/quic/core/quic_stream_sequencer.h"
29#include "net/third_party/quiche/src/quic/core/quic_types.h"
30#include "net/third_party/quiche/src/quic/core/session_notifier_interface.h"
renjietangf196f6a2020-02-12 12:34:23 -080031#include "net/third_party/quiche/src/quic/core/stream_delegate_interface.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050032#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
33#include "net/third_party/quiche/src/quic/platform/api/quic_mem_slice_span.h"
34#include "net/third_party/quiche/src/quic/platform/api/quic_reference_counted.h"
dmcardle15db6882020-02-26 12:55:36 -080035#include "net/third_party/quiche/src/common/platform/api/quiche_optional.h"
dmcardlecf0bfcf2019-12-13 08:08:21 -080036#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050037#include "net/third_party/quiche/src/spdy/core/spdy_protocol.h"
38
39namespace quic {
40
41namespace test {
42class QuicStreamPeer;
43} // namespace test
44
45class QuicSession;
46class QuicStream;
47
48// Buffers frames for a stream until the first byte of that frame arrives.
49class QUIC_EXPORT_PRIVATE PendingStream
50 : public QuicStreamSequencer::StreamInterface {
51 public:
52 PendingStream(QuicStreamId id, QuicSession* session);
53 PendingStream(const PendingStream&) = delete;
54 PendingStream(PendingStream&&) = default;
55 ~PendingStream() override = default;
56
57 // QuicStreamSequencer::StreamInterface
58 void OnDataAvailable() override;
59 void OnFinRead() override;
60 void AddBytesConsumed(QuicByteCount bytes) override;
61 void Reset(QuicRstStreamErrorCode error) override;
renjietang87df0d02020-02-13 11:53:52 -080062 void OnUnrecoverableError(QuicErrorCode error,
63 const std::string& details) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050064 QuicStreamId id() const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050065
66 // Buffers the contents of |frame|. Frame must have a non-zero offset.
67 // If the data violates flow control, the connection will be closed.
68 void OnStreamFrame(const QuicStreamFrame& frame);
69
70 // Stores the final byte offset from |frame|.
71 // If the final offset violates flow control, the connection will be closed.
72 void OnRstStreamFrame(const QuicRstStreamFrame& frame);
73
74 // Returns the number of bytes read on this stream.
75 uint64_t stream_bytes_read() { return stream_bytes_read_; }
76
renjietang0c558862019-05-08 13:26:23 -070077 const QuicStreamSequencer* sequencer() const { return &sequencer_; }
78
dschinazif1e7b422020-04-30 12:21:28 -070079 void MarkConsumed(QuicByteCount num_bytes);
renjietangbb1c4892019-05-24 15:58:44 -070080
bnc4ff60622019-08-09 18:55:45 -070081 // Tells the sequencer to ignore all incoming data itself and not call
82 // OnDataAvailable().
83 void StopReading();
84
QUICHE teama6ef0a62019-03-07 20:34:33 -050085 private:
86 friend class QuicStream;
87
88 bool MaybeIncreaseHighestReceivedOffset(QuicStreamOffset new_offset);
89
90 // ID of this stream.
91 QuicStreamId id_;
92
93 // Session which owns this.
renjietangf196f6a2020-02-12 12:34:23 -080094 // TODO(b/136274541): Remove session pointer from streams.
QUICHE teama6ef0a62019-03-07 20:34:33 -050095 QuicSession* session_;
renjietangf196f6a2020-02-12 12:34:23 -080096 StreamDelegateInterface* stream_delegate_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050097
98 // Bytes read refers to payload bytes only: they do not include framing,
99 // encryption overhead etc.
100 uint64_t stream_bytes_read_;
101
102 // True if a frame containing a fin has been received.
103 bool fin_received_;
104
105 // Connection-level flow controller. Owned by the session.
106 QuicFlowController* connection_flow_controller_;
107 // Stream-level flow controller.
108 QuicFlowController flow_controller_;
109 // Stores the buffered frames.
110 QuicStreamSequencer sequencer_;
111};
112
113class QUIC_EXPORT_PRIVATE QuicStream
114 : public QuicStreamSequencer::StreamInterface {
115 public:
bnc3e004e92020-08-31 07:03:13 -0700116 // Default priority for Google QUIC.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500117 // This is somewhat arbitrary. It's possible, but unlikely, we will either
118 // fail to set a priority client-side, or cancel a stream before stripping the
119 // priority from the wire server-side. In either case, start out with a
bnc5f202512020-02-01 18:43:02 -0800120 // priority in the middle in case of Google QUIC.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500121 static const spdy::SpdyPriority kDefaultPriority = 3;
122 static_assert(kDefaultPriority ==
123 (spdy::kV3LowestPriority + spdy::kV3HighestPriority) / 2,
124 "Unexpected value of kDefaultPriority");
125
126 // Creates a new stream with stream_id |id| associated with |session|. If
127 // |is_static| is true, then the stream will be given precedence
128 // over other streams when determing what streams should write next.
129 // |type| indicates whether the stream is bidirectional, read unidirectional
130 // or write unidirectional.
131 // TODO(fayang): Remove |type| when IETF stream ID numbering fully kicks in.
132 QuicStream(QuicStreamId id,
133 QuicSession* session,
134 bool is_static,
135 StreamType type);
renjietangbaea59c2019-05-29 15:08:14 -0700136 QuicStream(PendingStream* pending, StreamType type, bool is_static);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500137 QuicStream(const QuicStream&) = delete;
138 QuicStream& operator=(const QuicStream&) = delete;
139
140 virtual ~QuicStream();
141
bnc3e004e92020-08-31 07:03:13 -0700142 // Default priority for IETF QUIC, defined by the priority extension at
143 // https://httpwg.org/http-extensions/draft-ietf-httpbis-priority.html#urgency.
144 // TODO(bnc): Remove this method and reinstate static const int
145 // kDefaultUrgency member when removing quic_http3_new_default_urgency_value.
146 static int DefaultUrgency();
147
QUICHE teama6ef0a62019-03-07 20:34:33 -0500148 // QuicStreamSequencer::StreamInterface implementation.
149 QuicStreamId id() const override { return id_; }
150 // Called by the stream subclass after it has consumed the final incoming
151 // data.
152 void OnFinRead() override;
153
154 // Called by the subclass or the sequencer to reset the stream from this
155 // end.
156 void Reset(QuicRstStreamErrorCode error) override;
157
158 // Called by the subclass or the sequencer to close the entire connection from
159 // this end.
renjietang87df0d02020-02-13 11:53:52 -0800160 void OnUnrecoverableError(QuicErrorCode error,
161 const std::string& details) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500162
QUICHE teama6ef0a62019-03-07 20:34:33 -0500163 // Called by the session when a (potentially duplicate) stream frame has been
164 // received for this stream.
165 virtual void OnStreamFrame(const QuicStreamFrame& frame);
166
167 // Called by the session when the connection becomes writeable to allow the
168 // stream to write any pending data.
169 virtual void OnCanWrite();
170
QUICHE teama6ef0a62019-03-07 20:34:33 -0500171 // Called by the session when the endpoint receives a RST_STREAM from the
172 // peer.
173 virtual void OnStreamReset(const QuicRstStreamFrame& frame);
174
175 // Called by the session when the endpoint receives or sends a connection
176 // close, and should immediately close the stream.
177 virtual void OnConnectionClosed(QuicErrorCode error,
178 ConnectionCloseSource source);
179
fayang476683a2019-07-25 12:42:16 -0700180 const spdy::SpdyStreamPrecedence& precedence() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500181
bnccf09f952020-01-30 17:35:59 -0800182 // Send PRIORITY_UPDATE frame if application protocol supports it.
183 virtual void MaybeSendPriorityUpdateFrame() {}
184
185 // Sets |priority_| to priority. This should only be called before bytes are
186 // written to the server. For a server stream, this is called when a
187 // PRIORITY_UPDATE frame is received. This calls
188 // MaybeSendPriorityUpdateFrame(), which for a client stream might send a
189 // PRIORITY_UPDATE frame.
fayang476683a2019-07-25 12:42:16 -0700190 void SetPriority(const spdy::SpdyStreamPrecedence& precedence);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500191
192 // Returns true if this stream is still waiting for acks of sent data.
193 // This will return false if all data has been acked, or if the stream
194 // is no longer interested in data being acked (which happens when
195 // a stream is reset because of an error).
196 bool IsWaitingForAcks() const;
197
198 // Number of bytes available to read.
dschinazif1e7b422020-04-30 12:21:28 -0700199 QuicByteCount ReadableBytes() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500200
201 QuicRstStreamErrorCode stream_error() const { return stream_error_; }
202 QuicErrorCode connection_error() const { return connection_error_; }
203
204 bool reading_stopped() const {
205 return sequencer_.ignore_read_data() || read_side_closed_;
206 }
207 bool write_side_closed() const { return write_side_closed_; }
208
renjietang647b3cf2020-08-04 13:23:12 -0700209 bool IsZombie() const {
210 return read_side_closed_ && write_side_closed_ && IsWaitingForAcks();
211 }
212
QUICHE teama6ef0a62019-03-07 20:34:33 -0500213 bool rst_received() const { return rst_received_; }
214 bool rst_sent() const { return rst_sent_; }
215 bool fin_received() const { return fin_received_; }
216 bool fin_sent() const { return fin_sent_; }
217 bool fin_outstanding() const { return fin_outstanding_; }
218 bool fin_lost() const { return fin_lost_; }
219
220 uint64_t BufferedDataBytes() const;
221
222 uint64_t stream_bytes_read() const { return stream_bytes_read_; }
223 uint64_t stream_bytes_written() const;
224
225 size_t busy_counter() const { return busy_counter_; }
226 void set_busy_counter(size_t busy_counter) { busy_counter_ = busy_counter; }
227
QUICHE teama6ef0a62019-03-07 20:34:33 -0500228 // Adjust the flow control window according to new offset in |frame|.
229 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame);
230
231 int num_frames_received() const;
232 int num_duplicate_frames_received() const;
233
renjietang07b2e8d2020-08-10 15:18:24 -0700234 // Flow controller related methods.
235 bool IsFlowControlBlocked() const;
236 QuicStreamOffset highest_received_byte_offset() const;
237 void UpdateReceiveWindowSize(QuicStreamOffset size);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500238
239 // Called when endpoint receives a frame which could increase the highest
240 // offset.
241 // Returns true if the highest offset did increase.
242 bool MaybeIncreaseHighestReceivedOffset(QuicStreamOffset new_offset);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500243
renjietange0f96d72020-04-28 11:25:29 -0700244 // Set the flow controller's send window offset from session config.
renjietang3f68bdf2020-08-10 11:52:30 -0700245 // |was_zero_rtt_rejected| is true if this config is from a rejected IETF QUIC
246 // 0-RTT attempt. Closes the connection and returns false if |new_offset| is
247 // not valid.
248 bool MaybeConfigSendWindowOffset(QuicStreamOffset new_offset,
249 bool was_zero_rtt_rejected);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500250
251 // Returns true if the stream has received either a RST_STREAM or a FIN -
252 // either of which gives a definitive number of bytes which the peer has
253 // sent. If this is not true on deletion of the stream object, the session
254 // must keep track of the stream's byte offset until a definitive final value
255 // arrives.
renjietang6c066562019-11-04 17:05:59 -0800256 bool HasReceivedFinalOffset() const { return fin_received_ || rst_received_; }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500257
258 // Returns true if the stream has queued data waiting to write.
259 bool HasBufferedData() const;
260
261 // Returns the version of QUIC being used for this stream.
262 QuicTransportVersion transport_version() const;
263
264 // Returns the crypto handshake protocol that was used on this stream's
265 // connection.
266 HandshakeProtocol handshake_protocol() const;
267
268 // Sets the sequencer to consume all incoming data itself and not call
269 // OnDataAvailable().
270 // When the FIN is received, the stream will be notified automatically (via
271 // OnFinRead()) (which may happen during the call of StopReading()).
272 // TODO(dworley): There should be machinery to send a RST_STREAM/NO_ERROR and
273 // stop sending stream-level flow-control updates when this end sends FIN.
274 virtual void StopReading();
275
276 // Sends as much of 'data' to the connection as the connection will consume,
277 // and then buffers any remaining data in queued_data_.
278 // If fin is true: if it is immediately passed on to the session,
279 // write_side_closed() becomes true, otherwise fin_buffered_ becomes true.
280 void WriteOrBufferData(
dmcardlecf0bfcf2019-12-13 08:08:21 -0800281 quiche::QuicheStringPiece data,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500282 bool fin,
283 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener);
284
285 // Adds random padding after the fin is consumed for this stream.
286 void AddRandomPaddingAfterFin();
287
288 // Write |data_length| of data starts at |offset| from send buffer.
289 bool WriteStreamData(QuicStreamOffset offset,
290 QuicByteCount data_length,
291 QuicDataWriter* writer);
292
293 // Called when data [offset, offset + data_length) is acked. |fin_acked|
294 // indicates whether the fin is acked. Returns true and updates
295 // |newly_acked_length| if any new stream data (including fin) gets acked.
296 virtual bool OnStreamFrameAcked(QuicStreamOffset offset,
297 QuicByteCount data_length,
298 bool fin_acked,
299 QuicTime::Delta ack_delay_time,
QUICHE team2f5f30b2020-02-18 08:52:28 -0800300 QuicTime receive_timestamp,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500301 QuicByteCount* newly_acked_length);
302
303 // Called when data [offset, offset + data_length) was retransmitted.
304 // |fin_retransmitted| indicates whether fin was retransmitted.
305 virtual void OnStreamFrameRetransmitted(QuicStreamOffset offset,
306 QuicByteCount data_length,
307 bool fin_retransmitted);
308
309 // Called when data [offset, offset + data_length) is considered as lost.
310 // |fin_lost| indicates whether the fin is considered as lost.
311 virtual void OnStreamFrameLost(QuicStreamOffset offset,
312 QuicByteCount data_length,
313 bool fin_lost);
314
315 // Called to retransmit outstanding portion in data [offset, offset +
renjietang4d992bf2020-03-03 13:01:55 -0800316 // data_length) and |fin| with Transmission |type|.
317 // Returns true if all data gets retransmitted.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500318 virtual bool RetransmitStreamData(QuicStreamOffset offset,
319 QuicByteCount data_length,
renjietang4d992bf2020-03-03 13:01:55 -0800320 bool fin,
321 TransmissionType type);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500322
323 // Sets deadline of this stream to be now + |ttl|, returns true if the setting
324 // succeeds.
325 bool MaybeSetTtl(QuicTime::Delta ttl);
326
327 // Same as WritevData except data is provided in reference counted memory so
328 // that data copy is avoided.
329 QuicConsumedData WriteMemSlices(QuicMemSliceSpan span, bool fin);
330
331 // Returns true if any stream data is lost (including fin) and needs to be
332 // retransmitted.
333 virtual bool HasPendingRetransmission() const;
334
335 // Returns true if any portion of data [offset, offset + data_length) is
336 // outstanding or fin is outstanding (if |fin| is true). Returns false
337 // otherwise.
338 bool IsStreamFrameOutstanding(QuicStreamOffset offset,
339 QuicByteCount data_length,
340 bool fin) const;
341
342 StreamType type() const { return type_; }
343
renjietanged49cb92020-03-03 14:30:53 -0800344 // Handle received StopSending frame. Returns true if the processing finishes
345 // gracefully.
346 virtual bool OnStopSending(uint16_t code);
renjietangd9762282019-11-11 17:11:18 -0800347
renjietangfbeb5bf2019-04-19 15:06:20 -0700348 // Returns true if the stream is static.
349 bool is_static() const { return is_static_; }
350
fayangbe6d6642020-04-16 14:15:34 -0700351 bool was_draining() const { return was_draining_; }
352
bnc5f202512020-02-01 18:43:02 -0800353 static spdy::SpdyStreamPrecedence CalculateDefaultPriority(
354 const QuicSession* session);
355
QUICHE teama6ef0a62019-03-07 20:34:33 -0500356 protected:
QUICHE teama6ef0a62019-03-07 20:34:33 -0500357 // Called when data of [offset, offset + data_length] is buffered in send
358 // buffer.
359 virtual void OnDataBuffered(
dschinazi17d42422019-06-18 16:35:07 -0700360 QuicStreamOffset /*offset*/,
361 QuicByteCount /*data_length*/,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500362 const QuicReferenceCountedPointer<QuicAckListenerInterface>&
dschinazi17d42422019-06-18 16:35:07 -0700363 /*ack_listener*/) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -0500364
fayangb8f83442020-06-01 12:09:17 -0700365 // Called just before the object is destroyed.
366 // The object should not be accessed after OnClose is called.
367 // Sends a RST_STREAM with code QUIC_RST_ACKNOWLEDGEMENT if neither a FIN nor
368 // a RST_STREAM has been sent.
369 virtual void OnClose();
370
QUICHE teama6ef0a62019-03-07 20:34:33 -0500371 // True if buffered data in send buffer is below buffered_data_threshold_.
372 bool CanWriteNewData() const;
373
374 // True if buffered data in send buffer is still below
375 // buffered_data_threshold_ even after writing |length| bytes.
376 bool CanWriteNewDataAfterData(QuicByteCount length) const;
377
378 // Called when upper layer can write new data.
379 virtual void OnCanWriteNewData() {}
380
381 // Called when |bytes_consumed| bytes has been consumed.
dschinazif1e7b422020-04-30 12:21:28 -0700382 virtual void OnStreamDataConsumed(QuicByteCount bytes_consumed);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500383
ianswett93637202019-04-03 08:05:29 -0700384 // Called by the stream sequencer as bytes are consumed from the buffer.
385 // If the receive window has dropped below the threshold, then send a
386 // WINDOW_UPDATE frame.
387 void AddBytesConsumed(QuicByteCount bytes) override;
388
QUICHE teama6ef0a62019-03-07 20:34:33 -0500389 // Writes pending retransmissions if any.
390 virtual void WritePendingRetransmission();
391
392 // This is called when stream tries to retransmit data after deadline_. Make
393 // this virtual so that subclasses can implement their own logics.
394 virtual void OnDeadlinePassed();
395
fayang3a51d1a2020-04-16 13:42:08 -0700396 // Called to set fin_sent_. This is only used by Google QUIC while body is
397 // empty.
398 void SetFinSent();
399
renjietangf00e1e12020-08-26 10:51:15 -0700400 // Close the write side of the socket. Further writes will fail.
401 // Can be called by the subclass or internally.
402 // Does not send a FIN. May cause the stream to be closed.
403 virtual void CloseWriteSide();
404
renjietangdf2240d2020-07-17 12:17:00 -0700405 void set_rst_received(bool rst_received) { rst_received_ = rst_received; }
406 void set_stream_error(QuicRstStreamErrorCode error) { stream_error_ = error; }
407
renjietangf196f6a2020-02-12 12:34:23 -0800408 StreamDelegateInterface* stream_delegate() { return stream_delegate_; }
409
QUICHE teama6ef0a62019-03-07 20:34:33 -0500410 bool fin_buffered() const { return fin_buffered_; }
411
412 const QuicSession* session() const { return session_; }
413 QuicSession* session() { return session_; }
414
415 const QuicStreamSequencer* sequencer() const { return &sequencer_; }
416 QuicStreamSequencer* sequencer() { return &sequencer_; }
417
418 void DisableConnectionFlowControlForThisStream() {
419 stream_contributes_to_connection_flow_control_ = false;
420 }
421
422 const QuicIntervalSet<QuicStreamOffset>& bytes_acked() const;
423
424 const QuicStreamSendBuffer& send_buffer() const { return send_buffer_; }
425
426 QuicStreamSendBuffer& send_buffer() { return send_buffer_; }
427
428 private:
429 friend class test::QuicStreamPeer;
430 friend class QuicStreamUtils;
431
432 QuicStream(QuicStreamId id,
433 QuicSession* session,
434 QuicStreamSequencer sequencer,
435 bool is_static,
436 StreamType type,
437 uint64_t stream_bytes_read,
438 bool fin_received,
dmcardle15db6882020-02-26 12:55:36 -0800439 quiche::QuicheOptional<QuicFlowController> flow_controller,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500440 QuicFlowController* connection_flow_controller);
441
QUICHE teama6ef0a62019-03-07 20:34:33 -0500442 // Calls MaybeSendBlocked on the stream's flow controller and the connection
443 // level flow controller. If the stream is flow control blocked by the
444 // connection-level flow controller but not by the stream-level flow
445 // controller, marks this stream as connection-level write blocked.
446 void MaybeSendBlocked();
447
448 // Write buffered data in send buffer. TODO(fayang): Consider combine
449 // WriteOrBufferData, Writev and WriteBufferedData.
450 void WriteBufferedData();
451
renjietangf00e1e12020-08-26 10:51:15 -0700452 // Close the read side of the stream. May cause the stream to be closed.
453 void CloseReadSide();
454
ianswett93637202019-04-03 08:05:29 -0700455 // Called when bytes are sent to the peer.
456 void AddBytesSent(QuicByteCount bytes);
457
QUICHE teama6ef0a62019-03-07 20:34:33 -0500458 // Returns true if deadline_ has passed.
459 bool HasDeadlinePassed() const;
460
461 QuicStreamSequencer sequencer_;
462 QuicStreamId id_;
463 // Pointer to the owning QuicSession object.
renjietangf196f6a2020-02-12 12:34:23 -0800464 // TODO(b/136274541): Remove session pointer from streams.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500465 QuicSession* session_;
renjietangf196f6a2020-02-12 12:34:23 -0800466 StreamDelegateInterface* stream_delegate_;
fayang476683a2019-07-25 12:42:16 -0700467 // The precedence of the stream, once parsed.
468 spdy::SpdyStreamPrecedence precedence_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500469 // Bytes read refers to payload bytes only: they do not include framing,
470 // encryption overhead etc.
471 uint64_t stream_bytes_read_;
472
473 // Stream error code received from a RstStreamFrame or error code sent by the
474 // visitor or sequencer in the RstStreamFrame.
475 QuicRstStreamErrorCode stream_error_;
476 // Connection error code due to which the stream was closed. |stream_error_|
477 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers
478 // should check |connection_error_|.
479 QuicErrorCode connection_error_;
480
481 // True if the read side is closed and further frames should be rejected.
482 bool read_side_closed_;
483 // True if the write side is closed, and further writes should fail.
484 bool write_side_closed_;
485
486 // True if the subclass has written a FIN with WriteOrBufferData, but it was
487 // buffered in queued_data_ rather than being sent to the session.
488 bool fin_buffered_;
489 // True if a FIN has been sent to the session.
490 bool fin_sent_;
491 // True if a FIN is waiting to be acked.
492 bool fin_outstanding_;
493 // True if a FIN is lost.
494 bool fin_lost_;
495
496 // True if this stream has received (and the sequencer has accepted) a
497 // StreamFrame with the FIN set.
498 bool fin_received_;
499
500 // True if an RST_STREAM has been sent to the session.
501 // In combination with fin_sent_, used to ensure that a FIN and/or a
502 // RST_STREAM is always sent to terminate the stream.
503 bool rst_sent_;
504
505 // True if this stream has received a RST_STREAM frame.
506 bool rst_received_;
507
dmcardle15db6882020-02-26 12:55:36 -0800508 quiche::QuicheOptional<QuicFlowController> flow_controller_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500509
510 // The connection level flow controller. Not owned.
511 QuicFlowController* connection_flow_controller_;
512
513 // Special streams, such as the crypto and headers streams, do not respect
514 // connection level flow control limits (but are stream level flow control
515 // limited).
516 bool stream_contributes_to_connection_flow_control_;
517
518 // A counter incremented when OnCanWrite() is called and no progress is made.
519 // For debugging only.
520 size_t busy_counter_;
521
522 // Indicates whether paddings will be added after the fin is consumed for this
523 // stream.
524 bool add_random_padding_after_fin_;
525
526 // Send buffer of this stream. Send buffer is cleaned up when data gets acked
527 // or discarded.
528 QuicStreamSendBuffer send_buffer_;
529
bnc5a401422019-06-18 04:32:32 -0700530 // Latched value of quic_buffered_data_threshold.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500531 const QuicByteCount buffered_data_threshold_;
532
533 // If true, then this stream has precedence over other streams for write
534 // scheduling.
535 const bool is_static_;
536
537 // If initialized, reset this stream at this deadline.
538 QuicTime deadline_;
539
fayang6dfe58d2020-06-01 08:02:47 -0700540 // True if this stream has entered draining state.
fayangbe6d6642020-04-16 14:15:34 -0700541 bool was_draining_;
542
QUICHE teama6ef0a62019-03-07 20:34:33 -0500543 // Indicates whether this stream is bidirectional, read unidirectional or
544 // write unidirectional.
545 const StreamType type_;
renjietangff3d3a32020-02-13 15:13:51 -0800546
547 Perspective perspective_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500548};
549
550} // namespace quic
551
552#endif // QUICHE_QUIC_CORE_QUIC_STREAM_H_