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 #include "net/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "net/quic/crypto/proof_verifier.h" | 8 #include "net/quic/crypto/proof_verifier.h" |
9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
11 #include "net/quic/quic_flow_controller.h" | 11 #include "net/quic/quic_flow_controller.h" |
12 #include "net/quic/quic_headers_stream.h" | 12 #include "net/quic/quic_headers_stream.h" |
13 #include "net/ssl/ssl_info.h" | 13 #include "net/ssl/ssl_info.h" |
14 | 14 |
15 using base::StringPiece; | 15 using base::StringPiece; |
16 using base::hash_map; | 16 using base::hash_map; |
17 using base::hash_set; | 17 using base::hash_set; |
18 using std::make_pair; | 18 using std::make_pair; |
| 19 using std::max; |
19 using std::vector; | 20 using std::vector; |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 #define ENDPOINT (is_server() ? "Server: " : " Client: ") | 24 #define ENDPOINT (is_server() ? "Server: " : " Client: ") |
24 | 25 |
25 // We want to make sure we delete any closed streams in a safe manner. | 26 // We want to make sure we delete any closed streams in a safe manner. |
26 // To avoid deleting a stream in mid-operation, we have a simple shim between | 27 // To avoid deleting a stream in mid-operation, we have a simple shim between |
27 // us and the stream, so we can delete any streams when we return from | 28 // us and the stream, so we can delete any streams when we return from |
28 // processing. | 29 // processing. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 97 } |
97 | 98 |
98 private: | 99 private: |
99 QuicSession* session_; | 100 QuicSession* session_; |
100 }; | 101 }; |
101 | 102 |
102 QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) | 103 QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) |
103 : connection_(connection), | 104 : connection_(connection), |
104 visitor_shim_(new VisitorShim(this)), | 105 visitor_shim_(new VisitorShim(this)), |
105 config_(config), | 106 config_(config), |
106 max_open_streams_(config_.max_streams_per_connection()), | 107 max_open_streams_(config_.MaxStreamsPerConnection()), |
107 next_stream_id_(is_server() ? 2 : 5), | 108 next_stream_id_(is_server() ? 2 : 5), |
108 largest_peer_created_stream_id_(0), | 109 largest_peer_created_stream_id_(0), |
109 error_(QUIC_NO_ERROR), | 110 error_(QUIC_NO_ERROR), |
110 goaway_received_(false), | 111 goaway_received_(false), |
111 goaway_sent_(false), | 112 goaway_sent_(false), |
112 has_pending_handshake_(false) { | 113 has_pending_handshake_(false) { |
113 if (connection_->version() <= QUIC_VERSION_19) { | 114 if (connection_->version() <= QUIC_VERSION_19) { |
114 flow_controller_.reset(new QuicFlowController( | 115 flow_controller_.reset(new QuicFlowController( |
115 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow, | 116 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow, |
116 config_.GetInitialFlowControlWindowToSend(), | 117 config_.GetInitialFlowControlWindowToSend(), |
117 config_.GetInitialFlowControlWindowToSend())); | 118 config_.GetInitialFlowControlWindowToSend())); |
118 } else { | 119 } else { |
119 flow_controller_.reset(new QuicFlowController( | 120 flow_controller_.reset(new QuicFlowController( |
120 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow, | 121 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow, |
121 config_.GetInitialSessionFlowControlWindowToSend(), | 122 config_.GetInitialSessionFlowControlWindowToSend(), |
122 config_.GetInitialSessionFlowControlWindowToSend())); | 123 config_.GetInitialSessionFlowControlWindowToSend())); |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
126 void QuicSession::InitializeSession() { | 127 void QuicSession::InitializeSession() { |
127 connection_->set_visitor(visitor_shim_.get()); | 128 connection_->set_visitor(visitor_shim_.get()); |
128 connection_->SetFromConfig(config_); | 129 connection_->SetFromConfig(config_); |
129 if (connection_->connected()) { | 130 if (!FLAGS_quic_unified_timeouts && connection_->connected()) { |
130 connection_->SetOverallConnectionTimeout( | 131 connection_->SetOverallConnectionTimeout( |
131 config_.max_time_before_crypto_handshake()); | 132 config_.max_time_before_crypto_handshake()); |
132 } | 133 } |
133 headers_stream_.reset(new QuicHeadersStream(this)); | 134 headers_stream_.reset(new QuicHeadersStream(this)); |
134 } | 135 } |
135 | 136 |
136 QuicSession::~QuicSession() { | 137 QuicSession::~QuicSession() { |
137 STLDeleteElements(&closed_streams_); | 138 STLDeleteElements(&closed_streams_); |
138 STLDeleteValues(&stream_map_); | 139 STLDeleteValues(&stream_map_); |
139 | 140 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 465 } |
465 | 466 |
466 bool QuicSession::IsCryptoHandshakeConfirmed() { | 467 bool QuicSession::IsCryptoHandshakeConfirmed() { |
467 return GetCryptoStream()->handshake_confirmed(); | 468 return GetCryptoStream()->handshake_confirmed(); |
468 } | 469 } |
469 | 470 |
470 void QuicSession::OnConfigNegotiated() { | 471 void QuicSession::OnConfigNegotiated() { |
471 connection_->SetFromConfig(config_); | 472 connection_->SetFromConfig(config_); |
472 QuicVersion version = connection()->version(); | 473 QuicVersion version = connection()->version(); |
473 | 474 |
474 // A server should accept a small number of additional streams beyond the | |
475 // limit sent to the client. This helps avoid early connection termination | |
476 // when FIN/RSTs for old streams are lost or arrive out of order. | |
477 if (FLAGS_quic_allow_more_open_streams) { | 475 if (FLAGS_quic_allow_more_open_streams) { |
478 set_max_open_streams((is_server() ? kMaxStreamsMultiplier : 1.0) * | 476 uint32 max_streams = config_.MaxStreamsPerConnection(); |
479 config_.max_streams_per_connection()); | 477 if (is_server()) { |
480 } | 478 // A server should accept a small number of additional streams beyond the |
481 | 479 // limit sent to the client. This helps avoid early connection termination |
482 if (version <= QUIC_VERSION_16) { | 480 // when FIN/RSTs for old streams are lost or arrive out of order. |
483 return; | 481 // Use a minimum number of additional streams, or a percentage increase, |
| 482 // whichever is larger. |
| 483 max_streams = |
| 484 max(max_streams + kMaxStreamsMinimumIncrement, |
| 485 static_cast<uint32>(max_streams * kMaxStreamsMultiplier)); |
| 486 } |
| 487 set_max_open_streams(max_streams); |
484 } | 488 } |
485 | 489 |
486 if (version <= QUIC_VERSION_19) { | 490 if (version <= QUIC_VERSION_19) { |
487 // QUIC_VERSION_17,18,19 don't support independent stream/session flow | 491 // QUIC_VERSION_17,18,19 don't support independent stream/session flow |
488 // control windows. | 492 // control windows. |
489 if (config_.HasReceivedInitialFlowControlWindowBytes()) { | 493 if (config_.HasReceivedInitialFlowControlWindowBytes()) { |
490 // Streams which were created before the SHLO was received (0-RTT | 494 // Streams which were created before the SHLO was received (0-RTT |
491 // requests) are now informed of the peer's initial flow control window. | 495 // requests) are now informed of the peer's initial flow control window. |
492 uint32 new_window = config_.ReceivedInitialFlowControlWindowBytes(); | 496 uint32 new_window = config_.ReceivedInitialFlowControlWindowBytes(); |
493 OnNewStreamFlowControlWindow(new_window); | 497 OnNewStreamFlowControlWindow(new_window); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 // decrypted by the peer. | 563 // decrypted by the peer. |
560 connection_->RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); | 564 connection_->RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); |
561 break; | 565 break; |
562 | 566 |
563 case HANDSHAKE_CONFIRMED: | 567 case HANDSHAKE_CONFIRMED: |
564 LOG_IF(DFATAL, !config_.negotiated()) << ENDPOINT | 568 LOG_IF(DFATAL, !config_.negotiated()) << ENDPOINT |
565 << "Handshake confirmed without parameter negotiation."; | 569 << "Handshake confirmed without parameter negotiation."; |
566 // Discard originally encrypted packets, since they can't be decrypted by | 570 // Discard originally encrypted packets, since they can't be decrypted by |
567 // the peer. | 571 // the peer. |
568 connection_->NeuterUnencryptedPackets(); | 572 connection_->NeuterUnencryptedPackets(); |
569 connection_->SetOverallConnectionTimeout(QuicTime::Delta::Infinite()); | 573 if (!FLAGS_quic_unified_timeouts) { |
| 574 connection_->SetOverallConnectionTimeout(QuicTime::Delta::Infinite()); |
| 575 } |
570 if (!FLAGS_quic_allow_more_open_streams) { | 576 if (!FLAGS_quic_allow_more_open_streams) { |
571 max_open_streams_ = config_.max_streams_per_connection(); | 577 max_open_streams_ = config_.MaxStreamsPerConnection(); |
572 } | 578 } |
573 break; | 579 break; |
574 | 580 |
575 default: | 581 default: |
576 LOG(ERROR) << ENDPOINT << "Got unknown handshake event: " << event; | 582 LOG(ERROR) << ENDPOINT << "Got unknown handshake event: " << event; |
577 } | 583 } |
578 } | 584 } |
579 | 585 |
580 void QuicSession::OnCryptoHandshakeMessageSent( | 586 void QuicSession::OnCryptoHandshakeMessageSent( |
581 const CryptoHandshakeMessage& message) { | 587 const CryptoHandshakeMessage& message) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 if (version < QUIC_VERSION_19) { | 773 if (version < QUIC_VERSION_19) { |
768 flow_controller_->Disable(); | 774 flow_controller_->Disable(); |
769 } | 775 } |
770 | 776 |
771 // Disable stream level flow control based on negotiated version. Streams may | 777 // Disable stream level flow control based on negotiated version. Streams may |
772 // have been created with a different version. | 778 // have been created with a different version. |
773 if (version < QUIC_VERSION_21) { | 779 if (version < QUIC_VERSION_21) { |
774 GetCryptoStream()->flow_controller()->Disable(); | 780 GetCryptoStream()->flow_controller()->Disable(); |
775 headers_stream_->flow_controller()->Disable(); | 781 headers_stream_->flow_controller()->Disable(); |
776 } | 782 } |
777 for (DataStreamMap::iterator it = stream_map_.begin(); | |
778 it != stream_map_.end(); ++it) { | |
779 if (version <= QUIC_VERSION_16) { | |
780 it->second->flow_controller()->Disable(); | |
781 } | |
782 } | |
783 } | 783 } |
784 | 784 |
785 } // namespace net | 785 } // namespace net |
OLD | NEW |