| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // A QuicSession, which demuxes a single connection to individual streams. | 5 // A QuicSession, which demuxes a single connection to individual streams. |
| 6 | 6 |
| 7 #ifndef NET_QUIC_QUIC_SESSION_H_ | 7 #ifndef NET_QUIC_QUIC_SESSION_H_ |
| 8 #define NET_QUIC_QUIC_SESSION_H_ | 8 #define NET_QUIC_QUIC_SESSION_H_ |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <unordered_map> | 15 #include <unordered_map> |
| 16 #include <unordered_set> | 16 #include <unordered_set> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/containers/small_map.h" | 20 #include "base/containers/small_map.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
| 23 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
| 24 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
| 25 #include "net/quic/core/quic_connection.h" | 25 #include "net/quic/core/quic_connection.h" |
| 26 #include "net/quic/core/quic_crypto_stream.h" | 26 #include "net/quic/core/quic_crypto_stream.h" |
| 27 #include "net/quic/core/quic_packet_creator.h" | 27 #include "net/quic/core/quic_packet_creator.h" |
| 28 #include "net/quic/core/quic_protocol.h" | 28 #include "net/quic/core/quic_protocol.h" |
| 29 #include "net/quic/core/quic_stream.h" |
| 29 #include "net/quic/core/quic_write_blocked_list.h" | 30 #include "net/quic/core/quic_write_blocked_list.h" |
| 30 #include "net/quic/core/reliable_quic_stream.h" | |
| 31 | 31 |
| 32 namespace net { | 32 namespace net { |
| 33 | 33 |
| 34 class QuicCryptoStream; | 34 class QuicCryptoStream; |
| 35 class QuicFlowController; | 35 class QuicFlowController; |
| 36 class ReliableQuicStream; | 36 class QuicStream; |
| 37 | 37 |
| 38 namespace test { | 38 namespace test { |
| 39 class QuicSessionPeer; | 39 class QuicSessionPeer; |
| 40 } // namespace test | 40 } // namespace test |
| 41 | 41 |
| 42 class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { | 42 class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { |
| 43 public: | 43 public: |
| 44 // An interface from the session to the entity owning the session. | 44 // An interface from the session to the entity owning the session. |
| 45 // This lets the session notify its owner (the Dispatcher) when the connection | 45 // This lets the session notify its owner (the Dispatcher) when the connection |
| 46 // is closed, blocked, or added/removed from the time-wait std::list. | 46 // is closed, blocked, or added/removed from the time-wait std::list. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const QuicReceivedPacket& packet); | 111 const QuicReceivedPacket& packet); |
| 112 | 112 |
| 113 // Called by streams when they want to write data to the peer. | 113 // Called by streams when they want to write data to the peer. |
| 114 // Returns a pair with the number of bytes consumed from data, and a boolean | 114 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 115 // indicating if the fin bit was consumed. This does not indicate the data | 115 // indicating if the fin bit was consumed. This does not indicate the data |
| 116 // has been sent on the wire: it may have been turned into a packet and queued | 116 // has been sent on the wire: it may have been turned into a packet and queued |
| 117 // if the socket was unexpectedly blocked. | 117 // if the socket was unexpectedly blocked. |
| 118 // If provided, |ack_notifier_delegate| will be registered to be notified when | 118 // If provided, |ack_notifier_delegate| will be registered to be notified when |
| 119 // we have seen ACKs for all packets resulting from this call. | 119 // we have seen ACKs for all packets resulting from this call. |
| 120 virtual QuicConsumedData WritevData( | 120 virtual QuicConsumedData WritevData( |
| 121 ReliableQuicStream* stream, | 121 QuicStream* stream, |
| 122 QuicStreamId id, | 122 QuicStreamId id, |
| 123 QuicIOVector iov, | 123 QuicIOVector iov, |
| 124 QuicStreamOffset offset, | 124 QuicStreamOffset offset, |
| 125 bool fin, | 125 bool fin, |
| 126 QuicAckListenerInterface* ack_notifier_delegate); | 126 QuicAckListenerInterface* ack_notifier_delegate); |
| 127 | 127 |
| 128 // Called by streams when they want to close the stream in both directions. | 128 // Called by streams when they want to close the stream in both directions. |
| 129 virtual void SendRstStream(QuicStreamId id, | 129 virtual void SendRstStream(QuicStreamId id, |
| 130 QuicRstStreamErrorCode error, | 130 QuicRstStreamErrorCode error, |
| 131 QuicStreamOffset bytes_written); | 131 QuicStreamOffset bytes_written); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 size_t max_open_outgoing_streams() const { | 231 size_t max_open_outgoing_streams() const { |
| 232 return max_open_outgoing_streams_; | 232 return max_open_outgoing_streams_; |
| 233 } | 233 } |
| 234 | 234 |
| 235 size_t MaxAvailableStreams() const; | 235 size_t MaxAvailableStreams() const; |
| 236 | 236 |
| 237 // Returns existing static or dynamic stream with id = |stream_id|. If no | 237 // Returns existing static or dynamic stream with id = |stream_id|. If no |
| 238 // such stream exists, and |stream_id| is a peer-created dynamic stream id, | 238 // such stream exists, and |stream_id| is a peer-created dynamic stream id, |
| 239 // then a new stream is created and returned. In all other cases, nullptr is | 239 // then a new stream is created and returned. In all other cases, nullptr is |
| 240 // returned. | 240 // returned. |
| 241 ReliableQuicStream* GetOrCreateStream(const QuicStreamId stream_id); | 241 QuicStream* GetOrCreateStream(const QuicStreamId stream_id); |
| 242 | 242 |
| 243 // Mark a stream as draining. | 243 // Mark a stream as draining. |
| 244 virtual void StreamDraining(QuicStreamId id); | 244 virtual void StreamDraining(QuicStreamId id); |
| 245 | 245 |
| 246 // Returns true if this stream should yield writes to another blocked stream. | 246 // Returns true if this stream should yield writes to another blocked stream. |
| 247 bool ShouldYield(QuicStreamId stream_id); | 247 bool ShouldYield(QuicStreamId stream_id); |
| 248 | 248 |
| 249 protected: | 249 protected: |
| 250 using StaticStreamMap = | 250 using StaticStreamMap = |
| 251 base::SmallMap<std::unordered_map<QuicStreamId, ReliableQuicStream*>, 2>; | 251 base::SmallMap<std::unordered_map<QuicStreamId, QuicStream*>, 2>; |
| 252 | 252 |
| 253 using DynamicStreamMap = base::SmallMap< | 253 using DynamicStreamMap = base::SmallMap< |
| 254 std::unordered_map<QuicStreamId, std::unique_ptr<ReliableQuicStream>>, | 254 std::unordered_map<QuicStreamId, std::unique_ptr<QuicStream>>, |
| 255 10>; | 255 10>; |
| 256 | 256 |
| 257 using ClosedStreams = std::vector<std::unique_ptr<ReliableQuicStream>>; | 257 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; |
| 258 | 258 |
| 259 // Creates a new stream to handle a peer-initiated stream. | 259 // Creates a new stream to handle a peer-initiated stream. |
| 260 // Caller does not own the returned stream. | 260 // Caller does not own the returned stream. |
| 261 // Returns nullptr and does error handling if the stream can not be created. | 261 // Returns nullptr and does error handling if the stream can not be created. |
| 262 virtual ReliableQuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; | 262 virtual QuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; |
| 263 | 263 |
| 264 // Create a new stream to handle a locally-initiated stream. | 264 // Create a new stream to handle a locally-initiated stream. |
| 265 // Caller does not own the returned stream. | 265 // Caller does not own the returned stream. |
| 266 // Returns nullptr if max streams have already been opened. | 266 // Returns nullptr if max streams have already been opened. |
| 267 virtual ReliableQuicStream* CreateOutgoingDynamicStream( | 267 virtual QuicStream* CreateOutgoingDynamicStream(SpdyPriority priority) = 0; |
| 268 SpdyPriority priority) = 0; | |
| 269 | 268 |
| 270 // Return the reserved crypto stream. | 269 // Return the reserved crypto stream. |
| 271 virtual QuicCryptoStream* GetCryptoStream() = 0; | 270 virtual QuicCryptoStream* GetCryptoStream() = 0; |
| 272 | 271 |
| 273 // Adds |stream| to the dynamic stream map. | 272 // Adds |stream| to the dynamic stream map. |
| 274 virtual void ActivateStream(std::unique_ptr<ReliableQuicStream> stream); | 273 virtual void ActivateStream(std::unique_ptr<QuicStream> stream); |
| 275 | 274 |
| 276 // Returns the stream ID for a new outgoing stream, and increments the | 275 // Returns the stream ID for a new outgoing stream, and increments the |
| 277 // underlying counter. | 276 // underlying counter. |
| 278 QuicStreamId GetNextOutgoingStreamId(); | 277 QuicStreamId GetNextOutgoingStreamId(); |
| 279 | 278 |
| 280 // Returns existing stream with id = |stream_id|. If no such stream exists, | 279 // Returns existing stream with id = |stream_id|. If no such stream exists, |
| 281 // and |stream_id| is a peer-created id, then a new stream is created and | 280 // and |stream_id| is a peer-created id, then a new stream is created and |
| 282 // returned. However if |stream_id| is a locally-created id and no such stream | 281 // returned. However if |stream_id| is a locally-created id and no such stream |
| 283 // exists, the connection is closed. | 282 // exists, the connection is closed. |
| 284 // Caller does not own the returned stream. | 283 // Caller does not own the returned stream. |
| 285 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id); | 284 QuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id); |
| 286 | 285 |
| 287 // Performs the work required to close |stream_id|. If |locally_reset| | 286 // Performs the work required to close |stream_id|. If |locally_reset| |
| 288 // then the stream has been reset by this endpoint, not by the peer. | 287 // then the stream has been reset by this endpoint, not by the peer. |
| 289 virtual void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); | 288 virtual void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); |
| 290 | 289 |
| 291 // When a stream is closed locally, it may not yet know how many bytes the | 290 // When a stream is closed locally, it may not yet know how many bytes the |
| 292 // peer sent on that stream. | 291 // peer sent on that stream. |
| 293 // When this data arrives (via stream frame w. FIN, or RST) this method | 292 // When this data arrives (via stream frame w. FIN, or RST) this method |
| 294 // is called, and correctly updates the connection level flow controller. | 293 // is called, and correctly updates the connection level flow controller. |
| 295 void UpdateFlowControlOnFinalReceivedByteOffset( | 294 void UpdateFlowControlOnFinalReceivedByteOffset( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // Called in OnConfigNegotiated when we receive a new stream level flow | 364 // Called in OnConfigNegotiated when we receive a new stream level flow |
| 366 // control window in a negotiated config. Closes the connection if invalid. | 365 // control window in a negotiated config. Closes the connection if invalid. |
| 367 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); | 366 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); |
| 368 | 367 |
| 369 // Called in OnConfigNegotiated when we receive a new connection level flow | 368 // Called in OnConfigNegotiated when we receive a new connection level flow |
| 370 // control window in a negotiated config. Closes the connection if invalid. | 369 // control window in a negotiated config. Closes the connection if invalid. |
| 371 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); | 370 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); |
| 372 | 371 |
| 373 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes | 372 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes |
| 374 // forward progress. Returns false if busy loop detected. | 373 // forward progress. Returns false if busy loop detected. |
| 375 bool CheckStreamNotBusyLooping(ReliableQuicStream* stream, | 374 bool CheckStreamNotBusyLooping(QuicStream* stream, |
| 376 uint64_t previous_bytes_written, | 375 uint64_t previous_bytes_written, |
| 377 bool previous_fin_sent); | 376 bool previous_fin_sent); |
| 378 | 377 |
| 379 // Keep track of highest received byte offset of locally closed streams, while | 378 // Keep track of highest received byte offset of locally closed streams, while |
| 380 // waiting for a definitive final highest offset from the peer. | 379 // waiting for a definitive final highest offset from the peer. |
| 381 std::map<QuicStreamId, QuicStreamOffset> | 380 std::map<QuicStreamId, QuicStreamOffset> |
| 382 locally_closed_streams_highest_offset_; | 381 locally_closed_streams_highest_offset_; |
| 383 | 382 |
| 384 QuicConnection* connection_; | 383 QuicConnection* connection_; |
| 385 | 384 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 438 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
| 440 // call stack of OnCanWrite. | 439 // call stack of OnCanWrite. |
| 441 QuicStreamId currently_writing_stream_id_; | 440 QuicStreamId currently_writing_stream_id_; |
| 442 | 441 |
| 443 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 442 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
| 444 }; | 443 }; |
| 445 | 444 |
| 446 } // namespace net | 445 } // namespace net |
| 447 | 446 |
| 448 #endif // NET_QUIC_QUIC_SESSION_H_ | 447 #endif // NET_QUIC_QUIC_SESSION_H_ |
| OLD | NEW |