blob: 57bfedea7ba79e2e9b3c42c3873314f7f83f9ed8 [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"
nharperd5c4a932019-05-13 13:58:49 -070034#include "net/third_party/quiche/src/quic/platform/api/quic_optional.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050035#include "net/third_party/quiche/src/quic/platform/api/quic_reference_counted.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
renjietangbb1c4892019-05-24 15:58:44 -070079 void MarkConsumed(size_t num_bytes);
80
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:
116 // This is somewhat arbitrary. It's possible, but unlikely, we will either
117 // fail to set a priority client-side, or cancel a stream before stripping the
118 // priority from the wire server-side. In either case, start out with a
bnc5f202512020-02-01 18:43:02 -0800119 // priority in the middle in case of Google QUIC.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500120 static const spdy::SpdyPriority kDefaultPriority = 3;
121 static_assert(kDefaultPriority ==
122 (spdy::kV3LowestPriority + spdy::kV3HighestPriority) / 2,
123 "Unexpected value of kDefaultPriority");
bnc5f202512020-02-01 18:43:02 -0800124 // On the other hand, when using IETF QUIC, use the default value defined by
125 // the priority extension at
126 // https://httpwg.org/http-extensions/draft-ietf-httpbis-priority.html#default.
127 static const int kDefaultUrgency = 1;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500128
129 // Creates a new stream with stream_id |id| associated with |session|. If
130 // |is_static| is true, then the stream will be given precedence
131 // over other streams when determing what streams should write next.
132 // |type| indicates whether the stream is bidirectional, read unidirectional
133 // or write unidirectional.
134 // TODO(fayang): Remove |type| when IETF stream ID numbering fully kicks in.
135 QuicStream(QuicStreamId id,
136 QuicSession* session,
137 bool is_static,
138 StreamType type);
renjietangbaea59c2019-05-29 15:08:14 -0700139 QuicStream(PendingStream* pending, StreamType type, bool is_static);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500140 QuicStream(const QuicStream&) = delete;
141 QuicStream& operator=(const QuicStream&) = delete;
142
143 virtual ~QuicStream();
144
QUICHE teama6ef0a62019-03-07 20:34:33 -0500145 // QuicStreamSequencer::StreamInterface implementation.
146 QuicStreamId id() const override { return id_; }
147 // Called by the stream subclass after it has consumed the final incoming
148 // data.
149 void OnFinRead() override;
150
151 // Called by the subclass or the sequencer to reset the stream from this
152 // end.
153 void Reset(QuicRstStreamErrorCode error) override;
154
155 // Called by the subclass or the sequencer to close the entire connection from
156 // this end.
renjietang87df0d02020-02-13 11:53:52 -0800157 void OnUnrecoverableError(QuicErrorCode error,
158 const std::string& details) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500159
QUICHE teama6ef0a62019-03-07 20:34:33 -0500160 // Called by the session when a (potentially duplicate) stream frame has been
161 // received for this stream.
162 virtual void OnStreamFrame(const QuicStreamFrame& frame);
163
164 // Called by the session when the connection becomes writeable to allow the
165 // stream to write any pending data.
166 virtual void OnCanWrite();
167
168 // Called by the session just before the object is destroyed.
169 // The object should not be accessed after OnClose is called.
170 // Sends a RST_STREAM with code QUIC_RST_ACKNOWLEDGEMENT if neither a FIN nor
171 // a RST_STREAM has been sent.
172 virtual void OnClose();
173
174 // Called by the session when the endpoint receives a RST_STREAM from the
175 // peer.
176 virtual void OnStreamReset(const QuicRstStreamFrame& frame);
177
178 // Called by the session when the endpoint receives or sends a connection
179 // close, and should immediately close the stream.
180 virtual void OnConnectionClosed(QuicErrorCode error,
181 ConnectionCloseSource source);
182
fayang476683a2019-07-25 12:42:16 -0700183 const spdy::SpdyStreamPrecedence& precedence() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500184
bnccf09f952020-01-30 17:35:59 -0800185 // Send PRIORITY_UPDATE frame if application protocol supports it.
186 virtual void MaybeSendPriorityUpdateFrame() {}
187
188 // Sets |priority_| to priority. This should only be called before bytes are
189 // written to the server. For a server stream, this is called when a
190 // PRIORITY_UPDATE frame is received. This calls
191 // MaybeSendPriorityUpdateFrame(), which for a client stream might send a
192 // PRIORITY_UPDATE frame.
fayang476683a2019-07-25 12:42:16 -0700193 void SetPriority(const spdy::SpdyStreamPrecedence& precedence);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500194
195 // Returns true if this stream is still waiting for acks of sent data.
196 // This will return false if all data has been acked, or if the stream
197 // is no longer interested in data being acked (which happens when
198 // a stream is reset because of an error).
199 bool IsWaitingForAcks() const;
200
201 // Number of bytes available to read.
202 size_t ReadableBytes() const;
203
204 QuicRstStreamErrorCode stream_error() const { return stream_error_; }
205 QuicErrorCode connection_error() const { return connection_error_; }
206
207 bool reading_stopped() const {
208 return sequencer_.ignore_read_data() || read_side_closed_;
209 }
210 bool write_side_closed() const { return write_side_closed_; }
211
212 bool rst_received() const { return rst_received_; }
213 bool rst_sent() const { return rst_sent_; }
214 bool fin_received() const { return fin_received_; }
215 bool fin_sent() const { return fin_sent_; }
216 bool fin_outstanding() const { return fin_outstanding_; }
217 bool fin_lost() const { return fin_lost_; }
218
219 uint64_t BufferedDataBytes() const;
220
221 uint64_t stream_bytes_read() const { return stream_bytes_read_; }
222 uint64_t stream_bytes_written() const;
223
224 size_t busy_counter() const { return busy_counter_; }
225 void set_busy_counter(size_t busy_counter) { busy_counter_ = busy_counter; }
226
227 void set_fin_sent(bool fin_sent) { fin_sent_ = fin_sent; }
228 void set_fin_received(bool fin_received) { fin_received_ = fin_received; }
229 void set_rst_sent(bool rst_sent) { rst_sent_ = rst_sent; }
230
231 void set_rst_received(bool rst_received) { rst_received_ = rst_received; }
232 void set_stream_error(QuicRstStreamErrorCode error) { stream_error_ = error; }
233
234 // Adjust the flow control window according to new offset in |frame|.
235 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame);
236
237 int num_frames_received() const;
238 int num_duplicate_frames_received() const;
239
nharperd5c4a932019-05-13 13:58:49 -0700240 QuicFlowController* flow_controller() { return &*flow_controller_; }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500241
242 // Called when endpoint receives a frame which could increase the highest
243 // offset.
244 // Returns true if the highest offset did increase.
245 bool MaybeIncreaseHighestReceivedOffset(QuicStreamOffset new_offset);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500246
247 // Updates the flow controller's send window offset and calls OnCanWrite if
248 // it was blocked before.
249 void UpdateSendWindowOffset(QuicStreamOffset new_offset);
250
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 +
316 // data_length) and |fin|. Returns true if all data gets retransmitted.
317 virtual bool RetransmitStreamData(QuicStreamOffset offset,
318 QuicByteCount data_length,
319 bool fin);
320
321 // Sets deadline of this stream to be now + |ttl|, returns true if the setting
322 // succeeds.
323 bool MaybeSetTtl(QuicTime::Delta ttl);
324
325 // Same as WritevData except data is provided in reference counted memory so
326 // that data copy is avoided.
327 QuicConsumedData WriteMemSlices(QuicMemSliceSpan span, bool fin);
328
329 // Returns true if any stream data is lost (including fin) and needs to be
330 // retransmitted.
331 virtual bool HasPendingRetransmission() const;
332
333 // Returns true if any portion of data [offset, offset + data_length) is
334 // outstanding or fin is outstanding (if |fin| is true). Returns false
335 // otherwise.
336 bool IsStreamFrameOutstanding(QuicStreamOffset offset,
337 QuicByteCount data_length,
338 bool fin) const;
339
340 StreamType type() const { return type_; }
341
342 // Creates and sends a STOP_SENDING frame. This can be called regardless of
343 // the version that has been negotiated. If not IETF QUIC/Version 99 then the
344 // method is a noop, relieving the application of the necessity of
345 // understanding the connection's QUIC version and knowing whether it can call
346 // this method or not.
347 void SendStopSending(uint16_t code);
348
renjietangd9762282019-11-11 17:11:18 -0800349 // Handle received StopSending frame.
350 virtual void OnStopSending(uint16_t /*code*/) {}
351
QUICHE teama6ef0a62019-03-07 20:34:33 -0500352 // Close the write side of the socket. Further writes will fail.
353 // Can be called by the subclass or internally.
354 // Does not send a FIN. May cause the stream to be closed.
355 virtual void CloseWriteSide();
356
renjietangfbeb5bf2019-04-19 15:06:20 -0700357 // Returns true if the stream is static.
358 bool is_static() const { return is_static_; }
359
bnc5f202512020-02-01 18:43:02 -0800360 static spdy::SpdyStreamPrecedence CalculateDefaultPriority(
361 const QuicSession* session);
362
QUICHE teama6ef0a62019-03-07 20:34:33 -0500363 protected:
QUICHE teama6ef0a62019-03-07 20:34:33 -0500364 // Close the read side of the socket. May cause the stream to be closed.
365 // Subclasses and consumers should use StopReading to terminate reading early
366 // if expecting a FIN. Can be used directly by subclasses if not expecting a
367 // FIN.
368 void CloseReadSide();
369
370 // Called when data of [offset, offset + data_length] is buffered in send
371 // buffer.
372 virtual void OnDataBuffered(
dschinazi17d42422019-06-18 16:35:07 -0700373 QuicStreamOffset /*offset*/,
374 QuicByteCount /*data_length*/,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500375 const QuicReferenceCountedPointer<QuicAckListenerInterface>&
dschinazi17d42422019-06-18 16:35:07 -0700376 /*ack_listener*/) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -0500377
378 // True if buffered data in send buffer is below buffered_data_threshold_.
379 bool CanWriteNewData() const;
380
381 // True if buffered data in send buffer is still below
382 // buffered_data_threshold_ even after writing |length| bytes.
383 bool CanWriteNewDataAfterData(QuicByteCount length) const;
384
385 // Called when upper layer can write new data.
386 virtual void OnCanWriteNewData() {}
387
388 // Called when |bytes_consumed| bytes has been consumed.
389 virtual void OnStreamDataConsumed(size_t bytes_consumed);
390
ianswett93637202019-04-03 08:05:29 -0700391 // Called by the stream sequencer as bytes are consumed from the buffer.
392 // If the receive window has dropped below the threshold, then send a
393 // WINDOW_UPDATE frame.
394 void AddBytesConsumed(QuicByteCount bytes) override;
395
QUICHE teama6ef0a62019-03-07 20:34:33 -0500396 // Writes pending retransmissions if any.
397 virtual void WritePendingRetransmission();
398
399 // This is called when stream tries to retransmit data after deadline_. Make
400 // this virtual so that subclasses can implement their own logics.
401 virtual void OnDeadlinePassed();
402
renjietangf196f6a2020-02-12 12:34:23 -0800403 StreamDelegateInterface* stream_delegate() { return stream_delegate_; }
404
QUICHE teama6ef0a62019-03-07 20:34:33 -0500405 bool fin_buffered() const { return fin_buffered_; }
406
407 const QuicSession* session() const { return session_; }
408 QuicSession* session() { return session_; }
409
410 const QuicStreamSequencer* sequencer() const { return &sequencer_; }
411 QuicStreamSequencer* sequencer() { return &sequencer_; }
412
413 void DisableConnectionFlowControlForThisStream() {
414 stream_contributes_to_connection_flow_control_ = false;
415 }
416
417 const QuicIntervalSet<QuicStreamOffset>& bytes_acked() const;
418
419 const QuicStreamSendBuffer& send_buffer() const { return send_buffer_; }
420
421 QuicStreamSendBuffer& send_buffer() { return send_buffer_; }
422
423 private:
424 friend class test::QuicStreamPeer;
425 friend class QuicStreamUtils;
426
427 QuicStream(QuicStreamId id,
428 QuicSession* session,
429 QuicStreamSequencer sequencer,
430 bool is_static,
431 StreamType type,
432 uint64_t stream_bytes_read,
433 bool fin_received,
nharperd5c4a932019-05-13 13:58:49 -0700434 QuicOptional<QuicFlowController> flow_controller,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500435 QuicFlowController* connection_flow_controller);
436
QUICHE teama6ef0a62019-03-07 20:34:33 -0500437 // Calls MaybeSendBlocked on the stream's flow controller and the connection
438 // level flow controller. If the stream is flow control blocked by the
439 // connection-level flow controller but not by the stream-level flow
440 // controller, marks this stream as connection-level write blocked.
441 void MaybeSendBlocked();
442
443 // Write buffered data in send buffer. TODO(fayang): Consider combine
444 // WriteOrBufferData, Writev and WriteBufferedData.
445 void WriteBufferedData();
446
ianswett93637202019-04-03 08:05:29 -0700447 // Called when bytes are sent to the peer.
448 void AddBytesSent(QuicByteCount bytes);
449
QUICHE teama6ef0a62019-03-07 20:34:33 -0500450 // Returns true if deadline_ has passed.
451 bool HasDeadlinePassed() const;
452
453 QuicStreamSequencer sequencer_;
454 QuicStreamId id_;
455 // Pointer to the owning QuicSession object.
renjietangf196f6a2020-02-12 12:34:23 -0800456 // TODO(b/136274541): Remove session pointer from streams.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500457 QuicSession* session_;
renjietangf196f6a2020-02-12 12:34:23 -0800458 StreamDelegateInterface* stream_delegate_;
fayang476683a2019-07-25 12:42:16 -0700459 // The precedence of the stream, once parsed.
460 spdy::SpdyStreamPrecedence precedence_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500461 // Bytes read refers to payload bytes only: they do not include framing,
462 // encryption overhead etc.
463 uint64_t stream_bytes_read_;
464
465 // Stream error code received from a RstStreamFrame or error code sent by the
466 // visitor or sequencer in the RstStreamFrame.
467 QuicRstStreamErrorCode stream_error_;
468 // Connection error code due to which the stream was closed. |stream_error_|
469 // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers
470 // should check |connection_error_|.
471 QuicErrorCode connection_error_;
472
473 // True if the read side is closed and further frames should be rejected.
474 bool read_side_closed_;
475 // True if the write side is closed, and further writes should fail.
476 bool write_side_closed_;
477
478 // True if the subclass has written a FIN with WriteOrBufferData, but it was
479 // buffered in queued_data_ rather than being sent to the session.
480 bool fin_buffered_;
481 // True if a FIN has been sent to the session.
482 bool fin_sent_;
483 // True if a FIN is waiting to be acked.
484 bool fin_outstanding_;
485 // True if a FIN is lost.
486 bool fin_lost_;
487
488 // True if this stream has received (and the sequencer has accepted) a
489 // StreamFrame with the FIN set.
490 bool fin_received_;
491
492 // True if an RST_STREAM has been sent to the session.
493 // In combination with fin_sent_, used to ensure that a FIN and/or a
494 // RST_STREAM is always sent to terminate the stream.
495 bool rst_sent_;
496
497 // True if this stream has received a RST_STREAM frame.
498 bool rst_received_;
499
nharperd5c4a932019-05-13 13:58:49 -0700500 QuicOptional<QuicFlowController> flow_controller_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500501
502 // The connection level flow controller. Not owned.
503 QuicFlowController* connection_flow_controller_;
504
505 // Special streams, such as the crypto and headers streams, do not respect
506 // connection level flow control limits (but are stream level flow control
507 // limited).
508 bool stream_contributes_to_connection_flow_control_;
509
510 // A counter incremented when OnCanWrite() is called and no progress is made.
511 // For debugging only.
512 size_t busy_counter_;
513
514 // Indicates whether paddings will be added after the fin is consumed for this
515 // stream.
516 bool add_random_padding_after_fin_;
517
518 // Send buffer of this stream. Send buffer is cleaned up when data gets acked
519 // or discarded.
520 QuicStreamSendBuffer send_buffer_;
521
bnc5a401422019-06-18 04:32:32 -0700522 // Latched value of quic_buffered_data_threshold.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500523 const QuicByteCount buffered_data_threshold_;
524
525 // If true, then this stream has precedence over other streams for write
526 // scheduling.
527 const bool is_static_;
528
529 // If initialized, reset this stream at this deadline.
530 QuicTime deadline_;
531
532 // Indicates whether this stream is bidirectional, read unidirectional or
533 // write unidirectional.
534 const StreamType type_;
renjietangff3d3a32020-02-13 15:13:51 -0800535
536 Perspective perspective_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500537};
538
539} // namespace quic
540
541#endif // QUICHE_QUIC_CORE_QUIC_STREAM_H_