| 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 when stream |id| is done waiting for acks either because all data |
| 219 // gets acked or is not interested in data being acked (which happens when |
| 220 // a stream is reset because of an error). |
| 221 void OnStreamDoneWaitingForAcks(QuicStreamId id); |
| 222 |
| 211 // Returns true if the session has data to be sent, either queued in the | 223 // Returns true if the session has data to be sent, either queued in the |
| 212 // connection, or in a write-blocked stream. | 224 // connection, or in a write-blocked stream. |
| 213 bool HasDataToWrite() const; | 225 bool HasDataToWrite() const; |
| 214 | 226 |
| 215 bool goaway_sent() const; | 227 bool goaway_sent() const; |
| 216 | 228 |
| 217 bool goaway_received() const; | 229 bool goaway_received() const; |
| 218 | 230 |
| 219 QuicErrorCode error() const { return error_; } | 231 QuicErrorCode error() const { return error_; } |
| 220 | 232 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 247 // Mark a stream as draining. | 259 // Mark a stream as draining. |
| 248 virtual void StreamDraining(QuicStreamId id); | 260 virtual void StreamDraining(QuicStreamId id); |
| 249 | 261 |
| 250 // Returns true if this stream should yield writes to another blocked stream. | 262 // Returns true if this stream should yield writes to another blocked stream. |
| 251 bool ShouldYield(QuicStreamId stream_id); | 263 bool ShouldYield(QuicStreamId stream_id); |
| 252 | 264 |
| 253 void set_respect_goaway(bool respect_goaway) { | 265 void set_respect_goaway(bool respect_goaway) { |
| 254 respect_goaway_ = respect_goaway; | 266 respect_goaway_ = respect_goaway; |
| 255 } | 267 } |
| 256 | 268 |
| 269 bool use_stream_notifier() const { return use_stream_notifier_; } |
| 270 |
| 257 protected: | 271 protected: |
| 258 using StaticStreamMap = QuicSmallMap<QuicStreamId, QuicStream*, 2>; | 272 using StaticStreamMap = QuicSmallMap<QuicStreamId, QuicStream*, 2>; |
| 259 | 273 |
| 260 using DynamicStreamMap = | 274 using DynamicStreamMap = |
| 261 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; | 275 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
| 262 | 276 |
| 263 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; | 277 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; |
| 264 | 278 |
| 279 using ZombieStreamMap = |
| 280 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
| 281 |
| 265 // TODO(ckrasic) - For all *DynamicStream2 below, rename after | 282 // TODO(ckrasic) - For all *DynamicStream2 below, rename after |
| 266 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. | 283 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. |
| 267 | 284 |
| 268 // Returns true if an incoming stream can be created. | 285 // Returns true if an incoming stream can be created. |
| 269 virtual bool ShouldCreateIncomingDynamicStream2(QuicStreamId id); | 286 virtual bool ShouldCreateIncomingDynamicStream2(QuicStreamId id); |
| 270 | 287 |
| 271 // Returns true if an outgoing stream can be created. | 288 // Returns true if an outgoing stream can be created. |
| 272 virtual bool ShouldCreateOutgoingDynamicStream2(); | 289 virtual bool ShouldCreateOutgoingDynamicStream2(); |
| 273 | 290 |
| 274 // Creates a new stream to handle a peer-initiated stream. | 291 // 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_; } | 357 StaticStreamMap& static_streams() { return static_stream_map_; } |
| 341 const StaticStreamMap& static_streams() const { return static_stream_map_; } | 358 const StaticStreamMap& static_streams() const { return static_stream_map_; } |
| 342 | 359 |
| 343 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } | 360 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } |
| 344 const DynamicStreamMap& dynamic_streams() const { | 361 const DynamicStreamMap& dynamic_streams() const { |
| 345 return dynamic_stream_map_; | 362 return dynamic_stream_map_; |
| 346 } | 363 } |
| 347 | 364 |
| 348 ClosedStreams* closed_streams() { return &closed_streams_; } | 365 ClosedStreams* closed_streams() { return &closed_streams_; } |
| 349 | 366 |
| 367 const ZombieStreamMap& zombie_streams() const { return zombie_streams_; } |
| 368 |
| 350 void set_max_open_incoming_streams(size_t max_open_incoming_streams); | 369 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); | 370 void set_max_open_outgoing_streams(size_t max_open_outgoing_streams); |
| 352 | 371 |
| 353 void set_largest_peer_created_stream_id( | 372 void set_largest_peer_created_stream_id( |
| 354 QuicStreamId largest_peer_created_stream_id) { | 373 QuicStreamId largest_peer_created_stream_id) { |
| 355 largest_peer_created_stream_id_ = largest_peer_created_stream_id; | 374 largest_peer_created_stream_id_ = largest_peer_created_stream_id; |
| 356 } | 375 } |
| 357 void set_error(QuicErrorCode error) { error_ = error; } | 376 void set_error(QuicErrorCode error) { error_ = error; } |
| 358 QuicWriteBlockedList* write_blocked_streams() { | 377 QuicWriteBlockedList* write_blocked_streams() { |
| 359 return &write_blocked_streams_; | 378 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 | 428 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes |
| 410 // forward progress. Returns false if busy loop detected. | 429 // forward progress. Returns false if busy loop detected. |
| 411 bool CheckStreamNotBusyLooping(QuicStream* stream, | 430 bool CheckStreamNotBusyLooping(QuicStream* stream, |
| 412 uint64_t previous_bytes_written, | 431 uint64_t previous_bytes_written, |
| 413 bool previous_fin_sent); | 432 bool previous_fin_sent); |
| 414 | 433 |
| 415 // Called in OnConfigNegotiated for Finch trials to measure performance of | 434 // Called in OnConfigNegotiated for Finch trials to measure performance of |
| 416 // starting with larger flow control receive windows. | 435 // starting with larger flow control receive windows. |
| 417 void AdjustInitialFlowControlWindows(size_t stream_window); | 436 void AdjustInitialFlowControlWindows(size_t stream_window); |
| 418 | 437 |
| 438 // Find stream with |id|, returns nullptr if the stream does not exist or |
| 439 // closed. |
| 440 QuicStream* GetStream(QuicStreamId id) const; |
| 441 |
| 419 // Keep track of highest received byte offset of locally closed streams, while | 442 // Keep track of highest received byte offset of locally closed streams, while |
| 420 // waiting for a definitive final highest offset from the peer. | 443 // waiting for a definitive final highest offset from the peer. |
| 421 std::map<QuicStreamId, QuicStreamOffset> | 444 std::map<QuicStreamId, QuicStreamOffset> |
| 422 locally_closed_streams_highest_offset_; | 445 locally_closed_streams_highest_offset_; |
| 423 | 446 |
| 424 QuicConnection* connection_; | 447 QuicConnection* connection_; |
| 425 | 448 |
| 426 // May be null. | 449 // May be null. |
| 427 Visitor* visitor_; | 450 Visitor* visitor_; |
| 428 | 451 |
| 429 ClosedStreams closed_streams_; | 452 ClosedStreams closed_streams_; |
| 430 | 453 |
| 454 // Streams which are closed, but need to be kept alive. Currently, the only |
| 455 // reason is the stream's sent data (including FIN) does not get fully acked. |
| 456 ZombieStreamMap zombie_streams_; |
| 457 |
| 431 QuicConfig config_; | 458 QuicConfig config_; |
| 432 | 459 |
| 433 // The maximum number of outgoing streams this connection can open. | 460 // The maximum number of outgoing streams this connection can open. |
| 434 size_t max_open_outgoing_streams_; | 461 size_t max_open_outgoing_streams_; |
| 435 | 462 |
| 436 // The maximum number of incoming streams this connection will allow. | 463 // The maximum number of incoming streams this connection will allow. |
| 437 size_t max_open_incoming_streams_; | 464 size_t max_open_incoming_streams_; |
| 438 | 465 |
| 439 // Static streams, such as crypto and header streams. Owned by child classes | 466 // Static streams, such as crypto and header streams. Owned by child classes |
| 440 // that create these streams. | 467 // that create these streams. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 505 |
| 479 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 506 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
| 480 // call stack of OnCanWrite. | 507 // call stack of OnCanWrite. |
| 481 QuicStreamId currently_writing_stream_id_; | 508 QuicStreamId currently_writing_stream_id_; |
| 482 | 509 |
| 483 // If this is set to false, the session will ignore peer GOAWAYs and | 510 // If this is set to false, the session will ignore peer GOAWAYs and |
| 484 // allow the creation of outgoing streams regardless of the high | 511 // allow the creation of outgoing streams regardless of the high |
| 485 // chance they will fail. | 512 // chance they will fail. |
| 486 bool respect_goaway_; | 513 bool respect_goaway_; |
| 487 | 514 |
| 515 // This session is notified on every ack or loss. |
| 516 const bool use_stream_notifier_; |
| 517 |
| 488 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 518 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
| 489 }; | 519 }; |
| 490 | 520 |
| 491 } // namespace net | 521 } // namespace net |
| 492 | 522 |
| 493 #endif // NET_QUIC_CORE_QUIC_SESSION_H_ | 523 #endif // NET_QUIC_CORE_QUIC_SESSION_H_ |
| OLD | NEW |