QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015 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_SPDY_SESSION_H_ |
| 6 | #define QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_SESSION_H_ |
| 7 | |
| 8 | #include <cstddef> |
| 9 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 10 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | |
renjietang | a6d4737 | 2019-09-27 14:17:56 -0700 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/http/http_frames.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/http/quic_header_list.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/http/quic_headers_stream.h" |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/core/http/quic_receive_control_stream.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/http/quic_send_control_stream.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_stream.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_decoder.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_decoder_stream_sender.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_encoder.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_encoder_stream_sender.h" |
renjietang | 87cd7de | 2019-08-16 08:35:10 -0700 | [diff] [blame] | 22 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_receive_stream.h" |
| 23 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_send_stream.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/core/quic_session.h" |
| 25 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
| 26 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 27 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/spdy/core/http2_frame_decoder_adapter.h" |
| 29 | |
| 30 | namespace quic { |
| 31 | |
| 32 | namespace test { |
| 33 | class QuicSpdySessionPeer; |
| 34 | } // namespace test |
| 35 | |
| 36 | // QuicHpackDebugVisitor gathers data used for understanding HPACK HoL |
| 37 | // dynamics. Specifically, it is to help predict the compression |
| 38 | // penalty of avoiding HoL by chagning how the dynamic table is used. |
| 39 | // In chromium, the concrete instance populates an UMA |
| 40 | // histogram with the data. |
| 41 | class QUIC_EXPORT_PRIVATE QuicHpackDebugVisitor { |
| 42 | public: |
| 43 | QuicHpackDebugVisitor(); |
| 44 | QuicHpackDebugVisitor(const QuicHpackDebugVisitor&) = delete; |
| 45 | QuicHpackDebugVisitor& operator=(const QuicHpackDebugVisitor&) = delete; |
| 46 | |
| 47 | virtual ~QuicHpackDebugVisitor(); |
| 48 | |
| 49 | // For each HPACK indexed representation processed, |elapsed| is |
| 50 | // the time since the corresponding entry was added to the dynamic |
| 51 | // table. |
| 52 | virtual void OnUseEntry(QuicTime::Delta elapsed) = 0; |
| 53 | }; |
| 54 | |
renjietang | aaf85e4 | 2019-09-17 10:29:50 -0700 | [diff] [blame] | 55 | class QUIC_EXPORT_PRIVATE Http3DebugVisitor { |
| 56 | public: |
| 57 | Http3DebugVisitor(); |
| 58 | Http3DebugVisitor(const Http3DebugVisitor&) = delete; |
| 59 | Http3DebugVisitor& operator=(const Http3DebugVisitor&) = delete; |
| 60 | |
| 61 | virtual ~Http3DebugVisitor(); |
| 62 | |
| 63 | // Called when peer's control stream type is received. |
| 64 | virtual void OnPeerControlStreamCreated(QuicStreamId /*stream_id*/) = 0; |
| 65 | |
| 66 | // Called when peer's QPACK encoder stream type is received. |
| 67 | virtual void OnPeerQpackEncoderStreamCreated(QuicStreamId /*stream_id*/) = 0; |
| 68 | |
| 69 | // Called when peer's QPACK decoder stream type is received. |
| 70 | virtual void OnPeerQpackDecoderStreamCreated(QuicStreamId /*stream_id*/) = 0; |
| 71 | |
| 72 | // Called when SETTINGS frame is received. |
renjietang | a6d4737 | 2019-09-27 14:17:56 -0700 | [diff] [blame] | 73 | virtual void OnSettingsFrameReceived(const SettingsFrame& /*frame*/) = 0; |
| 74 | |
| 75 | // Called when SETTINGS frame is sent. |
| 76 | virtual void OnSettingsFrameSent(const SettingsFrame& /*frame*/) = 0; |
renjietang | aaf85e4 | 2019-09-17 10:29:50 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
renjietang | 69a8eaf | 2019-08-06 15:55:58 -0700 | [diff] [blame] | 79 | // A QUIC session for HTTP. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 80 | class QUIC_EXPORT_PRIVATE QuicSpdySession |
| 81 | : public QuicSession, |
| 82 | public QpackEncoder::DecoderStreamErrorDelegate, |
renjietang | c2aa5cb | 2019-06-20 12:22:53 -0700 | [diff] [blame] | 83 | public QpackDecoder::EncoderStreamErrorDelegate { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 84 | public: |
| 85 | // Does not take ownership of |connection| or |visitor|. |
| 86 | QuicSpdySession(QuicConnection* connection, |
| 87 | QuicSession::Visitor* visitor, |
| 88 | const QuicConfig& config, |
| 89 | const ParsedQuicVersionVector& supported_versions); |
| 90 | QuicSpdySession(const QuicSpdySession&) = delete; |
| 91 | QuicSpdySession& operator=(const QuicSpdySession&) = delete; |
| 92 | |
| 93 | ~QuicSpdySession() override; |
| 94 | |
| 95 | void Initialize() override; |
| 96 | |
| 97 | // QpackEncoder::DecoderStreamErrorDelegate implementation. |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 98 | void OnDecoderStreamError(quiche::QuicheStringPiece error_message) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 99 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 100 | // QpackDecoder::EncoderStreamErrorDelegate implementation. |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 101 | void OnEncoderStreamError(quiche::QuicheStringPiece error_message) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 103 | // Called by |headers_stream_| when headers with a priority have been |
| 104 | // received for a stream. This method will only be called for server streams. |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 105 | virtual void OnStreamHeadersPriority( |
| 106 | QuicStreamId stream_id, |
| 107 | const spdy::SpdyStreamPrecedence& precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | |
| 109 | // Called by |headers_stream_| when headers have been completely received |
| 110 | // for a stream. |fin| will be true if the fin flag was set in the headers |
| 111 | // frame. |
| 112 | virtual void OnStreamHeaderList(QuicStreamId stream_id, |
| 113 | bool fin, |
| 114 | size_t frame_len, |
| 115 | const QuicHeaderList& header_list); |
| 116 | |
| 117 | // Called by |headers_stream_| when push promise headers have been |
| 118 | // completely received. |fin| will be true if the fin flag was set |
| 119 | // in the headers. |
| 120 | virtual void OnPromiseHeaderList(QuicStreamId stream_id, |
| 121 | QuicStreamId promised_stream_id, |
| 122 | size_t frame_len, |
| 123 | const QuicHeaderList& header_list); |
| 124 | |
| 125 | // Called by |headers_stream_| when a PRIORITY frame has been received for a |
| 126 | // stream. This method will only be called for server streams. |
| 127 | virtual void OnPriorityFrame(QuicStreamId stream_id, |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 128 | const spdy::SpdyStreamPrecedence& precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 129 | |
| 130 | // Sends contents of |iov| to h2_deframer_, returns number of bytes processed. |
| 131 | size_t ProcessHeaderData(const struct iovec& iov); |
| 132 | |
| 133 | // Writes |headers| for the stream |id| to the dedicated headers stream. |
| 134 | // If |fin| is true, then no more data will be sent for the stream |id|. |
| 135 | // If provided, |ack_notifier_delegate| will be registered to be notified when |
| 136 | // we have seen ACKs for all packets resulting from this call. |
| 137 | virtual size_t WriteHeadersOnHeadersStream( |
| 138 | QuicStreamId id, |
| 139 | spdy::SpdyHeaderBlock headers, |
| 140 | bool fin, |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 141 | const spdy::SpdyStreamPrecedence& precedence, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 142 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 143 | |
bnc | cd3c4b5 | 2020-01-10 11:13:18 -0800 | [diff] [blame] | 144 | // Writes an HTTP/2 PRIORITY frame the to peer. Returns the size in bytes of |
| 145 | // the resulting PRIORITY frame for QUIC_VERSION_43 and above. Otherwise, does |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 146 | // nothing and returns 0. |
| 147 | size_t WritePriority(QuicStreamId id, |
| 148 | QuicStreamId parent_stream_id, |
| 149 | int weight, |
| 150 | bool exclusive); |
| 151 | |
bnc | cd3c4b5 | 2020-01-10 11:13:18 -0800 | [diff] [blame] | 152 | // Writes an HTTP/3 PRIORITY_UPDATE frame to the peer. |
| 153 | void WriteHttp3PriorityUpdate(const PriorityUpdateFrame& priority_update); |
| 154 | |
renjietang | 686ce58 | 2019-10-17 14:28:16 -0700 | [diff] [blame] | 155 | // Process received HTTP/3 GOAWAY frame. This method should only be called on |
| 156 | // the client side. |
| 157 | virtual void OnHttp3GoAway(QuicStreamId stream_id); |
| 158 | |
| 159 | // Write the GOAWAY |frame| on control stream. |
| 160 | void SendHttp3GoAway(); |
| 161 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 162 | // Write |headers| for |promised_stream_id| on |original_stream_id| in a |
| 163 | // PUSH_PROMISE frame to peer. |
renjietang | f4f4712 | 2019-07-22 12:08:53 -0700 | [diff] [blame] | 164 | virtual void WritePushPromise(QuicStreamId original_stream_id, |
| 165 | QuicStreamId promised_stream_id, |
| 166 | spdy::SpdyHeaderBlock headers); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 167 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 168 | QpackEncoder* qpack_encoder(); |
| 169 | QpackDecoder* qpack_decoder(); |
renjietang | 9818f8c | 2019-07-16 11:12:27 -0700 | [diff] [blame] | 170 | QuicHeadersStream* headers_stream() { return headers_stream_; } |
renjietang | fbeb5bf | 2019-04-19 15:06:20 -0700 | [diff] [blame] | 171 | |
renjietang | 9818f8c | 2019-07-16 11:12:27 -0700 | [diff] [blame] | 172 | const QuicHeadersStream* headers_stream() const { return headers_stream_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 173 | |
| 174 | bool server_push_enabled() const { return server_push_enabled_; } |
| 175 | |
bnc | 5b182b9 | 2019-07-30 11:00:15 -0700 | [diff] [blame] | 176 | // Called when a setting is parsed from an incoming SETTINGS frame. |
| 177 | void OnSetting(uint64_t id, uint64_t value); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 178 | |
| 179 | // Return true if this session wants to release headers stream's buffer |
| 180 | // aggressively. |
| 181 | virtual bool ShouldReleaseHeadersStreamSequencerBuffer(); |
| 182 | |
| 183 | void CloseConnectionWithDetails(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 184 | const std::string& details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 185 | |
bnc | 5597f29 | 2019-08-23 07:09:25 -0700 | [diff] [blame] | 186 | // Must not be called after Initialize(). |
| 187 | // TODO(bnc): Move to constructor argument. |
| 188 | void set_qpack_maximum_dynamic_table_capacity( |
| 189 | uint64_t qpack_maximum_dynamic_table_capacity) { |
| 190 | qpack_maximum_dynamic_table_capacity_ = |
| 191 | qpack_maximum_dynamic_table_capacity; |
| 192 | } |
| 193 | |
| 194 | // Must not be called after Initialize(). |
| 195 | // TODO(bnc): Move to constructor argument. |
| 196 | void set_qpack_maximum_blocked_streams( |
| 197 | uint64_t qpack_maximum_blocked_streams) { |
| 198 | qpack_maximum_blocked_streams_ = qpack_maximum_blocked_streams; |
| 199 | } |
| 200 | |
| 201 | // Must not be called after Initialize(). |
bnc | 30d610c | 2019-07-08 18:39:59 -0700 | [diff] [blame] | 202 | // TODO(bnc): Move to constructor argument. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 203 | void set_max_inbound_header_list_size(size_t max_inbound_header_list_size) { |
| 204 | max_inbound_header_list_size_ = max_inbound_header_list_size; |
| 205 | } |
| 206 | |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 207 | size_t max_outbound_header_list_size() const { |
| 208 | return max_outbound_header_list_size_; |
| 209 | } |
| 210 | |
renjietang | fee2cc3 | 2019-04-05 11:32:07 -0700 | [diff] [blame] | 211 | size_t max_inbound_header_list_size() const { |
| 212 | return max_inbound_header_list_size_; |
| 213 | } |
| 214 | |
QUICHE team | c2653c4 | 2019-03-08 13:30:06 -0800 | [diff] [blame] | 215 | // Returns true if the session has active request streams. |
| 216 | bool HasActiveRequestStreams() const; |
| 217 | |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 218 | // Called when the size of the compressed frame payload is available. |
| 219 | void OnCompressedFrameSize(size_t frame_len); |
| 220 | |
| 221 | // Called when a PUSH_PROMISE frame has been received. |
| 222 | void OnPushPromise(spdy::SpdyStreamId stream_id, |
| 223 | spdy::SpdyStreamId promised_stream_id); |
| 224 | |
| 225 | // Called when the complete list of headers is available. |
| 226 | void OnHeaderList(const QuicHeaderList& header_list); |
| 227 | |
| 228 | QuicStreamId promised_stream_id() const { return promised_stream_id_; } |
| 229 | |
renjietang | c04c85f | 2019-07-25 14:07:27 -0700 | [diff] [blame] | 230 | // Initialze HTTP/3 unidirectional streams if |unidirectional| is true and |
| 231 | // those streams are not initialized yet. |
| 232 | void OnCanCreateNewOutgoingStream(bool unidirectional) override; |
| 233 | |
rch | 6317221 | 2019-10-15 11:38:28 -0700 | [diff] [blame] | 234 | void SetMaxAllowedPushId(QuicStreamId max_allowed_push_id); |
QUICHE team | c258e4f | 2019-08-14 10:04:58 -0700 | [diff] [blame] | 235 | |
| 236 | QuicStreamId max_allowed_push_id() { return max_allowed_push_id_; } |
| 237 | |
fayang | eae1ea8 | 2019-08-20 13:21:19 -0700 | [diff] [blame] | 238 | int32_t destruction_indicator() const { return destruction_indicator_; } |
| 239 | |
renjietang | aaf85e4 | 2019-09-17 10:29:50 -0700 | [diff] [blame] | 240 | void set_debug_visitor(Http3DebugVisitor* debug_visitor) { |
| 241 | debug_visitor_ = debug_visitor; |
| 242 | } |
| 243 | |
| 244 | Http3DebugVisitor* debug_visitor() { return debug_visitor_; } |
| 245 | |
renjietang | 686ce58 | 2019-10-17 14:28:16 -0700 | [diff] [blame] | 246 | bool http3_goaway_received() const { return http3_goaway_received_; } |
| 247 | |
| 248 | bool http3_goaway_sent() const { return http3_goaway_sent_; } |
| 249 | |
bnc | 20a9ad9 | 2019-10-01 10:29:14 -0700 | [diff] [blame] | 250 | // Log header compression ratio histogram. |
| 251 | // |using_qpack| is true for QPACK, false for HPACK. |
| 252 | // |is_sent| is true for sent headers, false for received ones. |
| 253 | // Ratio is recorded as percentage. Smaller value means more efficient |
| 254 | // compression. Compressed size might be larger than uncompressed size, but |
| 255 | // recorded ratio is trunckated at 200%. |
| 256 | // Uncompressed size can be zero for an empty header list, and compressed size |
| 257 | // can be zero for an empty header list when using HPACK. (QPACK always emits |
| 258 | // a header block prefix of at least two bytes.) This method records nothing |
| 259 | // if either |compressed| or |uncompressed| is not positive. |
| 260 | // In order for measurements for different protocol to be comparable, the |
| 261 | // caller must ensure that uncompressed size is the total length of header |
| 262 | // names and values without any overhead. |
| 263 | static void LogHeaderCompressionRatioHistogram(bool using_qpack, |
| 264 | bool is_sent, |
| 265 | QuicByteCount compressed, |
| 266 | QuicByteCount uncompressed); |
| 267 | |
bnc | 20df1af | 2019-11-12 10:46:20 -0800 | [diff] [blame] | 268 | // True if any dynamic table entries have been referenced from either a sent |
| 269 | // or received header block. Used for stats. |
| 270 | bool dynamic_table_entry_referenced() const { |
| 271 | return (qpack_encoder_ && |
| 272 | qpack_encoder_->dynamic_table_entry_referenced()) || |
| 273 | (qpack_decoder_ && qpack_decoder_->dynamic_table_entry_referenced()); |
| 274 | } |
| 275 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 276 | protected: |
| 277 | // Override CreateIncomingStream(), CreateOutgoingBidirectionalStream() and |
| 278 | // CreateOutgoingUnidirectionalStream() with QuicSpdyStream return type to |
| 279 | // make sure that all data streams are QuicSpdyStreams. |
| 280 | QuicSpdyStream* CreateIncomingStream(QuicStreamId id) override = 0; |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 281 | QuicSpdyStream* CreateIncomingStream(PendingStream* pending) override = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 282 | virtual QuicSpdyStream* CreateOutgoingBidirectionalStream() = 0; |
| 283 | virtual QuicSpdyStream* CreateOutgoingUnidirectionalStream() = 0; |
| 284 | |
renjietang | 59dc770 | 2019-12-10 15:40:02 -0800 | [diff] [blame] | 285 | QuicSpdyStream* GetOrCreateSpdyDataStream(const QuicStreamId stream_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 286 | |
| 287 | // If an incoming stream can be created, return true. |
| 288 | virtual bool ShouldCreateIncomingStream(QuicStreamId id) = 0; |
| 289 | |
| 290 | // If an outgoing bidirectional/unidirectional stream can be created, return |
| 291 | // true. |
| 292 | virtual bool ShouldCreateOutgoingBidirectionalStream() = 0; |
| 293 | virtual bool ShouldCreateOutgoingUnidirectionalStream() = 0; |
| 294 | |
| 295 | // Returns true if there are open HTTP requests. |
| 296 | bool ShouldKeepConnectionAlive() const override; |
| 297 | |
renjietang | e76b2da | 2019-05-13 14:50:23 -0700 | [diff] [blame] | 298 | // Overridden to buffer incoming unidirectional streams for version 99. |
| 299 | bool UsesPendingStreams() const override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 300 | |
renjietang | bb1c489 | 2019-05-24 15:58:44 -0700 | [diff] [blame] | 301 | // Overridden to Process HTTP/3 stream types. H/3 streams will be created from |
| 302 | // pending streams accordingly if the stream type can be read. Returns true if |
| 303 | // unidirectional streams are created. |
| 304 | bool ProcessPendingStream(PendingStream* pending) override; |
renjietang | 0c55886 | 2019-05-08 13:26:23 -0700 | [diff] [blame] | 305 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 306 | size_t WriteHeadersOnHeadersStreamImpl( |
| 307 | QuicStreamId id, |
| 308 | spdy::SpdyHeaderBlock headers, |
| 309 | bool fin, |
| 310 | QuicStreamId parent_stream_id, |
| 311 | int weight, |
| 312 | bool exclusive, |
| 313 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener); |
| 314 | |
| 315 | void OnCryptoHandshakeEvent(CryptoHandshakeEvent event) override; |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 316 | void SetDefaultEncryptionLevel(quic::EncryptionLevel level) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 317 | |
| 318 | bool supports_push_promise() { return supports_push_promise_; } |
| 319 | |
| 320 | // Optional, enables instrumentation related to go/quic-hpack. |
| 321 | void SetHpackEncoderDebugVisitor( |
| 322 | std::unique_ptr<QuicHpackDebugVisitor> visitor); |
| 323 | void SetHpackDecoderDebugVisitor( |
| 324 | std::unique_ptr<QuicHpackDebugVisitor> visitor); |
| 325 | |
| 326 | // Sets the maximum size of the header compression table spdy_framer_ is |
| 327 | // willing to use to encode header blocks. |
| 328 | void UpdateHeaderEncoderTableSize(uint32_t value); |
| 329 | |
| 330 | // Called when SETTINGS_ENABLE_PUSH is received, only supported on |
| 331 | // server side. |
| 332 | void UpdateEnableServerPush(bool value); |
| 333 | |
| 334 | bool IsConnected() { return connection()->connected(); } |
| 335 | |
renjietang | 118c8ac | 2019-07-30 11:43:59 -0700 | [diff] [blame] | 336 | const QuicReceiveControlStream* receive_control_stream() const { |
| 337 | return receive_control_stream_; |
| 338 | } |
| 339 | |
renjietang | 1a33a0c | 2019-08-12 12:05:31 -0700 | [diff] [blame] | 340 | // Initializes HTTP/3 unidirectional streams if not yet initialzed. |
| 341 | virtual void MaybeInitializeHttp3UnidirectionalStreams(); |
| 342 | |
QUICHE team | c258e4f | 2019-08-14 10:04:58 -0700 | [diff] [blame] | 343 | void set_max_uncompressed_header_bytes( |
| 344 | size_t set_max_uncompressed_header_bytes); |
| 345 | |
rch | 6317221 | 2019-10-15 11:38:28 -0700 | [diff] [blame] | 346 | void SendMaxPushId(); |
QUICHE team | c258e4f | 2019-08-14 10:04:58 -0700 | [diff] [blame] | 347 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 348 | private: |
| 349 | friend class test::QuicSpdySessionPeer; |
| 350 | |
| 351 | class SpdyFramerVisitor; |
| 352 | |
| 353 | // The following methods are called by the SimpleVisitor. |
| 354 | |
| 355 | // Called when a HEADERS frame has been received. |
| 356 | void OnHeaders(spdy::SpdyStreamId stream_id, |
| 357 | bool has_priority, |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 358 | const spdy::SpdyStreamPrecedence& precedence, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 359 | bool fin); |
| 360 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 361 | // Called when a PRIORITY frame has been received. |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 362 | void OnPriority(spdy::SpdyStreamId stream_id, |
| 363 | const spdy::SpdyStreamPrecedence& precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 364 | |
renjietang | 309b7fb | 2019-08-21 12:26:26 -0700 | [diff] [blame] | 365 | void CloseConnectionOnDuplicateHttp3UnidirectionalStreams( |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 366 | quiche::QuicheStringPiece type); |
renjietang | 309b7fb | 2019-08-21 12:26:26 -0700 | [diff] [blame] | 367 | |
rch | 5f22abc | 2019-10-11 16:25:12 -0700 | [diff] [blame] | 368 | // Sends any data which should be sent at the start of a connection, |
| 369 | // including the initial SETTINGS frame, etc. |
| 370 | void SendInitialData(); |
| 371 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 372 | std::unique_ptr<QpackEncoder> qpack_encoder_; |
| 373 | std::unique_ptr<QpackDecoder> qpack_decoder_; |
| 374 | |
renjietang | 9818f8c | 2019-07-16 11:12:27 -0700 | [diff] [blame] | 375 | // Pointer to the header stream in stream_map_. |
| 376 | QuicHeadersStream* headers_stream_; |
renjietang | fbeb5bf | 2019-04-19 15:06:20 -0700 | [diff] [blame] | 377 | |
renjietang | 87cd7de | 2019-08-16 08:35:10 -0700 | [diff] [blame] | 378 | // HTTP/3 control streams. They are owned by QuicSession inside |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 379 | // stream map, and can be accessed by those unowned pointers below. |
| 380 | QuicSendControlStream* send_control_stream_; |
| 381 | QuicReceiveControlStream* receive_control_stream_; |
| 382 | |
renjietang | 87cd7de | 2019-08-16 08:35:10 -0700 | [diff] [blame] | 383 | // Pointers to HTTP/3 QPACK streams in stream map. |
| 384 | QpackReceiveStream* qpack_encoder_receive_stream_; |
| 385 | QpackReceiveStream* qpack_decoder_receive_stream_; |
| 386 | QpackSendStream* qpack_encoder_send_stream_; |
| 387 | QpackSendStream* qpack_decoder_send_stream_; |
| 388 | |
bnc | 5597f29 | 2019-08-23 07:09:25 -0700 | [diff] [blame] | 389 | // Maximum dynamic table capacity as defined at |
| 390 | // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#maximum-dynamic-table-capacity |
| 391 | // for the decoding context. Value will be sent via |
| 392 | // SETTINGS_QPACK_MAX_TABLE_CAPACITY. |
bnc | b9cf4c7 | 2019-09-12 14:46:01 -0700 | [diff] [blame] | 393 | // |qpack_maximum_dynamic_table_capacity_| also serves as an upper bound for |
| 394 | // the dynamic table capacity of the encoding context, to limit memory usage |
| 395 | // if a larger SETTINGS_QPACK_MAX_TABLE_CAPACITY value is received. |
bnc | 5597f29 | 2019-08-23 07:09:25 -0700 | [diff] [blame] | 396 | uint64_t qpack_maximum_dynamic_table_capacity_; |
| 397 | |
| 398 | // Maximum number of blocked streams as defined at |
| 399 | // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#blocked-streams |
| 400 | // for the decoding context. Value will be sent via |
| 401 | // SETTINGS_QPACK_BLOCKED_STREAMS. |
| 402 | uint64_t qpack_maximum_blocked_streams_; |
| 403 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 404 | // The maximum size of a header block that will be accepted from the peer, |
| 405 | // defined per spec as key + value + overhead per field (uncompressed). |
bnc | 5597f29 | 2019-08-23 07:09:25 -0700 | [diff] [blame] | 406 | // Value will be sent via SETTINGS_MAX_HEADER_LIST_SIZE. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 407 | size_t max_inbound_header_list_size_; |
| 408 | |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 409 | // The maximum size of a header block that can be sent to the peer. This field |
| 410 | // is informed and set by the peer via SETTINGS frame. |
| 411 | // TODO(renjietang): Honor this field when sending headers. |
| 412 | size_t max_outbound_header_list_size_; |
| 413 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 414 | // Set during handshake. If true, resources in x-associated-content and link |
| 415 | // headers will be pushed. |
| 416 | bool server_push_enabled_; |
| 417 | |
| 418 | // Data about the stream whose headers are being processed. |
| 419 | QuicStreamId stream_id_; |
| 420 | QuicStreamId promised_stream_id_; |
| 421 | bool fin_; |
| 422 | size_t frame_len_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 423 | |
| 424 | bool supports_push_promise_; |
| 425 | |
| 426 | spdy::SpdyFramer spdy_framer_; |
| 427 | http2::Http2DecoderAdapter h2_deframer_; |
| 428 | std::unique_ptr<SpdyFramerVisitor> spdy_framer_visitor_; |
QUICHE team | c258e4f | 2019-08-14 10:04:58 -0700 | [diff] [blame] | 429 | QuicStreamId max_allowed_push_id_; |
fayang | eae1ea8 | 2019-08-20 13:21:19 -0700 | [diff] [blame] | 430 | |
| 431 | // An integer used for live check. The indicator is assigned a value in |
| 432 | // constructor. As long as it is not the assigned value, that would indicate |
| 433 | // an use-after-free. |
| 434 | int32_t destruction_indicator_; |
renjietang | aaf85e4 | 2019-09-17 10:29:50 -0700 | [diff] [blame] | 435 | |
| 436 | // Not owned by the session. |
| 437 | Http3DebugVisitor* debug_visitor_; |
renjietang | 686ce58 | 2019-10-17 14:28:16 -0700 | [diff] [blame] | 438 | |
| 439 | // If the endpoint has received HTTP/3 GOAWAY frame. |
| 440 | bool http3_goaway_received_; |
| 441 | // If the endpoint has sent HTTP/3 GOAWAY frame. |
| 442 | bool http3_goaway_sent_; |
rch | 4cd745d | 2019-12-03 13:19:41 -0800 | [diff] [blame] | 443 | |
renjietang | 59dc770 | 2019-12-10 15:40:02 -0800 | [diff] [blame] | 444 | // If the endpoint has sent the initial HTTP/3 MAX_PUSH_ID frame. |
rch | 4cd745d | 2019-12-03 13:19:41 -0800 | [diff] [blame] | 445 | bool http3_max_push_id_sent_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 446 | }; |
| 447 | |
| 448 | } // namespace quic |
| 449 | |
| 450 | #endif // QUICHE_QUIC_CORE_HTTP_QUIC_SPDY_SESSION_H_ |