QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2013 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 | #ifndef QUICHE_QUIC_CORE_HTTP_QUIC_HEADERS_STREAM_H_ |
| 6 | #define QUICHE_QUIC_CORE_HTTP_QUIC_HEADERS_STREAM_H_ |
| 7 | |
| 8 | #include <cstddef> |
| 9 | #include <memory> |
| 10 | |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 11 | #include "quic/core/http/quic_header_list.h" |
| 12 | #include "quic/core/quic_packets.h" |
| 13 | #include "quic/core/quic_stream.h" |
| 14 | #include "quic/platform/api/quic_containers.h" |
| 15 | #include "quic/platform/api/quic_export.h" |
| 16 | #include "spdy/core/spdy_framer.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | |
| 18 | namespace quic { |
| 19 | |
| 20 | class QuicSpdySession; |
| 21 | |
| 22 | namespace test { |
| 23 | class QuicHeadersStreamPeer; |
| 24 | } // namespace test |
| 25 | |
| 26 | // Headers in QUIC are sent as HTTP/2 HEADERS or PUSH_PROMISE frames over a |
| 27 | // reserved stream with the id 3. Each endpoint (client and server) will |
| 28 | // allocate an instance of QuicHeadersStream to send and receive headers. |
| 29 | class QUIC_EXPORT_PRIVATE QuicHeadersStream : public QuicStream { |
| 30 | public: |
| 31 | explicit QuicHeadersStream(QuicSpdySession* session); |
| 32 | QuicHeadersStream(const QuicHeadersStream&) = delete; |
| 33 | QuicHeadersStream& operator=(const QuicHeadersStream&) = delete; |
| 34 | ~QuicHeadersStream() override; |
| 35 | |
| 36 | // QuicStream implementation |
| 37 | void OnDataAvailable() override; |
| 38 | |
| 39 | // Release underlying buffer if allowed. |
| 40 | void MaybeReleaseSequencerBuffer(); |
| 41 | |
| 42 | bool OnStreamFrameAcked(QuicStreamOffset offset, |
| 43 | QuicByteCount data_length, |
| 44 | bool fin_acked, |
| 45 | QuicTime::Delta ack_delay_time, |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 46 | QuicTime receive_timestamp, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 47 | QuicByteCount* newly_acked_length) override; |
| 48 | |
| 49 | void OnStreamFrameRetransmitted(QuicStreamOffset offset, |
| 50 | QuicByteCount data_length, |
| 51 | bool fin_retransmitted) override; |
| 52 | |
renjietang | 546c714 | 2020-03-05 14:12:10 -0800 | [diff] [blame] | 53 | void OnStreamReset(const QuicRstStreamFrame& frame) override; |
| 54 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 55 | private: |
| 56 | friend class test::QuicHeadersStreamPeer; |
| 57 | |
| 58 | // CompressedHeaderInfo includes simple information of a header, including |
| 59 | // offset in headers stream, unacked length and ack listener of this header. |
| 60 | struct QUIC_EXPORT_PRIVATE CompressedHeaderInfo { |
| 61 | CompressedHeaderInfo( |
| 62 | QuicStreamOffset headers_stream_offset, |
| 63 | QuicStreamOffset full_length, |
| 64 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 65 | CompressedHeaderInfo(const CompressedHeaderInfo& other); |
| 66 | ~CompressedHeaderInfo(); |
| 67 | |
| 68 | // Offset the header was sent on the headers stream. |
| 69 | QuicStreamOffset headers_stream_offset; |
| 70 | // The full length of the header. |
| 71 | QuicByteCount full_length; |
| 72 | // The remaining bytes to be acked. |
| 73 | QuicByteCount unacked_length; |
| 74 | // Ack listener of this header, and it is notified once any of the bytes has |
| 75 | // been acked or retransmitted. |
| 76 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener; |
| 77 | }; |
| 78 | |
| 79 | // Returns true if the session is still connected. |
| 80 | bool IsConnected(); |
| 81 | |
| 82 | // Override to store mapping from offset, length to ack_listener. This |
| 83 | // ack_listener is notified once data within [offset, offset + length] is |
| 84 | // acked or retransmitted. |
| 85 | void OnDataBuffered( |
| 86 | QuicStreamOffset offset, |
| 87 | QuicByteCount data_length, |
| 88 | const QuicReferenceCountedPointer<QuicAckListenerInterface>& ack_listener) |
| 89 | override; |
| 90 | |
| 91 | QuicSpdySession* spdy_session_; |
| 92 | |
| 93 | // Headers that have not been fully acked. |
wub | a750aab | 2020-02-10 06:43:15 -0800 | [diff] [blame] | 94 | QuicCircularDeque<CompressedHeaderInfo> unacked_headers_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // namespace quic |
| 98 | |
| 99 | #endif // QUICHE_QUIC_CORE_HTTP_QUIC_HEADERS_STREAM_H_ |