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" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 virtual bool HasOpenDataStreams() const OVERRIDE { | 90 virtual bool HasOpenDataStreams() const OVERRIDE { |
91 return session_->HasOpenDataStreams(); | 91 return session_->HasOpenDataStreams(); |
92 } | 92 } |
93 | 93 |
94 private: | 94 private: |
95 QuicSession* session_; | 95 QuicSession* session_; |
96 }; | 96 }; |
97 | 97 |
98 QuicSession::QuicSession(QuicConnection* connection, | 98 QuicSession::QuicSession(QuicConnection* connection, const QuicConfig& config) |
99 uint32 max_flow_control_receive_window_bytes, | |
100 const QuicConfig& config) | |
101 : connection_(connection), | 99 : connection_(connection), |
102 visitor_shim_(new VisitorShim(this)), | 100 visitor_shim_(new VisitorShim(this)), |
103 config_(config), | 101 config_(config), |
104 max_open_streams_(config_.max_streams_per_connection()), | 102 max_open_streams_(config_.max_streams_per_connection()), |
105 next_stream_id_(is_server() ? 2 : 3), | 103 next_stream_id_(is_server() ? 2 : 3), |
106 largest_peer_created_stream_id_(0), | 104 largest_peer_created_stream_id_(0), |
107 error_(QUIC_NO_ERROR), | 105 error_(QUIC_NO_ERROR), |
108 goaway_received_(false), | 106 goaway_received_(false), |
109 goaway_sent_(false), | 107 goaway_sent_(false), |
110 has_pending_handshake_(false), | 108 has_pending_handshake_(false) { |
111 max_flow_control_receive_window_bytes_( | |
112 max_flow_control_receive_window_bytes) { | |
113 if (max_flow_control_receive_window_bytes_ < kDefaultFlowControlSendWindow) { | |
114 LOG(ERROR) << "Initial receive window (" | |
115 << max_flow_control_receive_window_bytes_ | |
116 << ") cannot be set lower than default (" | |
117 << kDefaultFlowControlSendWindow << ")."; | |
118 max_flow_control_receive_window_bytes_ = kDefaultFlowControlSendWindow; | |
119 } | |
120 flow_controller_.reset(new QuicFlowController( | 109 flow_controller_.reset(new QuicFlowController( |
121 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow, | 110 connection_.get(), 0, is_server(), kDefaultFlowControlSendWindow, |
122 max_flow_control_receive_window_bytes_, | 111 config_.GetInitialFlowControlWindowToSend(), |
123 max_flow_control_receive_window_bytes_)); | 112 config_.GetInitialFlowControlWindowToSend())); |
124 | 113 |
125 connection_->set_visitor(visitor_shim_.get()); | 114 connection_->set_visitor(visitor_shim_.get()); |
126 connection_->SetFromConfig(config_); | 115 connection_->SetFromConfig(config_); |
127 if (connection_->connected()) { | 116 if (connection_->connected()) { |
128 connection_->SetOverallConnectionTimeout( | 117 connection_->SetOverallConnectionTimeout( |
129 config_.max_time_before_crypto_handshake()); | 118 config_.max_time_before_crypto_handshake()); |
130 } | 119 } |
131 headers_stream_.reset(new QuicHeadersStream(this)); | 120 headers_stream_.reset(new QuicHeadersStream(this)); |
132 if (!is_server()) { | 121 if (!is_server()) { |
133 // For version above QUIC v12, the headers stream is stream 3, so the | 122 // For version above QUIC v12, the headers stream is stream 3, so the |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 return GetCryptoStream()->handshake_confirmed(); | 459 return GetCryptoStream()->handshake_confirmed(); |
471 } | 460 } |
472 | 461 |
473 void QuicSession::OnConfigNegotiated() { | 462 void QuicSession::OnConfigNegotiated() { |
474 connection_->SetFromConfig(config_); | 463 connection_->SetFromConfig(config_); |
475 // Tell all streams about the newly received peer receive window. | 464 // Tell all streams about the newly received peer receive window. |
476 if (connection()->version() >= QUIC_VERSION_17 && | 465 if (connection()->version() >= QUIC_VERSION_17 && |
477 config_.HasReceivedInitialFlowControlWindowBytes()) { | 466 config_.HasReceivedInitialFlowControlWindowBytes()) { |
478 // Streams which were created before the SHLO was received (0RTT requests) | 467 // Streams which were created before the SHLO was received (0RTT requests) |
479 // are now informed of the peer's initial flow control window. | 468 // are now informed of the peer's initial flow control window. |
480 uint32 new_flow_control_send_window = | 469 uint32 new_window = config_.ReceivedInitialFlowControlWindowBytes(); |
481 config_.ReceivedInitialFlowControlWindowBytes(); | 470 OnNewStreamFlowControlWindow(new_window); |
482 if (new_flow_control_send_window < kDefaultFlowControlSendWindow) { | 471 OnNewSessionFlowControlWindow(new_window); |
483 LOG(ERROR) | 472 } |
484 << "Peer sent us an invalid flow control send window: " | 473 } |
485 << new_flow_control_send_window | 474 |
486 << ", below default: " << kDefaultFlowControlSendWindow; | 475 void QuicSession::OnNewStreamFlowControlWindow(uint32 new_window) { |
| 476 if (new_window < kDefaultFlowControlSendWindow) { |
| 477 LOG(ERROR) |
| 478 << "Peer sent us an invalid stream flow control send window: " |
| 479 << new_window << ", below default: " << kDefaultFlowControlSendWindow; |
| 480 if (connection_->connected()) { |
487 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW); | 481 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW); |
488 return; | |
489 } | 482 } |
490 DataStreamMap::iterator it = stream_map_.begin(); | 483 return; |
491 while (it != stream_map_.end()) { | 484 } |
492 it->second->flow_controller()->UpdateSendWindowOffset( | 485 |
493 new_flow_control_send_window); | 486 for (DataStreamMap::iterator it = stream_map_.begin(); |
494 it++; | 487 it != stream_map_.end(); ++it) { |
| 488 it->second->flow_controller()->UpdateSendWindowOffset(new_window); |
| 489 } |
| 490 } |
| 491 |
| 492 void QuicSession::OnNewSessionFlowControlWindow(uint32 new_window) { |
| 493 if (new_window < kDefaultFlowControlSendWindow) { |
| 494 LOG(ERROR) |
| 495 << "Peer sent us an invalid session flow control send window: " |
| 496 << new_window << ", below default: " << kDefaultFlowControlSendWindow; |
| 497 if (connection_->connected()) { |
| 498 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW); |
495 } | 499 } |
| 500 return; |
| 501 } |
496 | 502 |
497 // Update connection level window. | 503 flow_controller_->UpdateSendWindowOffset(new_window); |
498 flow_controller_->UpdateSendWindowOffset(new_flow_control_send_window); | |
499 } | |
500 } | 504 } |
501 | 505 |
502 void QuicSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { | 506 void QuicSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) { |
503 switch (event) { | 507 switch (event) { |
504 // TODO(satyamshekhar): Move the logic of setting the encrypter/decrypter | 508 // TODO(satyamshekhar): Move the logic of setting the encrypter/decrypter |
505 // to QuicSession since it is the glue. | 509 // to QuicSession since it is the glue. |
506 case ENCRYPTION_FIRST_ESTABLISHED: | 510 case ENCRYPTION_FIRST_ESTABLISHED: |
507 break; | 511 break; |
508 | 512 |
509 case ENCRYPTION_REESTABLISHED: | 513 case ENCRYPTION_REESTABLISHED: |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 // with a different version. | 714 // with a different version. |
711 for (DataStreamMap::iterator it = stream_map_.begin(); | 715 for (DataStreamMap::iterator it = stream_map_.begin(); |
712 it != stream_map_.end(); ++it) { | 716 it != stream_map_.end(); ++it) { |
713 if (version < QUIC_VERSION_17) { | 717 if (version < QUIC_VERSION_17) { |
714 it->second->flow_controller()->Disable(); | 718 it->second->flow_controller()->Disable(); |
715 } | 719 } |
716 } | 720 } |
717 } | 721 } |
718 | 722 |
719 } // namespace net | 723 } // namespace net |
OLD | NEW |