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 13 matching lines...) Expand all Loading... |
24 #include "net/quic/quic_packet_creator.h" | 24 #include "net/quic/quic_packet_creator.h" |
25 #include "net/quic/quic_protocol.h" | 25 #include "net/quic/quic_protocol.h" |
26 #include "net/quic/quic_write_blocked_list.h" | 26 #include "net/quic/quic_write_blocked_list.h" |
27 #include "net/quic/reliable_quic_stream.h" | 27 #include "net/quic/reliable_quic_stream.h" |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 | 30 |
31 class QuicCryptoStream; | 31 class QuicCryptoStream; |
32 class QuicFlowController; | 32 class QuicFlowController; |
33 class ReliableQuicStream; | 33 class ReliableQuicStream; |
34 class VisitorShim; | |
35 | 34 |
36 namespace test { | 35 namespace test { |
37 class QuicSessionPeer; | 36 class QuicSessionPeer; |
38 } // namespace test | 37 } // namespace test |
39 | 38 |
40 class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { | 39 class NET_EXPORT_PRIVATE QuicSession : public QuicConnectionVisitorInterface { |
41 public: | 40 public: |
42 // CryptoHandshakeEvent enumerates the events generated by a QuicCryptoStream. | 41 // CryptoHandshakeEvent enumerates the events generated by a QuicCryptoStream. |
43 enum CryptoHandshakeEvent { | 42 enum CryptoHandshakeEvent { |
44 // ENCRYPTION_FIRST_ESTABLISHED indicates that a full client hello has been | 43 // ENCRYPTION_FIRST_ESTABLISHED indicates that a full client hello has been |
(...skipping 23 matching lines...) Expand all Loading... |
68 void OnRstStream(const QuicRstStreamFrame& frame) override; | 67 void OnRstStream(const QuicRstStreamFrame& frame) override; |
69 void OnGoAway(const QuicGoAwayFrame& frame) override; | 68 void OnGoAway(const QuicGoAwayFrame& frame) override; |
70 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | 69 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
71 void OnBlockedFrame(const QuicBlockedFrame& frame) override; | 70 void OnBlockedFrame(const QuicBlockedFrame& frame) override; |
72 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override; | 71 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override; |
73 void OnWriteBlocked() override {} | 72 void OnWriteBlocked() override {} |
74 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override; | 73 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override; |
75 void OnCanWrite() override; | 74 void OnCanWrite() override; |
76 void OnCongestionWindowChange(QuicTime /*now*/) override {} | 75 void OnCongestionWindowChange(QuicTime /*now*/) override {} |
77 void OnConnectionMigration() override {} | 76 void OnConnectionMigration() override {} |
| 77 // Deletes streams that are safe to be deleted now that it's safe to do so (no |
| 78 // other operations are being done on the streams at this time). |
| 79 void PostProcessAfterData() override; |
78 bool WillingAndAbleToWrite() const override; | 80 bool WillingAndAbleToWrite() const override; |
79 bool HasPendingHandshake() const override; | 81 bool HasPendingHandshake() const override; |
80 bool HasOpenDynamicStreams() const override; | 82 bool HasOpenDynamicStreams() const override; |
81 | 83 |
82 // Called on every incoming packet. Passes |packet| through to |connection_|. | 84 // Called on every incoming packet. Passes |packet| through to |connection_|. |
83 virtual void ProcessUdpPacket(const IPEndPoint& self_address, | 85 virtual void ProcessUdpPacket(const IPEndPoint& self_address, |
84 const IPEndPoint& peer_address, | 86 const IPEndPoint& peer_address, |
85 const QuicEncryptedPacket& packet); | 87 const QuicEncryptedPacket& packet); |
86 | 88 |
87 // Called by streams when they want to write data to the peer. | 89 // Called by streams when they want to write data to the peer. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Returns the stream ID for a new outgoing stream, and increments the | 243 // Returns the stream ID for a new outgoing stream, and increments the |
242 // underlying counter. | 244 // underlying counter. |
243 QuicStreamId GetNextOutgoingStreamId(); | 245 QuicStreamId GetNextOutgoingStreamId(); |
244 | 246 |
245 // Returns existing stream with id = |stream_id|. If no such stream exists, | 247 // Returns existing stream with id = |stream_id|. If no such stream exists, |
246 // and |stream_id| is a peer-created id, then a new stream is created and | 248 // and |stream_id| is a peer-created id, then a new stream is created and |
247 // returned. However if |stream_id| is a locally-created id and no such stream | 249 // returned. However if |stream_id| is a locally-created id and no such stream |
248 // exists, the connection is closed. | 250 // exists, the connection is closed. |
249 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id); | 251 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id); |
250 | 252 |
251 // This is called after every call other than OnConnectionClose from the | |
252 // QuicConnectionVisitor to allow post-processing once the work has been done. | |
253 // In this case, it deletes streams given that it's safe to do so (no other | |
254 // operations are being done on the streams at this time) | |
255 virtual void PostProcessAfterData(); | |
256 | |
257 // Performs the work required to close |stream_id|. If |locally_reset| | 253 // Performs the work required to close |stream_id|. If |locally_reset| |
258 // then the stream has been reset by this endpoint, not by the peer. | 254 // then the stream has been reset by this endpoint, not by the peer. |
259 virtual void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); | 255 virtual void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); |
260 | 256 |
261 // When a stream is closed locally, it may not yet know how many bytes the | 257 // When a stream is closed locally, it may not yet know how many bytes the |
262 // peer sent on that stream. | 258 // peer sent on that stream. |
263 // When this data arrives (via stream frame w. FIN, or RST) this method | 259 // When this data arrives (via stream frame w. FIN, or RST) this method |
264 // is called, and correctly updates the connection level flow controller. | 260 // is called, and correctly updates the connection level flow controller. |
265 void UpdateFlowControlOnFinalReceivedByteOffset( | 261 void UpdateFlowControlOnFinalReceivedByteOffset( |
266 QuicStreamId id, | 262 QuicStreamId id, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, | 315 void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, |
320 QuicStreamOffset offset); | 316 QuicStreamOffset offset); |
321 // If stream is a locally closed stream, this RST will update FIN offset. | 317 // If stream is a locally closed stream, this RST will update FIN offset. |
322 // Otherwise stream is a preserved stream and the behavior of it depends on | 318 // Otherwise stream is a preserved stream and the behavior of it depends on |
323 // derived class's own implementation. | 319 // derived class's own implementation. |
324 virtual void HandleRstOnValidNonexistentStream( | 320 virtual void HandleRstOnValidNonexistentStream( |
325 const QuicRstStreamFrame& frame); | 321 const QuicRstStreamFrame& frame); |
326 | 322 |
327 private: | 323 private: |
328 friend class test::QuicSessionPeer; | 324 friend class test::QuicSessionPeer; |
329 friend class VisitorShim; | |
330 | 325 |
331 // Called in OnConfigNegotiated when we receive a new stream level flow | 326 // Called in OnConfigNegotiated when we receive a new stream level flow |
332 // control window in a negotiated config. Closes the connection if invalid. | 327 // control window in a negotiated config. Closes the connection if invalid. |
333 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); | 328 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); |
334 | 329 |
335 // Called in OnConfigNegotiated when we receive a new connection level flow | 330 // Called in OnConfigNegotiated when we receive a new connection level flow |
336 // control window in a negotiated config. Closes the connection if invalid. | 331 // control window in a negotiated config. Closes the connection if invalid. |
337 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); | 332 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); |
338 | 333 |
339 // Called in OnConfigNegotiated when auto-tuning is enabled for flow | 334 // Called in OnConfigNegotiated when auto-tuning is enabled for flow |
340 // control receive windows. | 335 // control receive windows. |
341 void EnableAutoTuneReceiveWindow(); | 336 void EnableAutoTuneReceiveWindow(); |
342 | 337 |
343 // Called in OnConfigNegotiated for finch trials to measure performance of | 338 // Called in OnConfigNegotiated for finch trials to measure performance of |
344 // starting with smaller flow control receive windows and auto-tuning. | 339 // starting with smaller flow control receive windows and auto-tuning. |
345 void AdjustInitialFlowControlWindows(size_t stream_window); | 340 void AdjustInitialFlowControlWindows(size_t stream_window); |
346 | 341 |
347 // Keep track of highest received byte offset of locally closed streams, while | 342 // Keep track of highest received byte offset of locally closed streams, while |
348 // waiting for a definitive final highest offset from the peer. | 343 // waiting for a definitive final highest offset from the peer. |
349 std::map<QuicStreamId, QuicStreamOffset> | 344 std::map<QuicStreamId, QuicStreamOffset> |
350 locally_closed_streams_highest_offset_; | 345 locally_closed_streams_highest_offset_; |
351 | 346 |
352 scoped_ptr<QuicConnection> connection_; | 347 scoped_ptr<QuicConnection> connection_; |
353 | 348 |
354 // A shim to stand between the connection and the session, to handle stream | |
355 // deletions. | |
356 scoped_ptr<VisitorShim> visitor_shim_; | |
357 | |
358 std::vector<ReliableQuicStream*> closed_streams_; | 349 std::vector<ReliableQuicStream*> closed_streams_; |
359 | 350 |
360 QuicConfig config_; | 351 QuicConfig config_; |
361 | 352 |
362 // Returns the maximum number of streams this connection can open. | 353 // Returns the maximum number of streams this connection can open. |
363 size_t max_open_streams_; | 354 size_t max_open_streams_; |
364 | 355 |
365 // Static streams, such as crypto and header streams. Owned by child classes | 356 // Static streams, such as crypto and header streams. Owned by child classes |
366 // that create these streams. | 357 // that create these streams. |
367 StreamMap static_stream_map_; | 358 StreamMap static_stream_map_; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 396 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
406 // call stack of OnCanWrite. | 397 // call stack of OnCanWrite. |
407 QuicStreamId currently_writing_stream_id_; | 398 QuicStreamId currently_writing_stream_id_; |
408 | 399 |
409 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 400 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
410 }; | 401 }; |
411 | 402 |
412 } // namespace net | 403 } // namespace net |
413 | 404 |
414 #endif // NET_QUIC_QUIC_SESSION_H_ | 405 #endif // NET_QUIC_QUIC_SESSION_H_ |
OLD | NEW |