xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_stream.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // 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>
23 #include <optional>
24 #include <string>
25 
26 #include "absl/strings/string_view.h"
27 #include "absl/types/span.h"
28 #include "quiche/quic/core/frames/quic_rst_stream_frame.h"
29 #include "quiche/quic/core/quic_error_codes.h"
30 #include "quiche/quic/core/quic_flow_controller.h"
31 #include "quiche/quic/core/quic_packets.h"
32 #include "quiche/quic/core/quic_stream_priority.h"
33 #include "quiche/quic/core/quic_stream_send_buffer.h"
34 #include "quiche/quic/core/quic_stream_sequencer.h"
35 #include "quiche/quic/core/quic_types.h"
36 #include "quiche/quic/core/session_notifier_interface.h"
37 #include "quiche/quic/core/stream_delegate_interface.h"
38 #include "quiche/quic/platform/api/quic_export.h"
39 #include "quiche/common/platform/api/quiche_mem_slice.h"
40 #include "quiche/common/platform/api/quiche_reference_counted.h"
41 #include "quiche/spdy/core/spdy_protocol.h"
42 
43 namespace quic {
44 
45 namespace test {
46 class QuicStreamPeer;
47 }  // namespace test
48 
49 class QuicSession;
50 class QuicStream;
51 
52 // Buffers frames for a stream until the first byte of that frame arrives.
53 class QUICHE_EXPORT PendingStream
54     : public QuicStreamSequencer::StreamInterface {
55  public:
56   PendingStream(QuicStreamId id, QuicSession* session);
57   PendingStream(const PendingStream&) = delete;
58   PendingStream(PendingStream&&) = default;
59   ~PendingStream() override = default;
60 
61   // QuicStreamSequencer::StreamInterface
62   void OnDataAvailable() override;
63   void OnFinRead() override;
64   void AddBytesConsumed(QuicByteCount bytes) override;
65   void ResetWithError(QuicResetStreamError error) override;
66   void OnUnrecoverableError(QuicErrorCode error,
67                             const std::string& details) override;
68   void OnUnrecoverableError(QuicErrorCode error,
69                             QuicIetfTransportErrorCodes ietf_error,
70                             const std::string& details) override;
71   QuicStreamId id() const override;
72   ParsedQuicVersion version() const override;
73 
74   // Buffers the contents of |frame|. Frame must have a non-zero offset.
75   // If the data violates flow control, the connection will be closed.
76   void OnStreamFrame(const QuicStreamFrame& frame);
77 
is_bidirectional()78   bool is_bidirectional() const { return is_bidirectional_; }
79 
80   // Stores the final byte offset from |frame|.
81   // If the final offset violates flow control, the connection will be closed.
82   void OnRstStreamFrame(const QuicRstStreamFrame& frame);
83 
84   void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame);
85 
86   void OnStopSending(QuicResetStreamError stop_sending_error_code);
87 
88   // The error code received from QuicStopSendingFrame (if any).
GetStopSendingErrorCode()89   const std::optional<QuicResetStreamError>& GetStopSendingErrorCode() const {
90     return stop_sending_error_code_;
91   }
92 
93   // Returns the number of bytes read on this stream.
stream_bytes_read()94   uint64_t stream_bytes_read() { return stream_bytes_read_; }
95 
sequencer()96   const QuicStreamSequencer* sequencer() const { return &sequencer_; }
97 
98   void MarkConsumed(QuicByteCount num_bytes);
99 
100   // Tells the sequencer to ignore all incoming data itself and not call
101   // OnDataAvailable().
102   void StopReading();
103 
creation_time()104   QuicTime creation_time() const { return creation_time_; }
105 
106  private:
107   friend class QuicStream;
108 
109   bool MaybeIncreaseHighestReceivedOffset(QuicStreamOffset new_offset);
110 
111   // ID of this stream.
112   QuicStreamId id_;
113 
114   // QUIC version being used by this stream.
115   ParsedQuicVersion version_;
116 
117   // |stream_delegate_| must outlive this stream.
118   StreamDelegateInterface* stream_delegate_;
119 
120   // Bytes read refers to payload bytes only: they do not include framing,
121   // encryption overhead etc.
122   uint64_t stream_bytes_read_;
123 
124   // True if a frame containing a fin has been received.
125   bool fin_received_;
126 
127   // True if this pending stream is backing a bidirectional stream.
128   bool is_bidirectional_;
129 
130   // Connection-level flow controller. Owned by the session.
131   QuicFlowController* connection_flow_controller_;
132   // Stream-level flow controller.
133   QuicFlowController flow_controller_;
134   // Stores the buffered frames.
135   QuicStreamSequencer sequencer_;
136   // The error code received from QuicStopSendingFrame (if any).
137   std::optional<QuicResetStreamError> stop_sending_error_code_;
138   // The time when this pending stream is created.
139   const QuicTime creation_time_;
140 };
141 
142 class QUICHE_EXPORT QuicStream : public QuicStreamSequencer::StreamInterface {
143  public:
144   // Creates a new stream with stream_id |id| associated with |session|. If
145   // |is_static| is true, then the stream will be given precedence
146   // over other streams when determing what streams should write next.
147   // |type| indicates whether the stream is bidirectional, read unidirectional
148   // or write unidirectional.
149   // TODO(fayang): Remove |type| when IETF stream ID numbering fully kicks in.
150   QuicStream(QuicStreamId id, QuicSession* session, bool is_static,
151              StreamType type);
152   QuicStream(PendingStream* pending, QuicSession* session, bool is_static);
153   QuicStream(const QuicStream&) = delete;
154   QuicStream& operator=(const QuicStream&) = delete;
155 
156   virtual ~QuicStream();
157 
158   // QuicStreamSequencer::StreamInterface implementation.
id()159   QuicStreamId id() const override { return id_; }
160   ParsedQuicVersion version() const override;
161   // Called by the stream subclass after it has consumed the final incoming
162   // data.
163   void OnFinRead() override;
164 
165   // Called by the subclass or the sequencer to reset the stream from this
166   // end.
167   void ResetWithError(QuicResetStreamError error) override;
168   // Convenience wrapper for the method above.
169   // TODO(b/200606367): switch all calls to using QuicResetStreamError
170   // interface.
171   void Reset(QuicRstStreamErrorCode error);
172 
173   // Reset() sends both RESET_STREAM and STOP_SENDING; the two methods below
174   // allow to send only one of those.
175   void ResetWriteSide(QuicResetStreamError error);
176   void SendStopSending(QuicResetStreamError error);
177 
178   // Called by the subclass or the sequencer to close the entire connection from
179   // this end.
180   void OnUnrecoverableError(QuicErrorCode error,
181                             const std::string& details) override;
182   void OnUnrecoverableError(QuicErrorCode error,
183                             QuicIetfTransportErrorCodes ietf_error,
184                             const std::string& details) override;
185 
186   // Called by the session when a (potentially duplicate) stream frame has been
187   // received for this stream.
188   virtual void OnStreamFrame(const QuicStreamFrame& frame);
189 
190   // Called by the session when the connection becomes writeable to allow the
191   // stream to write any pending data.
192   virtual void OnCanWrite();
193 
194   // Called by the session when the endpoint receives a RST_STREAM from the
195   // peer.
196   virtual void OnStreamReset(const QuicRstStreamFrame& frame);
197 
198   // Called by the session when the endpoint receives or sends a connection
199   // close, and should immediately close the stream.
200   virtual void OnConnectionClosed(QuicErrorCode error,
201                                   ConnectionCloseSource source);
202 
203   const QuicStreamPriority& priority() const;
204 
205   // Send PRIORITY_UPDATE frame if application protocol supports it.
MaybeSendPriorityUpdateFrame()206   virtual void MaybeSendPriorityUpdateFrame() {}
207 
208   // Sets |priority_| to priority.  This should only be called before bytes are
209   // written to the server.  For a server stream, this is called when a
210   // PRIORITY_UPDATE frame is received.  This calls
211   // MaybeSendPriorityUpdateFrame(), which for a client stream might send a
212   // PRIORITY_UPDATE frame.
213   void SetPriority(const QuicStreamPriority& priority);
214 
215   // Returns true if this stream is still waiting for acks of sent data.
216   // This will return false if all data has been acked, or if the stream
217   // is no longer interested in data being acked (which happens when
218   // a stream is reset because of an error).
219   bool IsWaitingForAcks() const;
220 
stream_error()221   QuicRstStreamErrorCode stream_error() const {
222     return stream_error_.internal_code();
223   }
224   // Application error code of RESET_STREAM.
ietf_application_error()225   uint64_t ietf_application_error() const {
226     return stream_error_.ietf_application_code();
227   }
connection_error()228   QuicErrorCode connection_error() const { return connection_error_; }
229 
reading_stopped()230   bool reading_stopped() const {
231     return sequencer_.ignore_read_data() || read_side_closed_;
232   }
write_side_closed()233   bool write_side_closed() const { return write_side_closed_; }
read_side_closed()234   bool read_side_closed() const { return read_side_closed_; }
235 
IsZombie()236   bool IsZombie() const {
237     return read_side_closed_ && write_side_closed_ && IsWaitingForAcks();
238   }
239 
rst_received()240   bool rst_received() const { return rst_received_; }
rst_sent()241   bool rst_sent() const { return rst_sent_; }
fin_received()242   bool fin_received() const { return fin_received_; }
fin_sent()243   bool fin_sent() const { return fin_sent_; }
fin_outstanding()244   bool fin_outstanding() const { return fin_outstanding_; }
fin_lost()245   bool fin_lost() const { return fin_lost_; }
246 
247   uint64_t BufferedDataBytes() const;
248 
stream_bytes_read()249   uint64_t stream_bytes_read() const { return stream_bytes_read_; }
250   uint64_t stream_bytes_written() const;
251 
busy_counter()252   size_t busy_counter() const { return busy_counter_; }
set_busy_counter(size_t busy_counter)253   void set_busy_counter(size_t busy_counter) { busy_counter_ = busy_counter; }
254 
255   // Adjust the flow control window according to new offset in |frame|.
256   virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame);
257 
258   int num_frames_received() const;
259   int num_duplicate_frames_received() const;
260 
261   // Flow controller related methods.
262   bool IsFlowControlBlocked() const;
263   QuicStreamOffset highest_received_byte_offset() const;
264   void UpdateReceiveWindowSize(QuicStreamOffset size);
265 
266   // Called when endpoint receives a frame which could increase the highest
267   // offset.
268   // Returns true if the highest offset did increase.
269   bool MaybeIncreaseHighestReceivedOffset(QuicStreamOffset new_offset);
270 
271   // Set the flow controller's send window offset from session config.
272   // |was_zero_rtt_rejected| is true if this config is from a rejected IETF QUIC
273   // 0-RTT attempt. Closes the connection and returns false if |new_offset| is
274   // not valid.
275   bool MaybeConfigSendWindowOffset(QuicStreamOffset new_offset,
276                                    bool was_zero_rtt_rejected);
277 
278   // Returns true if the stream has received either a RST_STREAM or a FIN -
279   // either of which gives a definitive number of bytes which the peer has
280   // sent. If this is not true on deletion of the stream object, the session
281   // must keep track of the stream's byte offset until a definitive final value
282   // arrives.
HasReceivedFinalOffset()283   bool HasReceivedFinalOffset() const { return fin_received_ || rst_received_; }
284 
285   // Returns true if the stream has queued data waiting to write.
286   bool HasBufferedData() const;
287 
288   // Returns the version of QUIC being used for this stream.
289   QuicTransportVersion transport_version() const;
290 
291   // Returns the crypto handshake protocol that was used on this stream's
292   // connection.
293   HandshakeProtocol handshake_protocol() const;
294 
295   // Sets the sequencer to consume all incoming data itself and not call
296   // OnDataAvailable().
297   // When the FIN is received, the stream will be notified automatically (via
298   // OnFinRead()) (which may happen during the call of StopReading()).
299   // TODO(dworley): There should be machinery to send a RST_STREAM/NO_ERROR and
300   // stop sending stream-level flow-control updates when this end sends FIN.
301   virtual void StopReading();
302 
303   // Sends as much of |data| to the connection on the application encryption
304   // level as the connection will consume, and then buffers any remaining data
305   // in the send buffer. If fin is true: if it is immediately passed on to the
306   // session, write_side_closed() becomes true, otherwise fin_buffered_ becomes
307   // true.
308   void WriteOrBufferData(
309       absl::string_view data, bool fin,
310       quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface>
311           ack_listener);
312 
313   // Sends |data| to connection with specified |level|.
314   void WriteOrBufferDataAtLevel(
315       absl::string_view data, bool fin, EncryptionLevel level,
316       quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface>
317           ack_listener);
318 
319   // Adds random padding after the fin is consumed for this stream.
320   void AddRandomPaddingAfterFin();
321 
322   // Write |data_length| of data starts at |offset| from send buffer.
323   bool WriteStreamData(QuicStreamOffset offset, QuicByteCount data_length,
324                        QuicDataWriter* writer);
325 
326   // Called when data [offset, offset + data_length) is acked. |fin_acked|
327   // indicates whether the fin is acked. Returns true and updates
328   // |newly_acked_length| if any new stream data (including fin) gets acked.
329   virtual bool OnStreamFrameAcked(QuicStreamOffset offset,
330                                   QuicByteCount data_length, bool fin_acked,
331                                   QuicTime::Delta ack_delay_time,
332                                   QuicTime receive_timestamp,
333                                   QuicByteCount* newly_acked_length);
334 
335   // Called when data [offset, offset + data_length) was retransmitted.
336   // |fin_retransmitted| indicates whether fin was retransmitted.
337   virtual void OnStreamFrameRetransmitted(QuicStreamOffset offset,
338                                           QuicByteCount data_length,
339                                           bool fin_retransmitted);
340 
341   // Called when data [offset, offset + data_length) is considered as lost.
342   // |fin_lost| indicates whether the fin is considered as lost.
343   virtual void OnStreamFrameLost(QuicStreamOffset offset,
344                                  QuicByteCount data_length, bool fin_lost);
345 
346   // Called to retransmit outstanding portion in data [offset, offset +
347   // data_length) and |fin| with Transmission |type|.
348   // Returns true if all data gets retransmitted.
349   virtual bool RetransmitStreamData(QuicStreamOffset offset,
350                                     QuicByteCount data_length, bool fin,
351                                     TransmissionType type);
352 
353   // Sets deadline of this stream to be now + |ttl|, returns true if the setting
354   // succeeds.
355   bool MaybeSetTtl(QuicTime::Delta ttl);
356 
357   // Commits data into the stream write buffer, and potentially sends it over
358   // the wire.  This method has all-or-nothing semantics: if the write buffer is
359   // not full, all of the memslices in |span| are moved into it; otherwise,
360   // nothing happens. If `buffer_unconditionally` is set to true, behaves
361   // similar to `WriteOrBufferData()` in terms of buffering.
362   QuicConsumedData WriteMemSlices(absl::Span<quiche::QuicheMemSlice> span,
363                                   bool fin, bool buffer_uncondtionally = false);
364   QuicConsumedData WriteMemSlice(quiche::QuicheMemSlice span, bool fin);
365 
366   // Returns true if any stream data is lost (including fin) and needs to be
367   // retransmitted.
368   virtual bool HasPendingRetransmission() const;
369 
370   // Returns true if any portion of data [offset, offset + data_length) is
371   // outstanding or fin is outstanding (if |fin| is true). Returns false
372   // otherwise.
373   bool IsStreamFrameOutstanding(QuicStreamOffset offset,
374                                 QuicByteCount data_length, bool fin) const;
375 
type()376   StreamType type() const { return type_; }
377 
378   // Handle received StopSending frame. Returns true if the processing finishes
379   // gracefully.
380   virtual bool OnStopSending(QuicResetStreamError error);
381 
382   // Returns true if the stream is static.
is_static()383   bool is_static() const { return is_static_; }
384 
was_draining()385   bool was_draining() const { return was_draining_; }
386 
creation_time()387   QuicTime creation_time() const { return creation_time_; }
388 
fin_buffered()389   bool fin_buffered() const { return fin_buffered_; }
390 
391   // True if buffered data in send buffer is below buffered_data_threshold_.
392   bool CanWriteNewData() const;
393 
394   // Called immediately after the stream is created from a pending stream,
395   // indicating it can start processing data.
396   void OnStreamCreatedFromPendingStream();
397 
DisableConnectionFlowControlForThisStream()398   void DisableConnectionFlowControlForThisStream() {
399     stream_contributes_to_connection_flow_control_ = false;
400   }
401 
402   // Returns the min of stream level flow control window size and connection
403   // level flow control window size.
404   QuicByteCount CalculateSendWindowSize() const;
405 
pending_duration()406   const QuicTime::Delta pending_duration() const { return pending_duration_; }
407 
408  protected:
409   // Called when data of [offset, offset + data_length] is buffered in send
410   // buffer.
OnDataBuffered(QuicStreamOffset,QuicByteCount,const quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface> &)411   virtual void OnDataBuffered(
412       QuicStreamOffset /*offset*/, QuicByteCount /*data_length*/,
413       const quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface>&
414       /*ack_listener*/) {}
415 
416   // Called just before the object is destroyed.
417   // The object should not be accessed after OnClose is called.
418   // Sends a RST_STREAM with code QUIC_RST_ACKNOWLEDGEMENT if neither a FIN nor
419   // a RST_STREAM has been sent.
420   virtual void OnClose();
421 
422   // True if buffered data in send buffer is still below
423   // buffered_data_threshold_ even after writing |length| bytes.
424   bool CanWriteNewDataAfterData(QuicByteCount length) const;
425 
426   // Called when upper layer can write new data.
OnCanWriteNewData()427   virtual void OnCanWriteNewData() {}
428 
429   // Called when |bytes_consumed| bytes has been consumed.
430   virtual void OnStreamDataConsumed(QuicByteCount bytes_consumed);
431 
432   // Called by the stream sequencer as bytes are consumed from the buffer.
433   // If the receive window has dropped below the threshold, then send a
434   // WINDOW_UPDATE frame.
435   void AddBytesConsumed(QuicByteCount bytes) override;
436 
437   // Writes pending retransmissions if any.
438   virtual void WritePendingRetransmission();
439 
440   // This is called when stream tries to retransmit data after deadline_. Make
441   // this virtual so that subclasses can implement their own logics.
442   virtual void OnDeadlinePassed();
443 
444   // Called to set fin_sent_. This is only used by Google QUIC while body is
445   // empty.
446   void SetFinSent();
447 
448   // Send STOP_SENDING if it hasn't been sent yet.
449   void MaybeSendStopSending(QuicResetStreamError error);
450 
451   // Send RESET_STREAM if it hasn't been sent yet.
452   void MaybeSendRstStream(QuicResetStreamError error);
453 
454   // Convenience wrappers for two methods above.
MaybeSendRstStream(QuicRstStreamErrorCode error)455   void MaybeSendRstStream(QuicRstStreamErrorCode error) {
456     MaybeSendRstStream(QuicResetStreamError::FromInternal(error));
457   }
MaybeSendStopSending(QuicRstStreamErrorCode error)458   void MaybeSendStopSending(QuicRstStreamErrorCode error) {
459     MaybeSendStopSending(QuicResetStreamError::FromInternal(error));
460   }
461 
462   // Close the read side of the stream.  May cause the stream to be closed.
463   virtual void CloseReadSide();
464 
465   // Close the write side of the socket.  Further writes will fail.
466   // Can be called by the subclass or internally.
467   // Does not send a FIN.  May cause the stream to be closed.
468   virtual void CloseWriteSide();
469 
set_rst_received(bool rst_received)470   void set_rst_received(bool rst_received) { rst_received_ = rst_received; }
set_stream_error(QuicResetStreamError error)471   void set_stream_error(QuicResetStreamError error) { stream_error_ = error; }
472 
stream_delegate()473   StreamDelegateInterface* stream_delegate() { return stream_delegate_; }
474 
session()475   const QuicSession* session() const { return session_; }
session()476   QuicSession* session() { return session_; }
477 
sequencer()478   const QuicStreamSequencer* sequencer() const { return &sequencer_; }
sequencer()479   QuicStreamSequencer* sequencer() { return &sequencer_; }
480 
481   const QuicIntervalSet<QuicStreamOffset>& bytes_acked() const;
482 
send_buffer()483   const QuicStreamSendBuffer& send_buffer() const { return send_buffer_; }
484 
send_buffer()485   QuicStreamSendBuffer& send_buffer() { return send_buffer_; }
486 
487   // Called when the write side of the stream is closed, and all of the outgoing
488   // data has been acknowledged.  This corresponds to the "Data Recvd" state of
489   // RFC 9000.
OnWriteSideInDataRecvdState()490   virtual void OnWriteSideInDataRecvdState() {}
491 
492   // Return the current stream-level flow control send window in bytes.
493   std::optional<QuicByteCount> GetSendWindow() const;
494   std::optional<QuicByteCount> GetReceiveWindow() const;
495 
496  private:
497   friend class test::QuicStreamPeer;
498   friend class QuicStreamUtils;
499 
500   QuicStream(QuicStreamId id, QuicSession* session,
501              QuicStreamSequencer sequencer, bool is_static, StreamType type,
502              uint64_t stream_bytes_read, bool fin_received,
503              std::optional<QuicFlowController> flow_controller,
504              QuicFlowController* connection_flow_controller,
505              QuicTime::Delta pending_duration);
506 
507   // Calls MaybeSendBlocked on the stream's flow controller and the connection
508   // level flow controller.  If the stream is flow control blocked by the
509   // connection-level flow controller but not by the stream-level flow
510   // controller, marks this stream as connection-level write blocked.
511   void MaybeSendBlocked();
512 
513   // Write buffered data (in send buffer) at |level|.
514   void WriteBufferedData(EncryptionLevel level);
515 
516   // Called when bytes are sent to the peer.
517   void AddBytesSent(QuicByteCount bytes);
518 
519   // Returns true if deadline_ has passed.
520   bool HasDeadlinePassed() const;
521 
522   QuicStreamSequencer sequencer_;
523   QuicStreamId id_;
524   // Pointer to the owning QuicSession object.
525   // TODO(b/136274541): Remove session pointer from streams.
526   QuicSession* session_;
527   StreamDelegateInterface* stream_delegate_;
528   // The priority of the stream, once parsed.
529   QuicStreamPriority priority_;
530   // Bytes read refers to payload bytes only: they do not include framing,
531   // encryption overhead etc.
532   uint64_t stream_bytes_read_;
533 
534   // Stream error code received from a RstStreamFrame or error code sent by the
535   // visitor or sequencer in the RstStreamFrame.
536   QuicResetStreamError stream_error_;
537   // Connection error code due to which the stream was closed. |stream_error_|
538   // is set to |QUIC_STREAM_CONNECTION_ERROR| when this happens and consumers
539   // should check |connection_error_|.
540   QuicErrorCode connection_error_;
541 
542   // True if the read side is closed and further frames should be rejected.
543   bool read_side_closed_;
544   // True if the write side is closed, and further writes should fail.
545   bool write_side_closed_;
546 
547   // True if OnWriteSideInDataRecvdState() has already been called.
548   bool write_side_data_recvd_state_notified_;
549 
550   // True if the subclass has written a FIN with WriteOrBufferData, but it was
551   // buffered in queued_data_ rather than being sent to the session.
552   bool fin_buffered_;
553   // True if a FIN has been sent to the session.
554   bool fin_sent_;
555   // True if a FIN is waiting to be acked.
556   bool fin_outstanding_;
557   // True if a FIN is lost.
558   bool fin_lost_;
559 
560   // True if this stream has received (and the sequencer has accepted) a
561   // StreamFrame with the FIN set.
562   bool fin_received_;
563 
564   // True if an RST_STREAM has been sent to the session.
565   // In combination with fin_sent_, used to ensure that a FIN and/or a
566   // RST_STREAM is always sent to terminate the stream.
567   bool rst_sent_;
568 
569   // True if this stream has received a RST_STREAM frame.
570   bool rst_received_;
571 
572   // True if the stream has sent STOP_SENDING to the session.
573   bool stop_sending_sent_;
574 
575   std::optional<QuicFlowController> flow_controller_;
576 
577   // The connection level flow controller. Not owned.
578   QuicFlowController* connection_flow_controller_;
579 
580   // Special streams, such as the crypto and headers streams, do not respect
581   // connection level flow control limits (but are stream level flow control
582   // limited).
583   bool stream_contributes_to_connection_flow_control_;
584 
585   // A counter incremented when OnCanWrite() is called and no progress is made.
586   // For debugging only.
587   size_t busy_counter_;
588 
589   // Indicates whether paddings will be added after the fin is consumed for this
590   // stream.
591   bool add_random_padding_after_fin_;
592 
593   // Send buffer of this stream. Send buffer is cleaned up when data gets acked
594   // or discarded.
595   QuicStreamSendBuffer send_buffer_;
596 
597   // Latched value of quic_buffered_data_threshold.
598   const QuicByteCount buffered_data_threshold_;
599 
600   // If true, then this stream has precedence over other streams for write
601   // scheduling.
602   const bool is_static_;
603 
604   // If initialized, reset this stream at this deadline.
605   QuicTime deadline_;
606 
607   // True if this stream has entered draining state.
608   bool was_draining_;
609 
610   // Indicates whether this stream is bidirectional, read unidirectional or
611   // write unidirectional.
612   const StreamType type_;
613 
614   // Creation time of this stream, as reported by the QuicClock.
615   const QuicTime creation_time_;
616 
617   // The duration when the data for this stream was stored in a PendingStream
618   // before being moved to this QuicStream.
619   const QuicTime::Delta pending_duration_;
620 
621   Perspective perspective_;
622 };
623 
624 }  // namespace quic
625 
626 #endif  // QUICHE_QUIC_CORE_QUIC_STREAM_H_
627