QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | // A QuicSession, which demuxes a single connection to individual streams. |
| 6 | |
| 7 | #ifndef QUICHE_QUIC_CORE_QUIC_SESSION_H_ |
| 8 | #define QUICHE_QUIC_CORE_QUIC_SESSION_H_ |
| 9 | |
| 10 | #include <cstddef> |
renjietang | 216dc01 | 2019-08-27 11:28:27 -0700 | [diff] [blame] | 11 | #include <cstdint> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include <map> |
| 13 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 14 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/core/handshaker_delegate_interface.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 18 | #include "net/third_party/quiche/src/quic/core/legacy_quic_stream_id_manager.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_connection.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/quic_control_frame_manager.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/quic_crypto_stream.h" |
vasilvv | 2b0ab24 | 2020-01-07 07:32:09 -0800 | [diff] [blame] | 22 | #include "net/third_party/quiche/src/quic/core/quic_datagram_queue.h" |
wub | 2b5942f | 2019-04-11 13:22:50 -0700 | [diff] [blame] | 23 | #include "net/third_party/quiche/src/quic/core/quic_error_codes.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/core/quic_packet_creator.h" |
| 25 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 26 | #include "net/third_party/quiche/src/quic/core/quic_stream.h" |
| 27 | #include "net/third_party/quiche/src/quic/core/quic_stream_frame_data_producer.h" |
renjietang | 686ce58 | 2019-10-17 14:28:16 -0700 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | #include "net/third_party/quiche/src/quic/core/quic_write_blocked_list.h" |
| 30 | #include "net/third_party/quiche/src/quic/core/session_notifier_interface.h" |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 31 | #include "net/third_party/quiche/src/quic/core/stream_delegate_interface.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 32 | #include "net/third_party/quiche/src/quic/core/uber_quic_stream_id_manager.h" |
| 33 | #include "net/third_party/quiche/src/quic/platform/api/quic_containers.h" |
| 34 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 35 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 36 | #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] | 37 | |
| 38 | namespace quic { |
| 39 | |
| 40 | class QuicCryptoStream; |
| 41 | class QuicFlowController; |
| 42 | class QuicStream; |
| 43 | class QuicStreamIdManager; |
| 44 | |
| 45 | namespace test { |
| 46 | class QuicSessionPeer; |
| 47 | } // namespace test |
| 48 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 49 | class QUIC_EXPORT_PRIVATE QuicSession |
| 50 | : public QuicConnectionVisitorInterface, |
| 51 | public SessionNotifierInterface, |
| 52 | public QuicStreamFrameDataProducer, |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 53 | public QuicStreamIdManager::DelegateInterface, |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 54 | public HandshakerDelegateInterface, |
| 55 | public StreamDelegateInterface { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 56 | public: |
| 57 | // An interface from the session to the entity owning the session. |
| 58 | // This lets the session notify its owner (the Dispatcher) when the connection |
| 59 | // is closed, blocked, or added/removed from the time-wait list. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 60 | class QUIC_EXPORT_PRIVATE Visitor { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | public: |
| 62 | virtual ~Visitor() {} |
| 63 | |
| 64 | // Called when the connection is closed after the streams have been closed. |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 65 | virtual void OnConnectionClosed(QuicConnectionId server_connection_id, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 66 | QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 67 | const std::string& error_details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 68 | ConnectionCloseSource source) = 0; |
| 69 | |
| 70 | // Called when the session has become write blocked. |
| 71 | virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; |
| 72 | |
| 73 | // Called when the session receives reset on a stream from the peer. |
| 74 | virtual void OnRstStreamReceived(const QuicRstStreamFrame& frame) = 0; |
| 75 | |
| 76 | // Called when the session receives a STOP_SENDING for a stream from the |
| 77 | // peer. |
| 78 | virtual void OnStopSendingReceived(const QuicStopSendingFrame& frame) = 0; |
| 79 | }; |
| 80 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 81 | // Does not take ownership of |connection| or |visitor|. |
| 82 | QuicSession(QuicConnection* connection, |
| 83 | Visitor* owner, |
| 84 | const QuicConfig& config, |
renjietang | 216dc01 | 2019-08-27 11:28:27 -0700 | [diff] [blame] | 85 | const ParsedQuicVersionVector& supported_versions, |
| 86 | QuicStreamCount num_expected_unidirectional_static_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 87 | QuicSession(const QuicSession&) = delete; |
| 88 | QuicSession& operator=(const QuicSession&) = delete; |
| 89 | |
| 90 | ~QuicSession() override; |
| 91 | |
| 92 | virtual void Initialize(); |
| 93 | |
| 94 | // QuicConnectionVisitorInterface methods: |
| 95 | void OnStreamFrame(const QuicStreamFrame& frame) override; |
| 96 | void OnCryptoFrame(const QuicCryptoFrame& frame) override; |
| 97 | void OnRstStream(const QuicRstStreamFrame& frame) override; |
| 98 | void OnGoAway(const QuicGoAwayFrame& frame) override; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 99 | void OnMessageReceived(quiche::QuicheStringPiece message) override; |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 100 | void OnHandshakeDoneReceived() override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 101 | void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 102 | void OnBlockedFrame(const QuicBlockedFrame& frame) override; |
fkastenholz | 5d880a9 | 2019-06-21 09:01:56 -0700 | [diff] [blame] | 103 | void OnConnectionClosed(const QuicConnectionCloseFrame& frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 104 | ConnectionCloseSource source) override; |
| 105 | void OnWriteBlocked() override; |
| 106 | void OnSuccessfulVersionNegotiation( |
| 107 | const ParsedQuicVersion& version) override; |
zhongyi | 83161e4 | 2019-08-19 09:06:25 -0700 | [diff] [blame] | 108 | void OnPacketReceived(const QuicSocketAddress& self_address, |
| 109 | const QuicSocketAddress& peer_address, |
| 110 | bool is_connectivity_probe) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 111 | void OnCanWrite() override; |
QUICHE team | b834325 | 2019-04-29 13:58:01 -0700 | [diff] [blame] | 112 | bool SendProbingData() override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 113 | void OnCongestionWindowChange(QuicTime /*now*/) override {} |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 114 | void OnConnectionMigration(AddressChangeType /*type*/) override {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 115 | // Adds a connection level WINDOW_UPDATE frame. |
| 116 | void OnAckNeedsRetransmittableFrame() override; |
| 117 | void SendPing() override; |
| 118 | bool WillingAndAbleToWrite() const override; |
| 119 | bool HasPendingHandshake() const override; |
| 120 | void OnPathDegrading() override; |
| 121 | bool AllowSelfAddressChange() const override; |
fayang | c67c520 | 2020-01-22 07:43:15 -0800 | [diff] [blame] | 122 | HandshakeState GetHandshakeState() const override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 123 | void OnForwardProgressConfirmed() override; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 124 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override; |
| 125 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override; |
renjietang | eab918f | 2019-10-28 12:10:32 -0700 | [diff] [blame] | 126 | void OnStopSendingFrame(const QuicStopSendingFrame& frame) override; |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 127 | void OnPacketDecrypted(EncryptionLevel level) override; |
fayang | 2f2915d | 2020-01-24 06:47:15 -0800 | [diff] [blame] | 128 | void OnOneRttPacketAcknowledged() override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 129 | |
| 130 | // QuicStreamFrameDataProducer |
| 131 | WriteStreamDataResult WriteStreamData(QuicStreamId id, |
| 132 | QuicStreamOffset offset, |
| 133 | QuicByteCount data_length, |
| 134 | QuicDataWriter* writer) override; |
| 135 | bool WriteCryptoData(EncryptionLevel level, |
| 136 | QuicStreamOffset offset, |
| 137 | QuicByteCount data_length, |
| 138 | QuicDataWriter* writer) override; |
| 139 | |
| 140 | // SessionNotifierInterface methods: |
| 141 | bool OnFrameAcked(const QuicFrame& frame, |
QUICHE team | 9467db0 | 2019-05-30 09:38:45 -0700 | [diff] [blame] | 142 | QuicTime::Delta ack_delay_time, |
| 143 | QuicTime receive_timestamp) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 144 | void OnStreamFrameRetransmitted(const QuicStreamFrame& frame) override; |
| 145 | void OnFrameLost(const QuicFrame& frame) override; |
| 146 | void RetransmitFrames(const QuicFrames& frames, |
| 147 | TransmissionType type) override; |
| 148 | bool IsFrameOutstanding(const QuicFrame& frame) const override; |
| 149 | bool HasUnackedCryptoData() const override; |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 150 | bool HasUnackedStreamData() const override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 151 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 152 | // QuicStreamIdManager::DelegateInterface methods: |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 153 | void OnStreamIdManagerError(QuicErrorCode error_code, |
| 154 | std::string error_details) override; |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 155 | void SendMaxStreams(QuicStreamCount stream_count, |
| 156 | bool unidirectional) override; |
| 157 | void SendStreamsBlocked(QuicStreamCount stream_count, |
| 158 | bool unidirectional) override; |
| 159 | // The default implementation does nothing. Subclasses should override if |
| 160 | // for example they queue up stream requests. |
| 161 | void OnCanCreateNewOutgoingStream(bool unidirectional) override; |
| 162 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 163 | // Called on every incoming packet. Passes |packet| through to |connection_|. |
| 164 | virtual void ProcessUdpPacket(const QuicSocketAddress& self_address, |
| 165 | const QuicSocketAddress& peer_address, |
| 166 | const QuicReceivedPacket& packet); |
| 167 | |
| 168 | // Called by streams when they want to write data to the peer. |
| 169 | // Returns a pair with the number of bytes consumed from data, and a boolean |
| 170 | // indicating if the fin bit was consumed. This does not indicate the data |
| 171 | // has been sent on the wire: it may have been turned into a packet and queued |
| 172 | // if the socket was unexpectedly blocked. |
| 173 | virtual QuicConsumedData WritevData(QuicStream* stream, |
| 174 | QuicStreamId id, |
| 175 | size_t write_length, |
| 176 | QuicStreamOffset offset, |
| 177 | StreamSendingState state); |
| 178 | |
| 179 | // Called by application to send |message|. Data copy can be avoided if |
| 180 | // |message| is provided in reference counted memory. |
| 181 | // Please note, |message| provided in reference counted memory would be moved |
| 182 | // internally when message is successfully sent. Thereafter, it would be |
| 183 | // undefined behavior if callers try to access the slices through their own |
| 184 | // copy of the span object. |
| 185 | // Returns the message result which includes the message status and message ID |
| 186 | // (valid if the write succeeds). SendMessage flushes a message packet even it |
| 187 | // is not full. If the application wants to bundle other data in the same |
| 188 | // packet, please consider adding a packet flusher around the SendMessage |
| 189 | // and/or WritevData calls. |
| 190 | // |
| 191 | // OnMessageAcked and OnMessageLost are called when a particular message gets |
| 192 | // acked or lost. |
| 193 | // |
| 194 | // Note that SendMessage will fail with status = MESSAGE_STATUS_BLOCKED |
| 195 | // if connection is congestion control blocked or underlying socket is write |
| 196 | // blocked. In this case the caller can retry sending message again when |
| 197 | // connection becomes available, for example after getting OnCanWrite() |
| 198 | // callback. |
| 199 | MessageResult SendMessage(QuicMemSliceSpan message); |
| 200 | |
QUICHE team | 350e9e6 | 2019-11-19 13:16:24 -0800 | [diff] [blame] | 201 | // Same as above SendMessage, except caller can specify if the given |message| |
| 202 | // should be flushed even if the underlying connection is deemed unwritable. |
| 203 | MessageResult SendMessage(QuicMemSliceSpan message, bool flush); |
| 204 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 205 | // Called when message with |message_id| gets acked. |
QUICHE team | 9467db0 | 2019-05-30 09:38:45 -0700 | [diff] [blame] | 206 | virtual void OnMessageAcked(QuicMessageId message_id, |
| 207 | QuicTime receive_timestamp); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 208 | |
| 209 | // Called when message with |message_id| is considered as lost. |
| 210 | virtual void OnMessageLost(QuicMessageId message_id); |
| 211 | |
| 212 | // Called by control frame manager when it wants to write control frames to |
| 213 | // the peer. Returns true if |frame| is consumed, false otherwise. |
| 214 | virtual bool WriteControlFrame(const QuicFrame& frame); |
| 215 | |
renjietang | 6488161 | 2019-11-05 17:39:04 -0800 | [diff] [blame] | 216 | // Close the stream in both directions. |
| 217 | // TODO(renjietang): rename this method as it sends both RST_STREAM and |
| 218 | // STOP_SENDING in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 219 | virtual void SendRstStream(QuicStreamId id, |
| 220 | QuicRstStreamErrorCode error, |
| 221 | QuicStreamOffset bytes_written); |
| 222 | |
| 223 | // Called when the session wants to go away and not accept any new streams. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 224 | virtual void SendGoAway(QuicErrorCode error_code, const std::string& reason); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 225 | |
| 226 | // Sends a BLOCKED frame. |
| 227 | virtual void SendBlocked(QuicStreamId id); |
| 228 | |
| 229 | // Sends a WINDOW_UPDATE frame. |
| 230 | virtual void SendWindowUpdate(QuicStreamId id, QuicStreamOffset byte_offset); |
| 231 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 232 | // Create and transmit a STOP_SENDING frame |
| 233 | virtual void SendStopSending(uint16_t code, QuicStreamId stream_id); |
| 234 | |
| 235 | // Removes the stream associated with 'stream_id' from the active stream map. |
| 236 | virtual void CloseStream(QuicStreamId stream_id); |
| 237 | |
| 238 | // Returns true if outgoing packets will be encrypted, even if the server |
| 239 | // hasn't confirmed the handshake yet. |
| 240 | virtual bool IsEncryptionEstablished() const; |
| 241 | |
fayang | a3d8df7 | 2020-01-14 11:54:39 -0800 | [diff] [blame] | 242 | // Returns true if 1RTT keys are available. |
| 243 | bool OneRttKeysAvailable() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 244 | |
| 245 | // Called by the QuicCryptoStream when a new QuicConfig has been negotiated. |
| 246 | virtual void OnConfigNegotiated(); |
| 247 | |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 248 | // From HandshakerDelegateInterface |
fayang | d286652 | 2020-02-12 11:15:27 -0800 | [diff] [blame] | 249 | bool OnNewDecryptionKeyAvailable(EncryptionLevel level, |
fayang | 3f7bcbe | 2020-02-10 11:08:47 -0800 | [diff] [blame] | 250 | std::unique_ptr<QuicDecrypter> decrypter, |
| 251 | bool set_alternative_decrypter, |
| 252 | bool latch_once_used) override; |
| 253 | void OnNewEncryptionKeyAvailable( |
| 254 | EncryptionLevel level, |
| 255 | std::unique_ptr<QuicEncrypter> encrypter) override; |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 256 | void SetDefaultEncryptionLevel(EncryptionLevel level) override; |
| 257 | void DiscardOldDecryptionKey(EncryptionLevel level) override; |
| 258 | void DiscardOldEncryptionKey(EncryptionLevel level) override; |
| 259 | void NeuterUnencryptedData() override; |
| 260 | void NeuterHandshakeData() override; |
| 261 | |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 262 | // Implement StreamDelegateInterface. |
| 263 | void OnStreamError(QuicErrorCode error_code, |
| 264 | std::string error_details) override; |
| 265 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 266 | // Called by the QuicCryptoStream when a handshake message is sent. |
| 267 | virtual void OnCryptoHandshakeMessageSent( |
| 268 | const CryptoHandshakeMessage& message); |
| 269 | |
| 270 | // Called by the QuicCryptoStream when a handshake message is received. |
| 271 | virtual void OnCryptoHandshakeMessageReceived( |
| 272 | const CryptoHandshakeMessage& message); |
| 273 | |
| 274 | // Called by the stream on creation to set priority in the write blocked list. |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 275 | virtual void RegisterStreamPriority( |
| 276 | QuicStreamId id, |
| 277 | bool is_static, |
| 278 | const spdy::SpdyStreamPrecedence& precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 279 | // Called by the stream on deletion to clear priority from the write blocked |
| 280 | // list. |
| 281 | virtual void UnregisterStreamPriority(QuicStreamId id, bool is_static); |
| 282 | // Called by the stream on SetPriority to update priority on the write blocked |
| 283 | // list. |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 284 | virtual void UpdateStreamPriority( |
| 285 | QuicStreamId id, |
| 286 | const spdy::SpdyStreamPrecedence& new_precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 287 | |
| 288 | // Returns mutable config for this session. Returned config is owned |
| 289 | // by QuicSession. |
| 290 | QuicConfig* config(); |
| 291 | |
| 292 | // Returns true if the stream existed previously and has been closed. |
| 293 | // Returns false if the stream is still active or if the stream has |
| 294 | // not yet been created. |
| 295 | bool IsClosedStream(QuicStreamId id); |
| 296 | |
| 297 | QuicConnection* connection() { return connection_; } |
| 298 | const QuicConnection* connection() const { return connection_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 299 | const QuicSocketAddress& peer_address() const { |
| 300 | return connection_->peer_address(); |
| 301 | } |
| 302 | const QuicSocketAddress& self_address() const { |
| 303 | return connection_->self_address(); |
| 304 | } |
| 305 | QuicConnectionId connection_id() const { |
| 306 | return connection_->connection_id(); |
| 307 | } |
| 308 | |
renjietang | 69a8eaf | 2019-08-06 15:55:58 -0700 | [diff] [blame] | 309 | // Returns the number of currently open streams, excluding static streams, and |
| 310 | // never counting unfinished streams. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 311 | size_t GetNumActiveStreams() const; |
| 312 | |
| 313 | // Returns the number of currently draining streams. |
| 314 | size_t GetNumDrainingStreams() const; |
| 315 | |
renjietang | 69a8eaf | 2019-08-06 15:55:58 -0700 | [diff] [blame] | 316 | // Returns the number of currently open peer initiated streams, excluding |
| 317 | // static streams. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 318 | size_t GetNumOpenIncomingStreams() const; |
| 319 | |
renjietang | 69a8eaf | 2019-08-06 15:55:58 -0700 | [diff] [blame] | 320 | // Returns the number of currently open self initiated streams, excluding |
| 321 | // static streams. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 322 | size_t GetNumOpenOutgoingStreams() const; |
| 323 | |
renjietang | fbeb5bf | 2019-04-19 15:06:20 -0700 | [diff] [blame] | 324 | // Returns the number of open peer initiated static streams. |
| 325 | size_t num_incoming_static_streams() const { |
| 326 | return num_incoming_static_streams_; |
| 327 | } |
| 328 | |
| 329 | // Returns the number of open self initiated static streams. |
| 330 | size_t num_outgoing_static_streams() const { |
| 331 | return num_outgoing_static_streams_; |
| 332 | } |
| 333 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 334 | // Add the stream to the session's write-blocked list because it is blocked by |
| 335 | // connection-level flow control but not by its own stream-level flow control. |
| 336 | // The stream will be given a chance to write when a connection-level |
| 337 | // WINDOW_UPDATE arrives. |
QUICHE team | df0b19f | 2019-08-13 16:55:42 -0700 | [diff] [blame] | 338 | virtual void MarkConnectionLevelWriteBlocked(QuicStreamId id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 339 | |
| 340 | // Called when stream |id| is done waiting for acks either because all data |
| 341 | // gets acked or is not interested in data being acked (which happens when |
| 342 | // a stream is reset because of an error). |
| 343 | void OnStreamDoneWaitingForAcks(QuicStreamId id); |
| 344 | |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 345 | // Called when stream |id| is newly waiting for acks. |
| 346 | void OnStreamWaitingForAcks(QuicStreamId id); |
| 347 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 348 | // Returns true if the session has data to be sent, either queued in the |
| 349 | // connection, or in a write-blocked stream. |
| 350 | bool HasDataToWrite() const; |
| 351 | |
| 352 | // Returns the largest payload that will fit into a single MESSAGE frame. |
| 353 | // Because overhead can vary during a connection, this method should be |
| 354 | // checked for every message. |
ianswett | b239f86 | 2019-04-05 09:15:06 -0700 | [diff] [blame] | 355 | QuicPacketLength GetCurrentLargestMessagePayload() const; |
| 356 | |
| 357 | // Returns the largest payload that will fit into a single MESSAGE frame at |
| 358 | // any point during the connection. This assumes the version and |
| 359 | // connection ID lengths do not change. |
| 360 | QuicPacketLength GetGuaranteedLargestMessagePayload() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 361 | |
| 362 | bool goaway_sent() const { return goaway_sent_; } |
| 363 | |
| 364 | bool goaway_received() const { return goaway_received_; } |
| 365 | |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 366 | // Returns the Google QUIC error code |
| 367 | QuicErrorCode error() const { return on_closed_frame_.extracted_error_code; } |
wub | 43652ca | 2019-09-05 11:18:19 -0700 | [diff] [blame] | 368 | const std::string& error_details() const { |
| 369 | return on_closed_frame_.error_details; |
| 370 | } |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 371 | uint64_t transport_close_frame_type() const { |
| 372 | return on_closed_frame_.transport_close_frame_type; |
| 373 | } |
| 374 | QuicConnectionCloseType close_type() const { |
| 375 | return on_closed_frame_.close_type; |
| 376 | } |
| 377 | QuicIetfTransportErrorCodes transport_error_code() const { |
| 378 | return on_closed_frame_.transport_error_code; |
| 379 | } |
| 380 | uint16_t application_error_code() const { |
| 381 | return on_closed_frame_.application_error_code; |
| 382 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 383 | |
dschinazi | 31e94d4 | 2019-12-18 11:55:39 -0800 | [diff] [blame] | 384 | Perspective perspective() const { return perspective_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 385 | |
| 386 | QuicFlowController* flow_controller() { return &flow_controller_; } |
| 387 | |
| 388 | // Returns true if connection is flow controller blocked. |
| 389 | bool IsConnectionFlowControlBlocked() const; |
| 390 | |
| 391 | // Returns true if any stream is flow controller blocked. |
| 392 | bool IsStreamFlowControlBlocked(); |
| 393 | |
| 394 | size_t max_open_incoming_bidirectional_streams() const; |
| 395 | size_t max_open_incoming_unidirectional_streams() const; |
| 396 | |
| 397 | size_t MaxAvailableBidirectionalStreams() const; |
| 398 | size_t MaxAvailableUnidirectionalStreams() const; |
| 399 | |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 400 | // Returns existing stream with id = |stream_id|. If no |
| 401 | // such stream exists, and |stream_id| is a peer-created stream id, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 402 | // then a new stream is created and returned. In all other cases, nullptr is |
| 403 | // returned. |
renjietang | 880d243 | 2019-07-16 13:14:37 -0700 | [diff] [blame] | 404 | // Caller does not own the returned stream. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 405 | QuicStream* GetOrCreateStream(const QuicStreamId stream_id); |
| 406 | |
| 407 | // Mark a stream as draining. |
| 408 | virtual void StreamDraining(QuicStreamId id); |
| 409 | |
| 410 | // Returns true if this stream should yield writes to another blocked stream. |
QUICHE team | df0b19f | 2019-08-13 16:55:42 -0700 | [diff] [blame] | 411 | virtual bool ShouldYield(QuicStreamId stream_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 412 | |
| 413 | // Set transmission type of next sending packets. |
| 414 | void SetTransmissionType(TransmissionType type); |
| 415 | |
| 416 | // Clean up closed_streams_. |
| 417 | void CleanUpClosedStreams(); |
| 418 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 419 | const ParsedQuicVersionVector& supported_versions() const { |
| 420 | return supported_versions_; |
| 421 | } |
| 422 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 423 | QuicStreamId next_outgoing_bidirectional_stream_id() const; |
| 424 | QuicStreamId next_outgoing_unidirectional_stream_id() const; |
| 425 | |
| 426 | // Return true if given stream is peer initiated. |
| 427 | bool IsIncomingStream(QuicStreamId id) const; |
| 428 | |
| 429 | size_t GetNumLocallyClosedOutgoingStreamsHighestOffset() const; |
| 430 | |
| 431 | size_t num_locally_closed_incoming_streams_highest_offset() const { |
| 432 | return num_locally_closed_incoming_streams_highest_offset_; |
| 433 | } |
| 434 | |
wub | 2b5942f | 2019-04-11 13:22:50 -0700 | [diff] [blame] | 435 | // Record errors when a connection is closed at the server side, should only |
| 436 | // be called from server's perspective. |
| 437 | // Noop if |error| is QUIC_NO_ERROR. |
| 438 | static void RecordConnectionCloseAtServer(QuicErrorCode error, |
| 439 | ConnectionCloseSource source); |
| 440 | |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 441 | inline QuicTransportVersion transport_version() const { |
| 442 | return connection_->transport_version(); |
| 443 | } |
| 444 | |
nharper | 46c1e67 | 2020-01-16 14:50:31 -0800 | [diff] [blame] | 445 | inline ParsedQuicVersion version() const { return connection_->version(); } |
| 446 | |
fayang | 944cfbc | 2019-07-31 09:15:00 -0700 | [diff] [blame] | 447 | bool use_http2_priority_write_scheduler() const { |
| 448 | return use_http2_priority_write_scheduler_; |
| 449 | } |
| 450 | |
fkastenholz | 9b4b0ad | 2019-08-20 05:10:40 -0700 | [diff] [blame] | 451 | bool is_configured() const { return is_configured_; } |
| 452 | |
renjietang | 216dc01 | 2019-08-27 11:28:27 -0700 | [diff] [blame] | 453 | QuicStreamCount num_expected_unidirectional_static_streams() const { |
| 454 | return num_expected_unidirectional_static_streams_; |
| 455 | } |
| 456 | |
| 457 | // Set the number of unidirectional stream that the peer is allowed to open to |
| 458 | // be |max_stream| + |num_expected_static_streams_|. |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 459 | void ConfigureMaxDynamicStreamsToSend(QuicStreamCount max_stream) { |
| 460 | config_.SetMaxUnidirectionalStreamsToSend( |
renjietang | 216dc01 | 2019-08-27 11:28:27 -0700 | [diff] [blame] | 461 | max_stream + num_expected_unidirectional_static_streams_); |
| 462 | } |
| 463 | |
vasilvv | 4724c9c | 2019-08-29 11:52:11 -0700 | [diff] [blame] | 464 | // Returns the ALPN values to negotiate on this session. |
vasilvv | ad7424f | 2019-08-30 00:27:14 -0700 | [diff] [blame] | 465 | virtual std::vector<std::string> GetAlpnsToOffer() const { |
vasilvv | 4724c9c | 2019-08-29 11:52:11 -0700 | [diff] [blame] | 466 | // TODO(vasilvv): this currently sets HTTP/3 by default. Switch all |
| 467 | // non-HTTP applications to appropriate ALPNs. |
| 468 | return std::vector<std::string>({AlpnForVersion(connection()->version())}); |
| 469 | } |
| 470 | |
vasilvv | ad7424f | 2019-08-30 00:27:14 -0700 | [diff] [blame] | 471 | // Provided a list of ALPNs offered by the client, selects an ALPN from the |
| 472 | // list, or alpns.end() if none of the ALPNs are acceptable. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 473 | virtual std::vector<quiche::QuicheStringPiece>::const_iterator SelectAlpn( |
| 474 | const std::vector<quiche::QuicheStringPiece>& alpns) const; |
vasilvv | ad7424f | 2019-08-30 00:27:14 -0700 | [diff] [blame] | 475 | |
| 476 | // Called when the ALPN of the connection is established for a connection that |
| 477 | // uses TLS handshake. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 478 | virtual void OnAlpnSelected(quiche::QuicheStringPiece alpn); |
vasilvv | ad7424f | 2019-08-30 00:27:14 -0700 | [diff] [blame] | 479 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 480 | protected: |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 481 | using StreamMap = QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 482 | |
| 483 | using PendingStreamMap = |
| 484 | QuicSmallMap<QuicStreamId, std::unique_ptr<PendingStream>, 10>; |
| 485 | |
| 486 | using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; |
| 487 | |
| 488 | using ZombieStreamMap = |
| 489 | QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
| 490 | |
| 491 | // Creates a new stream to handle a peer-initiated stream. |
| 492 | // Caller does not own the returned stream. |
| 493 | // Returns nullptr and does error handling if the stream can not be created. |
| 494 | virtual QuicStream* CreateIncomingStream(QuicStreamId id) = 0; |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 495 | virtual QuicStream* CreateIncomingStream(PendingStream* pending) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 496 | |
| 497 | // Return the reserved crypto stream. |
| 498 | virtual QuicCryptoStream* GetMutableCryptoStream() = 0; |
| 499 | |
| 500 | // Return the reserved crypto stream as a constant pointer. |
| 501 | virtual const QuicCryptoStream* GetCryptoStream() const = 0; |
| 502 | |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 503 | // Adds |stream| to the stream map. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 504 | virtual void ActivateStream(std::unique_ptr<QuicStream> stream); |
| 505 | |
| 506 | // Returns the stream ID for a new outgoing bidirectional/unidirectional |
| 507 | // stream, and increments the underlying counter. |
| 508 | QuicStreamId GetNextOutgoingBidirectionalStreamId(); |
| 509 | QuicStreamId GetNextOutgoingUnidirectionalStreamId(); |
| 510 | |
| 511 | // Indicates whether the next outgoing bidirectional/unidirectional stream ID |
| 512 | // can be allocated or not. The test for version-99/IETF QUIC is whether it |
| 513 | // will exceed the maximum-stream-id or not. For non-version-99 (Google) QUIC |
| 514 | // it checks whether the next stream would exceed the limit on the number of |
| 515 | // open streams. |
| 516 | bool CanOpenNextOutgoingBidirectionalStream(); |
| 517 | bool CanOpenNextOutgoingUnidirectionalStream(); |
| 518 | |
| 519 | // Returns the number of open dynamic streams. |
| 520 | uint64_t GetNumOpenDynamicStreams() const; |
| 521 | |
bnc | 41c19ca | 2020-01-21 18:55:26 -0800 | [diff] [blame] | 522 | // Returns the maximum bidirectional streams parameter sent with the handshake |
| 523 | // as a transport parameter, or in the most recent MAX_STREAMS frame. |
| 524 | QuicStreamCount GetAdvertisedMaxIncomingBidirectionalStreams() const; |
| 525 | |
renjietang | 75bbf98 | 2020-02-03 16:40:05 -0800 | [diff] [blame] | 526 | // Performs the work required to close |stream_id|. If |rst_sent| then a |
| 527 | // Reset Stream frame has already been sent for this stream. |
| 528 | virtual void CloseStreamInner(QuicStreamId stream_id, bool rst_sent); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 529 | |
| 530 | // When a stream is closed locally, it may not yet know how many bytes the |
| 531 | // peer sent on that stream. |
| 532 | // When this data arrives (via stream frame w. FIN, trailing headers, or RST) |
| 533 | // this method is called, and correctly updates the connection level flow |
| 534 | // controller. |
| 535 | virtual void OnFinalByteOffsetReceived(QuicStreamId id, |
| 536 | QuicStreamOffset final_byte_offset); |
| 537 | |
renjietang | e76b2da | 2019-05-13 14:50:23 -0700 | [diff] [blame] | 538 | // Returns true if incoming unidirectional streams should be buffered until |
| 539 | // the first byte of the stream arrives. |
| 540 | // If a subclass returns true here, it should make sure to implement |
| 541 | // ProcessPendingStream(). |
| 542 | virtual bool UsesPendingStreams() const { return false; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 543 | |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 544 | StreamMap& stream_map() { return stream_map_; } |
| 545 | const StreamMap& stream_map() const { return stream_map_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 546 | |
renjietang | 56d2ed2 | 2019-10-22 14:11:55 -0700 | [diff] [blame] | 547 | const PendingStreamMap& pending_streams() const { |
| 548 | return pending_stream_map_; |
| 549 | } |
| 550 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 551 | ClosedStreams* closed_streams() { return &closed_streams_; } |
| 552 | |
| 553 | const ZombieStreamMap& zombie_streams() const { return zombie_streams_; } |
| 554 | |
| 555 | void set_largest_peer_created_stream_id( |
| 556 | QuicStreamId largest_peer_created_stream_id); |
| 557 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 558 | QuicWriteBlockedList* write_blocked_streams() { |
| 559 | return &write_blocked_streams_; |
| 560 | } |
| 561 | |
| 562 | size_t GetNumDynamicOutgoingStreams() const; |
| 563 | |
| 564 | size_t GetNumDrainingOutgoingStreams() const; |
| 565 | |
| 566 | // Returns true if the stream is still active. |
| 567 | bool IsOpenStream(QuicStreamId id); |
| 568 | |
rch | da26cdb | 2019-05-17 11:57:37 -0700 | [diff] [blame] | 569 | // Returns true if the stream is a static stream. |
| 570 | bool IsStaticStream(QuicStreamId id) const; |
| 571 | |
renjietang | 5c729f0 | 2019-09-06 12:43:48 -0700 | [diff] [blame] | 572 | // Close connection when receive a frame for a locally-created nonexistent |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 573 | // stream. |
| 574 | // Prerequisite: IsClosedStream(stream_id) == false |
| 575 | // Server session might need to override this method to allow server push |
| 576 | // stream to be promised before creating an active stream. |
| 577 | virtual void HandleFrameOnNonexistentOutgoingStream(QuicStreamId stream_id); |
| 578 | |
| 579 | virtual bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId stream_id); |
| 580 | |
| 581 | void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, |
| 582 | QuicStreamOffset offset); |
| 583 | // If stream is a locally closed stream, this RST will update FIN offset. |
| 584 | // Otherwise stream is a preserved stream and the behavior of it depends on |
| 585 | // derived class's own implementation. |
| 586 | virtual void HandleRstOnValidNonexistentStream( |
| 587 | const QuicRstStreamFrame& frame); |
| 588 | |
| 589 | // Returns a stateless reset token which will be included in the public reset |
| 590 | // packet. |
| 591 | virtual QuicUint128 GetStatelessResetToken() const; |
| 592 | |
| 593 | QuicControlFrameManager& control_frame_manager() { |
| 594 | return control_frame_manager_; |
| 595 | } |
| 596 | |
| 597 | const LegacyQuicStreamIdManager& stream_id_manager() const { |
| 598 | return stream_id_manager_; |
| 599 | } |
| 600 | |
vasilvv | 2b0ab24 | 2020-01-07 07:32:09 -0800 | [diff] [blame] | 601 | QuicDatagramQueue* datagram_queue() { return &datagram_queue_; } |
| 602 | |
renjietang | 0c55886 | 2019-05-08 13:26:23 -0700 | [diff] [blame] | 603 | // Processes the stream type information of |pending| depending on |
renjietang | bb1c489 | 2019-05-24 15:58:44 -0700 | [diff] [blame] | 604 | // different kinds of sessions' own rules. Returns true if the pending stream |
| 605 | // is converted into a normal stream. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 606 | virtual bool ProcessPendingStream(PendingStream* /*pending*/) { |
| 607 | return false; |
| 608 | } |
renjietang | 0c55886 | 2019-05-08 13:26:23 -0700 | [diff] [blame] | 609 | |
renjietang | 686ce58 | 2019-10-17 14:28:16 -0700 | [diff] [blame] | 610 | // Return the largest peer created stream id depending on directionality |
| 611 | // indicated by |unidirectional|. |
| 612 | QuicStreamId GetLargestPeerCreatedStreamId(bool unidirectional) const; |
| 613 | |
ianswett | 6aefa0b | 2019-12-10 07:26:15 -0800 | [diff] [blame] | 614 | // Deletes the connection and sets it to nullptr, so calling it mulitiple |
| 615 | // times is safe. |
| 616 | void DeleteConnection(); |
| 617 | |
bnc | b4e7b99 | 2020-01-21 18:36:14 -0800 | [diff] [blame] | 618 | // Call SetPriority() on stream id |id| and return true if stream is active. |
| 619 | bool MaybeSetStreamPriority(QuicStreamId stream_id, |
| 620 | const spdy::SpdyStreamPrecedence& precedence); |
| 621 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 622 | private: |
| 623 | friend class test::QuicSessionPeer; |
| 624 | |
| 625 | // Called in OnConfigNegotiated when we receive a new stream level flow |
| 626 | // control window in a negotiated config. Closes the connection if invalid. |
| 627 | void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); |
| 628 | |
dschinazi | 18cdf13 | 2019-10-09 16:08:18 -0700 | [diff] [blame] | 629 | // Called in OnConfigNegotiated when we receive a new unidirectional stream |
| 630 | // flow control window in a negotiated config. |
| 631 | void OnNewStreamUnidirectionalFlowControlWindow(QuicStreamOffset new_window); |
| 632 | |
| 633 | // Called in OnConfigNegotiated when we receive a new outgoing bidirectional |
| 634 | // stream flow control window in a negotiated config. |
| 635 | void OnNewStreamOutgoingBidirectionalFlowControlWindow( |
| 636 | QuicStreamOffset new_window); |
| 637 | |
| 638 | // Called in OnConfigNegotiated when we receive a new incoming bidirectional |
| 639 | // stream flow control window in a negotiated config. |
| 640 | void OnNewStreamIncomingBidirectionalFlowControlWindow( |
| 641 | QuicStreamOffset new_window); |
| 642 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 643 | // Called in OnConfigNegotiated when we receive a new connection level flow |
| 644 | // control window in a negotiated config. Closes the connection if invalid. |
| 645 | void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); |
| 646 | |
| 647 | // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes |
| 648 | // forward progress. Returns false if busy loop detected. |
| 649 | bool CheckStreamNotBusyLooping(QuicStream* stream, |
| 650 | uint64_t previous_bytes_written, |
| 651 | bool previous_fin_sent); |
| 652 | |
| 653 | // Debug helper for OnCanWrite. Check that after QuicStream::OnCanWrite(), |
| 654 | // if stream has buffered data and is not stream level flow control blocked, |
| 655 | // it has to be in the write blocked list. |
| 656 | bool CheckStreamWriteBlocked(QuicStream* stream) const; |
| 657 | |
| 658 | // Called in OnConfigNegotiated for Finch trials to measure performance of |
| 659 | // starting with larger flow control receive windows. |
| 660 | void AdjustInitialFlowControlWindows(size_t stream_window); |
| 661 | |
| 662 | // Find stream with |id|, returns nullptr if the stream does not exist or |
| 663 | // closed. |
| 664 | QuicStream* GetStream(QuicStreamId id) const; |
| 665 | |
renjietang | e76b2da | 2019-05-13 14:50:23 -0700 | [diff] [blame] | 666 | PendingStream* GetOrCreatePendingStream(QuicStreamId stream_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 667 | |
| 668 | // Let streams and control frame managers retransmit lost data, returns true |
| 669 | // if all lost data is retransmitted. Returns false otherwise. |
| 670 | bool RetransmitLostData(); |
| 671 | |
| 672 | // Closes the pending stream |stream_id| before it has been created. |
| 673 | void ClosePendingStream(QuicStreamId stream_id); |
| 674 | |
renjietang | e76b2da | 2019-05-13 14:50:23 -0700 | [diff] [blame] | 675 | // Creates or gets pending stream, feeds it with |frame|, and processes the |
| 676 | // pending stream. |
| 677 | void PendingStreamOnStreamFrame(const QuicStreamFrame& frame); |
| 678 | |
| 679 | // Creates or gets pending strea, feed it with |frame|, and closes the pending |
| 680 | // stream. |
| 681 | void PendingStreamOnRstStream(const QuicRstStreamFrame& frame); |
| 682 | |
renjietang | 61cc245 | 2019-11-26 10:57:10 -0800 | [diff] [blame] | 683 | // Does actual work of sending RESET_STREAM, if the stream type allows. |
| 684 | void MaybeSendRstStreamFrame(QuicStreamId id, |
| 685 | QuicRstStreamErrorCode error, |
| 686 | QuicStreamOffset bytes_written); |
| 687 | |
| 688 | // Sends a STOP_SENDING frame if the stream type allows. |
| 689 | void MaybeSendStopSendingFrame(QuicStreamId id, QuicRstStreamErrorCode error); |
| 690 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 691 | // Keep track of highest received byte offset of locally closed streams, while |
| 692 | // waiting for a definitive final highest offset from the peer. |
| 693 | std::map<QuicStreamId, QuicStreamOffset> |
| 694 | locally_closed_streams_highest_offset_; |
| 695 | |
| 696 | QuicConnection* connection_; |
| 697 | |
dschinazi | 31e94d4 | 2019-12-18 11:55:39 -0800 | [diff] [blame] | 698 | // Store perspective on QuicSession during the constructor as it may be needed |
| 699 | // during our destructor when connection_ may have already been destroyed. |
| 700 | Perspective perspective_; |
| 701 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 702 | // May be null. |
| 703 | Visitor* visitor_; |
| 704 | |
| 705 | // A list of streams which need to write more data. Stream register |
| 706 | // themselves in their constructor, and unregisterm themselves in their |
| 707 | // destructors, so the write blocked list must outlive all streams. |
| 708 | QuicWriteBlockedList write_blocked_streams_; |
| 709 | |
| 710 | ClosedStreams closed_streams_; |
| 711 | // Streams which are closed, but need to be kept alive. Currently, the only |
| 712 | // reason is the stream's sent data (including FIN) does not get fully acked. |
| 713 | ZombieStreamMap zombie_streams_; |
| 714 | |
| 715 | QuicConfig config_; |
| 716 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 717 | // Map from StreamId to pointers to streams. Owns the streams. |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 718 | StreamMap stream_map_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 719 | |
| 720 | // Map from StreamId to PendingStreams for peer-created unidirectional streams |
| 721 | // which are waiting for the first byte of payload to arrive. |
| 722 | PendingStreamMap pending_stream_map_; |
| 723 | |
| 724 | // Set of stream ids that are "draining" -- a FIN has been sent and received, |
| 725 | // but the stream object still exists because not all the received data has |
| 726 | // been consumed. |
| 727 | QuicUnorderedSet<QuicStreamId> draining_streams_; |
| 728 | |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 729 | // Set of stream ids that are waiting for acks excluding crypto stream id. |
| 730 | QuicUnorderedSet<QuicStreamId> streams_waiting_for_acks_; |
| 731 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 732 | // TODO(fayang): Consider moving LegacyQuicStreamIdManager into |
| 733 | // UberQuicStreamIdManager. |
| 734 | // Manages stream IDs for Google QUIC. |
| 735 | LegacyQuicStreamIdManager stream_id_manager_; |
| 736 | |
| 737 | // Manages stream IDs for version99/IETF QUIC |
| 738 | UberQuicStreamIdManager v99_streamid_manager_; |
| 739 | |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 740 | // A counter for peer initiated dynamic streams which are in the stream_map_. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 741 | size_t num_dynamic_incoming_streams_; |
| 742 | |
| 743 | // A counter for peer initiated streams which are in the draining_streams_. |
| 744 | size_t num_draining_incoming_streams_; |
| 745 | |
renjietang | fbeb5bf | 2019-04-19 15:06:20 -0700 | [diff] [blame] | 746 | // A counter for self initiated static streams which are in |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 747 | // stream_map_. |
renjietang | fbeb5bf | 2019-04-19 15:06:20 -0700 | [diff] [blame] | 748 | size_t num_outgoing_static_streams_; |
| 749 | |
| 750 | // A counter for peer initiated static streams which are in |
renjietang | 55d182a | 2019-07-12 10:26:25 -0700 | [diff] [blame] | 751 | // stream_map_. |
renjietang | fbeb5bf | 2019-04-19 15:06:20 -0700 | [diff] [blame] | 752 | size_t num_incoming_static_streams_; |
| 753 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 754 | // A counter for peer initiated streams which are in the |
| 755 | // locally_closed_streams_highest_offset_. |
| 756 | size_t num_locally_closed_incoming_streams_highest_offset_; |
| 757 | |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 758 | // Received information for a connection close. |
| 759 | QuicConnectionCloseFrame on_closed_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 760 | |
| 761 | // Used for connection-level flow control. |
| 762 | QuicFlowController flow_controller_; |
| 763 | |
| 764 | // The stream id which was last popped in OnCanWrite, or 0, if not under the |
| 765 | // call stack of OnCanWrite. |
| 766 | QuicStreamId currently_writing_stream_id_; |
| 767 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 768 | // Whether a GoAway has been sent. |
| 769 | bool goaway_sent_; |
| 770 | |
| 771 | // Whether a GoAway has been received. |
| 772 | bool goaway_received_; |
| 773 | |
| 774 | QuicControlFrameManager control_frame_manager_; |
| 775 | |
| 776 | // Id of latest successfully sent message. |
| 777 | QuicMessageId last_message_id_; |
| 778 | |
vasilvv | 2b0ab24 | 2020-01-07 07:32:09 -0800 | [diff] [blame] | 779 | // The buffer used to queue the DATAGRAM frames. |
| 780 | QuicDatagramQueue datagram_queue_; |
| 781 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 782 | // TODO(fayang): switch to linked_hash_set when chromium supports it. The bool |
| 783 | // is not used here. |
| 784 | // List of streams with pending retransmissions. |
| 785 | QuicLinkedHashMap<QuicStreamId, bool> streams_with_pending_retransmission_; |
| 786 | |
| 787 | // Clean up closed_streams_ when this alarm fires. |
| 788 | std::unique_ptr<QuicAlarm> closed_streams_clean_up_alarm_; |
| 789 | |
| 790 | // Supported version list used by the crypto handshake only. Please note, this |
| 791 | // list may be a superset of the connection framer's supported versions. |
| 792 | ParsedQuicVersionVector supported_versions_; |
fayang | 944cfbc | 2019-07-31 09:15:00 -0700 | [diff] [blame] | 793 | |
| 794 | // If true, write_blocked_streams_ uses HTTP2 (tree-style) priority write |
| 795 | // scheduler. |
| 796 | bool use_http2_priority_write_scheduler_; |
fkastenholz | 9b4b0ad | 2019-08-20 05:10:40 -0700 | [diff] [blame] | 797 | |
| 798 | // Initialized to false. Set to true when the session has been properly |
| 799 | // configured and is ready for general operation. |
| 800 | bool is_configured_; |
renjietang | 216dc01 | 2019-08-27 11:28:27 -0700 | [diff] [blame] | 801 | |
| 802 | // The number of expected static streams. |
| 803 | QuicStreamCount num_expected_unidirectional_static_streams_; |
fayang | 1b11b96 | 2019-09-16 14:01:48 -0700 | [diff] [blame] | 804 | |
| 805 | // If true, enables round robin scheduling. |
| 806 | bool enable_round_robin_scheduling_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 807 | }; |
| 808 | |
| 809 | } // namespace quic |
| 810 | |
| 811 | #endif // QUICHE_QUIC_CORE_QUIC_SESSION_H_ |