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