| 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> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class QuicCryptoStream; | 34 class QuicCryptoStream; |
| 35 class QuicFlowController; | 35 class QuicFlowController; |
| 36 class ReliableQuicStream; | 36 class ReliableQuicStream; |
| 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. |
| 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. |
| 47 class Visitor { |
| 48 public: |
| 49 virtual ~Visitor() {} |
| 50 |
| 51 // Called when the connection is closed after the streams have been closed. |
| 52 virtual void OnConnectionClosed(QuicConnectionId connection_id, |
| 53 QuicErrorCode error, |
| 54 const std::string& error_details) = 0; |
| 55 |
| 56 // Called when the session has become write blocked. |
| 57 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; |
| 58 }; |
| 59 |
| 44 // CryptoHandshakeEvent enumerates the events generated by a QuicCryptoStream. | 60 // CryptoHandshakeEvent enumerates the events generated by a QuicCryptoStream. |
| 45 enum CryptoHandshakeEvent { | 61 enum CryptoHandshakeEvent { |
| 46 // ENCRYPTION_FIRST_ESTABLISHED indicates that a full client hello has been | 62 // ENCRYPTION_FIRST_ESTABLISHED indicates that a full client hello has been |
| 47 // sent by a client and that subsequent packets will be encrypted. (Client | 63 // sent by a client and that subsequent packets will be encrypted. (Client |
| 48 // only.) | 64 // only.) |
| 49 ENCRYPTION_FIRST_ESTABLISHED, | 65 ENCRYPTION_FIRST_ESTABLISHED, |
| 50 // ENCRYPTION_REESTABLISHED indicates that a client hello was rejected by | 66 // ENCRYPTION_REESTABLISHED indicates that a client hello was rejected by |
| 51 // the server and thus the encryption key has been updated. Therefore the | 67 // the server and thus the encryption key has been updated. Therefore the |
| 52 // connection should resend any packets that were sent under | 68 // connection should resend any packets that were sent under |
| 53 // ENCRYPTION_INITIAL. (Client only.) | 69 // ENCRYPTION_INITIAL. (Client only.) |
| 54 ENCRYPTION_REESTABLISHED, | 70 ENCRYPTION_REESTABLISHED, |
| 55 // HANDSHAKE_CONFIRMED, in a client, indicates the the server has accepted | 71 // HANDSHAKE_CONFIRMED, in a client, indicates the the server has accepted |
| 56 // our handshake. In a server it indicates that a full, valid client hello | 72 // our handshake. In a server it indicates that a full, valid client hello |
| 57 // has been received. (Client and server.) | 73 // has been received. (Client and server.) |
| 58 HANDSHAKE_CONFIRMED, | 74 HANDSHAKE_CONFIRMED, |
| 59 }; | 75 }; |
| 60 | 76 |
| 61 // Does not take ownership of |connection|. | 77 // Does not take ownership of |connection| or |visitor|. |
| 62 QuicSession(QuicConnection* connection, const QuicConfig& config); | 78 QuicSession(QuicConnection* connection, |
| 79 Visitor* owner, |
| 80 const QuicConfig& config); |
| 63 | 81 |
| 64 ~QuicSession() override; | 82 ~QuicSession() override; |
| 65 | 83 |
| 66 virtual void Initialize(); | 84 virtual void Initialize(); |
| 67 | 85 |
| 68 // QuicConnectionVisitorInterface methods: | 86 // QuicConnectionVisitorInterface methods: |
| 69 void OnStreamFrame(const QuicStreamFrame& frame) override; | 87 void OnStreamFrame(const QuicStreamFrame& frame) override; |
| 70 void OnRstStream(const QuicRstStreamFrame& frame) override; | 88 void OnRstStream(const QuicRstStreamFrame& frame) override; |
| 71 void OnGoAway(const QuicGoAwayFrame& frame) override; | 89 void OnGoAway(const QuicGoAwayFrame& frame) override; |
| 72 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | 90 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 73 void OnBlockedFrame(const QuicBlockedFrame& frame) override; | 91 void OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 74 void OnConnectionClosed(QuicErrorCode error, | 92 void OnConnectionClosed(QuicErrorCode error, |
| 75 const std::string& error_details, | 93 const std::string& error_details, |
| 76 ConnectionCloseSource source) override; | 94 ConnectionCloseSource source) override; |
| 77 void OnWriteBlocked() override {} | 95 void OnWriteBlocked() override; |
| 78 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override; | 96 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override; |
| 79 void OnCanWrite() override; | 97 void OnCanWrite() override; |
| 80 void OnCongestionWindowChange(QuicTime /*now*/) override {} | 98 void OnCongestionWindowChange(QuicTime /*now*/) override {} |
| 81 void OnConnectionMigration(PeerAddressChangeType type) override {} | 99 void OnConnectionMigration(PeerAddressChangeType type) override {} |
| 82 // Deletes streams that are safe to be deleted now that it's safe to do so (no | 100 // Deletes streams that are safe to be deleted now that it's safe to do so (no |
| 83 // other operations are being done on the streams at this time). | 101 // other operations are being done on the streams at this time). |
| 84 void PostProcessAfterData() override; | 102 void PostProcessAfterData() override; |
| 85 bool WillingAndAbleToWrite() const override; | 103 bool WillingAndAbleToWrite() const override; |
| 86 bool HasPendingHandshake() const override; | 104 bool HasPendingHandshake() const override; |
| 87 bool HasOpenDynamicStreams() const override; | 105 bool HasOpenDynamicStreams() const override; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId stream_id); | 348 bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId stream_id); |
| 331 | 349 |
| 332 void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, | 350 void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, |
| 333 QuicStreamOffset offset); | 351 QuicStreamOffset offset); |
| 334 // If stream is a locally closed stream, this RST will update FIN offset. | 352 // If stream is a locally closed stream, this RST will update FIN offset. |
| 335 // Otherwise stream is a preserved stream and the behavior of it depends on | 353 // Otherwise stream is a preserved stream and the behavior of it depends on |
| 336 // derived class's own implementation. | 354 // derived class's own implementation. |
| 337 virtual void HandleRstOnValidNonexistentStream( | 355 virtual void HandleRstOnValidNonexistentStream( |
| 338 const QuicRstStreamFrame& frame); | 356 const QuicRstStreamFrame& frame); |
| 339 | 357 |
| 358 Visitor* visitor() { return visitor_; } |
| 359 |
| 360 const Visitor* visitor() const { return visitor_; } |
| 361 |
| 340 private: | 362 private: |
| 341 friend class test::QuicSessionPeer; | 363 friend class test::QuicSessionPeer; |
| 342 | 364 |
| 343 // Called in OnConfigNegotiated when we receive a new stream level flow | 365 // Called in OnConfigNegotiated when we receive a new stream level flow |
| 344 // control window in a negotiated config. Closes the connection if invalid. | 366 // control window in a negotiated config. Closes the connection if invalid. |
| 345 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); | 367 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); |
| 346 | 368 |
| 347 // Called in OnConfigNegotiated when we receive a new connection level flow | 369 // Called in OnConfigNegotiated when we receive a new connection level flow |
| 348 // control window in a negotiated config. Closes the connection if invalid. | 370 // control window in a negotiated config. Closes the connection if invalid. |
| 349 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); | 371 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); |
| 350 | 372 |
| 351 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes | 373 // Debug helper for |OnCanWrite()|, check that OnStreamWrite() makes |
| 352 // forward progress. Returns false if busy loop detected. | 374 // forward progress. Returns false if busy loop detected. |
| 353 bool CheckStreamNotBusyLooping(ReliableQuicStream* stream, | 375 bool CheckStreamNotBusyLooping(ReliableQuicStream* stream, |
| 354 uint64_t previous_bytes_written, | 376 uint64_t previous_bytes_written, |
| 355 bool previous_fin_sent); | 377 bool previous_fin_sent); |
| 356 | 378 |
| 357 // Keep track of highest received byte offset of locally closed streams, while | 379 // Keep track of highest received byte offset of locally closed streams, while |
| 358 // waiting for a definitive final highest offset from the peer. | 380 // waiting for a definitive final highest offset from the peer. |
| 359 std::map<QuicStreamId, QuicStreamOffset> | 381 std::map<QuicStreamId, QuicStreamOffset> |
| 360 locally_closed_streams_highest_offset_; | 382 locally_closed_streams_highest_offset_; |
| 361 | 383 |
| 362 QuicConnection* connection_; | 384 QuicConnection* connection_; |
| 363 | 385 |
| 386 // May be null. |
| 387 Visitor* visitor_; |
| 388 |
| 364 ClosedStreams closed_streams_; | 389 ClosedStreams closed_streams_; |
| 365 | 390 |
| 366 QuicConfig config_; | 391 QuicConfig config_; |
| 367 | 392 |
| 368 // The maximum number of outgoing streams this connection can open. | 393 // The maximum number of outgoing streams this connection can open. |
| 369 size_t max_open_outgoing_streams_; | 394 size_t max_open_outgoing_streams_; |
| 370 | 395 |
| 371 // The maximum number of incoming streams this connection will allow. | 396 // The maximum number of incoming streams this connection will allow. |
| 372 size_t max_open_incoming_streams_; | 397 size_t max_open_incoming_streams_; |
| 373 | 398 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 439 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
| 415 // call stack of OnCanWrite. | 440 // call stack of OnCanWrite. |
| 416 QuicStreamId currently_writing_stream_id_; | 441 QuicStreamId currently_writing_stream_id_; |
| 417 | 442 |
| 418 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 443 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
| 419 }; | 444 }; |
| 420 | 445 |
| 421 } // namespace net | 446 } // namespace net |
| 422 | 447 |
| 423 #endif // NET_QUIC_QUIC_SESSION_H_ | 448 #endif // NET_QUIC_QUIC_SESSION_H_ |
| OLD | NEW |