| 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_CORE_QUIC_SESSION_H_ | 7 #ifndef NET_QUIC_CORE_QUIC_SESSION_H_ |
| 8 #define NET_QUIC_CORE_QUIC_SESSION_H_ | 8 #define NET_QUIC_CORE_QUIC_SESSION_H_ |
| 9 | 9 |
| 10 #include <cstddef> | 10 #include <cstddef> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_set> | 14 #include <unordered_set> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "net/quic/core/quic_connection.h" | 19 #include "net/quic/core/quic_connection.h" |
| 20 #include "net/quic/core/quic_crypto_stream.h" | 20 #include "net/quic/core/quic_crypto_stream.h" |
| 21 #include "net/quic/core/quic_packet_creator.h" | 21 #include "net/quic/core/quic_packet_creator.h" |
| 22 #include "net/quic/core/quic_packets.h" | 22 #include "net/quic/core/quic_packets.h" |
| 23 #include "net/quic/core/quic_stream.h" | 23 #include "net/quic/core/quic_stream.h" |
| 24 #include "net/quic/core/quic_write_blocked_list.h" | 24 #include "net/quic/core/quic_write_blocked_list.h" |
| 25 #include "net/quic/core/stream_notifier_interface.h" |
| 25 #include "net/quic/platform/api/quic_containers.h" | 26 #include "net/quic/platform/api/quic_containers.h" |
| 26 #include "net/quic/platform/api/quic_export.h" | 27 #include "net/quic/platform/api/quic_export.h" |
| 27 #include "net/quic/platform/api/quic_socket_address.h" | 28 #include "net/quic/platform/api/quic_socket_address.h" |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 | 31 |
| 31 class QuicCryptoStream; | 32 class QuicCryptoStream; |
| 32 class QuicFlowController; | 33 class QuicFlowController; |
| 33 class QuicStream; | 34 class QuicStream; |
| 34 | 35 |
| 35 namespace test { | 36 namespace test { |
| 36 class QuicSessionPeer; | 37 class QuicSessionPeer; |
| 37 } // namespace test | 38 } // namespace test |
| 38 | 39 |
| 39 class QUIC_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { | 40 class QUIC_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface, |
| 41 public StreamNotifierInterface { |
| 40 public: | 42 public: |
| 41 // An interface from the session to the entity owning the session. | 43 // An interface from the session to the entity owning the session. |
| 42 // This lets the session notify its owner (the Dispatcher) when the connection | 44 // This lets the session notify its owner (the Dispatcher) when the connection |
| 43 // is closed, blocked, or added/removed from the time-wait list. | 45 // is closed, blocked, or added/removed from the time-wait list. |
| 44 class Visitor { | 46 class Visitor { |
| 45 public: | 47 public: |
| 46 virtual ~Visitor() {} | 48 virtual ~Visitor() {} |
| 47 | 49 |
| 48 // Called when the connection is closed after the streams have been closed. | 50 // Called when the connection is closed after the streams have been closed. |
| 49 virtual void OnConnectionClosed(QuicConnectionId connection_id, | 51 virtual void OnConnectionClosed(QuicConnectionId connection_id, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // Deletes streams that are safe to be deleted now that it's safe to do so (no | 102 // Deletes streams that are safe to be deleted now that it's safe to do so (no |
| 101 // other operations are being done on the streams at this time). | 103 // other operations are being done on the streams at this time). |
| 102 void PostProcessAfterData() override; | 104 void PostProcessAfterData() override; |
| 103 // Adds a connection level WINDOW_UPDATE frame. | 105 // Adds a connection level WINDOW_UPDATE frame. |
| 104 void OnAckNeedsRetransmittableFrame() override; | 106 void OnAckNeedsRetransmittableFrame() override; |
| 105 bool WillingAndAbleToWrite() const override; | 107 bool WillingAndAbleToWrite() const override; |
| 106 bool HasPendingHandshake() const override; | 108 bool HasPendingHandshake() const override; |
| 107 bool HasOpenDynamicStreams() const override; | 109 bool HasOpenDynamicStreams() const override; |
| 108 void OnPathDegrading() override; | 110 void OnPathDegrading() override; |
| 109 | 111 |
| 112 // StreamNotifierInterface methods: |
| 113 void OnStreamFrameAcked(const QuicStreamFrame& frame, |
| 114 QuicTime::Delta ack_delay_time) override; |
| 115 void OnStreamFrameRetransmitted(const QuicStreamFrame& frame) override; |
| 116 |
| 110 // Called on every incoming packet. Passes |packet| through to |connection_|. | 117 // Called on every incoming packet. Passes |packet| through to |connection_|. |
| 111 virtual void ProcessUdpPacket(const QuicSocketAddress& self_address, | 118 virtual void ProcessUdpPacket(const QuicSocketAddress& self_address, |
| 112 const QuicSocketAddress& peer_address, | 119 const QuicSocketAddress& peer_address, |
| 113 const QuicReceivedPacket& packet); | 120 const QuicReceivedPacket& packet); |
| 114 | 121 |
| 115 // Called by streams when they want to write data to the peer. | 122 // Called by streams when they want to write data to the peer. |
| 116 // Returns a pair with the number of bytes consumed from data, and a boolean | 123 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 117 // indicating if the fin bit was consumed. This does not indicate the data | 124 // indicating if the fin bit was consumed. This does not indicate the data |
| 118 // has been sent on the wire: it may have been turned into a packet and queued | 125 // has been sent on the wire: it may have been turned into a packet and queued |
| 119 // if the socket was unexpectedly blocked. | 126 // if the socket was unexpectedly blocked. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Returns the number of "available" streams, the stream ids less than | 208 // Returns the number of "available" streams, the stream ids less than |
| 202 // largest_peer_created_stream_id_ that have not yet been opened. | 209 // largest_peer_created_stream_id_ that have not yet been opened. |
| 203 size_t GetNumAvailableStreams() const; | 210 size_t GetNumAvailableStreams() const; |
| 204 | 211 |
| 205 // Add the stream to the session's write-blocked list because it is blocked by | 212 // Add the stream to the session's write-blocked list because it is blocked by |
| 206 // connection-level flow control but not by its own stream-level flow control. | 213 // connection-level flow control but not by its own stream-level flow control. |
| 207 // The stream will be given a chance to write when a connection-level | 214 // The stream will be given a chance to write when a connection-level |
| 208 // WINDOW_UPDATE arrives. | 215 // WINDOW_UPDATE arrives. |
| 209 void MarkConnectionLevelWriteBlocked(QuicStreamId id); | 216 void MarkConnectionLevelWriteBlocked(QuicStreamId id); |
| 210 | 217 |
| 218 // Called by a stream when it becomes deletable. |
| 219 void MarkStreamDeletable(QuicStreamId id); |
| 220 |
| 211 // Returns true if the session has data to be sent, either queued in the | 221 // Returns true if the session has data to be sent, either queued in the |
| 212 // connection, or in a write-blocked stream. | 222 // connection, or in a write-blocked stream. |
| 213 bool HasDataToWrite() const; | 223 bool HasDataToWrite() const; |
| 214 | 224 |
| 215 bool goaway_sent() const; | 225 bool goaway_sent() const; |
| 216 | 226 |
| 217 bool goaway_received() const; | 227 bool goaway_received() const; |
| 218 | 228 |
| 219 QuicErrorCode error() const { return error_; } | 229 QuicErrorCode error() const { return error_; } |
| 220 | 230 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 247 // Mark a stream as draining. | 257 // Mark a stream as draining. |
| 248 virtual void StreamDraining(QuicStreamId id); | 258 virtual void StreamDraining(QuicStreamId id); |
| 249 | 259 |
| 250 // Returns true if this stream should yield writes to another blocked stream. | 260 // Returns true if this stream should yield writes to another blocked stream. |
| 251 bool ShouldYield(QuicStreamId stream_id); | 261 bool ShouldYield(QuicStreamId stream_id); |
| 252 | 262 |
| 253 void set_respect_goaway(bool respect_goaway) { | 263 void set_respect_goaway(bool respect_goaway) { |
| 254 respect_goaway_ = respect_goaway; | 264 respect_goaway_ = respect_goaway; |
| 255 } | 265 } |
| 256 | 266 |
| 267 bool use_stream_notifier() const { return use_stream_notifier_; } |
| 268 |
| 257 protected: | 269 protected: |
| 258 using StaticStreamMap = QuicSmallMap<QuicStreamId, QuicStream*, 2>; | 270 using StaticStreamMap = QuicSmallMap<QuicStreamId, QuicStream*, 2>; |
| 259 | 271 |
| 260 using DynamicStreamMap = | 272 using DynamicStreamMap = |
| 261 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; | 273 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
| 262 | 274 |
| 263 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; | 275 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; |
| 264 | 276 |
| 277 using ZombieStreamMap = |
| 278 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
| 279 |
| 265 // TODO(ckrasic) - For all *DynamicStream2 below, rename after | 280 // TODO(ckrasic) - For all *DynamicStream2 below, rename after |
| 266 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. | 281 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. |
| 267 | 282 |
| 268 // Returns true if an incoming stream can be created. | 283 // Returns true if an incoming stream can be created. |
| 269 virtual bool ShouldCreateIncomingDynamicStream2(QuicStreamId id); | 284 virtual bool ShouldCreateIncomingDynamicStream2(QuicStreamId id); |
| 270 | 285 |
| 271 // Returns true if an outgoing stream can be created. | 286 // Returns true if an outgoing stream can be created. |
| 272 virtual bool ShouldCreateOutgoingDynamicStream2(); | 287 virtual bool ShouldCreateOutgoingDynamicStream2(); |
| 273 | 288 |
| 274 // Creates a new stream to handle a peer-initiated stream. | 289 // Creates a new stream to handle a peer-initiated stream. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 StaticStreamMap& static_streams() { return static_stream_map_; } | 355 StaticStreamMap& static_streams() { return static_stream_map_; } |
| 341 const StaticStreamMap& static_streams() const { return static_stream_map_; } | 356 const StaticStreamMap& static_streams() const { return static_stream_map_; } |
| 342 | 357 |
| 343 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } | 358 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } |
| 344 const DynamicStreamMap& dynamic_streams() const { | 359 const DynamicStreamMap& dynamic_streams() const { |
| 345 return dynamic_stream_map_; | 360 return dynamic_stream_map_; |
| 346 } | 361 } |
| 347 | 362 |
| 348 ClosedStreams* closed_streams() { return &closed_streams_; } | 363 ClosedStreams* closed_streams() { return &closed_streams_; } |
| 349 | 364 |
| 365 const ZombieStreamMap& zombie_streams() const { return zombie_streams_; } |
| 366 |
| 350 void set_max_open_incoming_streams(size_t max_open_incoming_streams); | 367 void set_max_open_incoming_streams(size_t max_open_incoming_streams); |
| 351 void set_max_open_outgoing_streams(size_t max_open_outgoing_streams); | 368 void set_max_open_outgoing_streams(size_t max_open_outgoing_streams); |
| 352 | 369 |
| 353 void set_largest_peer_created_stream_id( | 370 void set_largest_peer_created_stream_id( |
| 354 QuicStreamId largest_peer_created_stream_id) { | 371 QuicStreamId largest_peer_created_stream_id) { |
| 355 largest_peer_created_stream_id_ = largest_peer_created_stream_id; | 372 largest_peer_created_stream_id_ = largest_peer_created_stream_id; |
| 356 } | 373 } |
| 357 void set_error(QuicErrorCode error) { error_ = error; } | 374 void set_error(QuicErrorCode error) { error_ = error; } |
| 358 QuicWriteBlockedList* write_blocked_streams() { | 375 QuicWriteBlockedList* write_blocked_streams() { |
| 359 return &write_blocked_streams_; | 376 return &write_blocked_streams_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes | 426 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes |
| 410 // forward progress. Returns false if busy loop detected. | 427 // forward progress. Returns false if busy loop detected. |
| 411 bool CheckStreamNotBusyLooping(QuicStream* stream, | 428 bool CheckStreamNotBusyLooping(QuicStream* stream, |
| 412 uint64_t previous_bytes_written, | 429 uint64_t previous_bytes_written, |
| 413 bool previous_fin_sent); | 430 bool previous_fin_sent); |
| 414 | 431 |
| 415 // Called in OnConfigNegotiated for Finch trials to measure performance of | 432 // Called in OnConfigNegotiated for Finch trials to measure performance of |
| 416 // starting with larger flow control receive windows. | 433 // starting with larger flow control receive windows. |
| 417 void AdjustInitialFlowControlWindows(size_t stream_window); | 434 void AdjustInitialFlowControlWindows(size_t stream_window); |
| 418 | 435 |
| 436 // Find stream with |id|, returns nullptr if the stream does not exist or |
| 437 // closed. |
| 438 QuicStream* GetStream(QuicStreamId id) const; |
| 439 |
| 419 // Keep track of highest received byte offset of locally closed streams, while | 440 // Keep track of highest received byte offset of locally closed streams, while |
| 420 // waiting for a definitive final highest offset from the peer. | 441 // waiting for a definitive final highest offset from the peer. |
| 421 std::map<QuicStreamId, QuicStreamOffset> | 442 std::map<QuicStreamId, QuicStreamOffset> |
| 422 locally_closed_streams_highest_offset_; | 443 locally_closed_streams_highest_offset_; |
| 423 | 444 |
| 424 QuicConnection* connection_; | 445 QuicConnection* connection_; |
| 425 | 446 |
| 426 // May be null. | 447 // May be null. |
| 427 Visitor* visitor_; | 448 Visitor* visitor_; |
| 428 | 449 |
| 429 ClosedStreams closed_streams_; | 450 ClosedStreams closed_streams_; |
| 430 | 451 |
| 452 // Streams which are closed, but need to be kept alive. Currently, the only |
| 453 // reason is the stream's sent data (including FIN) does not get fully acked. |
| 454 ZombieStreamMap zombie_streams_; |
| 455 |
| 431 QuicConfig config_; | 456 QuicConfig config_; |
| 432 | 457 |
| 433 // The maximum number of outgoing streams this connection can open. | 458 // The maximum number of outgoing streams this connection can open. |
| 434 size_t max_open_outgoing_streams_; | 459 size_t max_open_outgoing_streams_; |
| 435 | 460 |
| 436 // The maximum number of incoming streams this connection will allow. | 461 // The maximum number of incoming streams this connection will allow. |
| 437 size_t max_open_incoming_streams_; | 462 size_t max_open_incoming_streams_; |
| 438 | 463 |
| 439 // Static streams, such as crypto and header streams. Owned by child classes | 464 // Static streams, such as crypto and header streams. Owned by child classes |
| 440 // that create these streams. | 465 // that create these streams. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 503 |
| 479 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 504 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
| 480 // call stack of OnCanWrite. | 505 // call stack of OnCanWrite. |
| 481 QuicStreamId currently_writing_stream_id_; | 506 QuicStreamId currently_writing_stream_id_; |
| 482 | 507 |
| 483 // If this is set to false, the session will ignore peer GOAWAYs and | 508 // If this is set to false, the session will ignore peer GOAWAYs and |
| 484 // allow the creation of outgoing streams regardless of the high | 509 // allow the creation of outgoing streams regardless of the high |
| 485 // chance they will fail. | 510 // chance they will fail. |
| 486 bool respect_goaway_; | 511 bool respect_goaway_; |
| 487 | 512 |
| 513 // This session is notified on every ack or loss. |
| 514 const bool use_stream_notifier_; |
| 515 |
| 488 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 516 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
| 489 }; | 517 }; |
| 490 | 518 |
| 491 } // namespace net | 519 } // namespace net |
| 492 | 520 |
| 493 #endif // NET_QUIC_CORE_QUIC_SESSION_H_ | 521 #endif // NET_QUIC_CORE_QUIC_SESSION_H_ |
| OLD | NEW |