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 "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/quic/crypto/proof_verifier.h" | 10 #include "net/quic/crypto/proof_verifier.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 perspective() == Perspective::IS_SERVER ? 1 : 0), | 38 perspective() == Perspective::IS_SERVER ? 1 : 0), |
39 num_dynamic_incoming_streams_(0), | 39 num_dynamic_incoming_streams_(0), |
40 num_draining_incoming_streams_(0), | 40 num_draining_incoming_streams_(0), |
41 num_locally_closed_incoming_streams_highest_offset_(0), | 41 num_locally_closed_incoming_streams_highest_offset_(0), |
42 error_(QUIC_NO_ERROR), | 42 error_(QUIC_NO_ERROR), |
43 flow_controller_(connection_.get(), | 43 flow_controller_(connection_.get(), |
44 0, | 44 0, |
45 perspective(), | 45 perspective(), |
46 kMinimumFlowControlSendWindow, | 46 kMinimumFlowControlSendWindow, |
47 config_.GetInitialSessionFlowControlWindowToSend(), | 47 config_.GetInitialSessionFlowControlWindowToSend(), |
48 FLAGS_quic_enable_autotune_by_default | 48 perspective() == Perspective::IS_SERVER), |
49 ? perspective() == Perspective::IS_SERVER | |
50 : false), | |
51 currently_writing_stream_id_(0) {} | 49 currently_writing_stream_id_(0) {} |
52 | 50 |
53 void QuicSession::Initialize() { | 51 void QuicSession::Initialize() { |
54 connection_->set_visitor(this); | 52 connection_->set_visitor(this); |
55 connection_->SetFromConfig(config_); | 53 connection_->SetFromConfig(config_); |
56 | 54 |
57 DCHECK_EQ(kCryptoStreamId, GetCryptoStream()->id()); | 55 DCHECK_EQ(kCryptoStreamId, GetCryptoStream()->id()); |
58 static_stream_map_[kCryptoStreamId] = GetCryptoStream(); | 56 static_stream_map_[kCryptoStreamId] = GetCryptoStream(); |
59 } | 57 } |
60 | 58 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 391 |
394 const QuicVersion version = connection()->version(); | 392 const QuicVersion version = connection()->version(); |
395 uint32_t max_streams = 0; | 393 uint32_t max_streams = 0; |
396 if (version > QUIC_VERSION_34 && | 394 if (version > QUIC_VERSION_34 && |
397 config_.HasReceivedMaxIncomingDynamicStreams()) { | 395 config_.HasReceivedMaxIncomingDynamicStreams()) { |
398 max_streams = config_.ReceivedMaxIncomingDynamicStreams(); | 396 max_streams = config_.ReceivedMaxIncomingDynamicStreams(); |
399 } else { | 397 } else { |
400 max_streams = config_.MaxStreamsPerConnection(); | 398 max_streams = config_.MaxStreamsPerConnection(); |
401 } | 399 } |
402 set_max_open_outgoing_streams(max_streams); | 400 set_max_open_outgoing_streams(max_streams); |
403 if (!FLAGS_quic_enable_autotune_by_default && | |
404 perspective() == Perspective::IS_SERVER) { | |
405 if (config_.HasReceivedConnectionOptions()) { | |
406 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kAFCW)) { | |
407 // The following variations change the initial receive flow control | |
408 // window sizes. | |
409 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW5)) { | |
410 AdjustInitialFlowControlWindows(32 * 1024); | |
411 } | |
412 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW6)) { | |
413 AdjustInitialFlowControlWindows(64 * 1024); | |
414 } | |
415 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW7)) { | |
416 AdjustInitialFlowControlWindows(128 * 1024); | |
417 } | |
418 EnableAutoTuneReceiveWindow(); | |
419 } | |
420 } | |
421 } | |
422 | 401 |
423 if (version <= QUIC_VERSION_34) { | 402 if (version <= QUIC_VERSION_34) { |
424 // A small number of additional incoming streams beyond the limit should be | 403 // A small number of additional incoming streams beyond the limit should be |
425 // allowed. This helps avoid early connection termination when FIN/RSTs for | 404 // allowed. This helps avoid early connection termination when FIN/RSTs for |
426 // old streams are lost or arrive out of order. | 405 // old streams are lost or arrive out of order. |
427 // Use a minimum number of additional streams, or a percentage increase, | 406 // Use a minimum number of additional streams, or a percentage increase, |
428 // whichever is larger. | 407 // whichever is larger. |
429 uint32_t max_incoming_streams = | 408 uint32_t max_incoming_streams = |
430 max(max_streams + kMaxStreamsMinimumIncrement, | 409 max(max_streams + kMaxStreamsMinimumIncrement, |
431 static_cast<uint32_t>(max_streams * kMaxStreamsMultiplier)); | 410 static_cast<uint32_t>(max_streams * kMaxStreamsMultiplier)); |
(...skipping 13 matching lines...) Expand all Loading... |
445 // requests) are now informed of the peer's initial flow control window. | 424 // requests) are now informed of the peer's initial flow control window. |
446 OnNewStreamFlowControlWindow( | 425 OnNewStreamFlowControlWindow( |
447 config_.ReceivedInitialStreamFlowControlWindowBytes()); | 426 config_.ReceivedInitialStreamFlowControlWindowBytes()); |
448 } | 427 } |
449 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) { | 428 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) { |
450 OnNewSessionFlowControlWindow( | 429 OnNewSessionFlowControlWindow( |
451 config_.ReceivedInitialSessionFlowControlWindowBytes()); | 430 config_.ReceivedInitialSessionFlowControlWindowBytes()); |
452 } | 431 } |
453 } | 432 } |
454 | 433 |
455 // TODO(ckrasic): remove the following two methods when deprecating | |
456 // FLAGS_quic_enable_autotune_by_default. | |
457 void QuicSession::EnableAutoTuneReceiveWindow() { | |
458 DVLOG(1) << ENDPOINT << "Enable auto tune receive windows"; | |
459 flow_controller_.set_auto_tune_receive_window(true); | |
460 // Inform all existing streams about the new window. | |
461 for (auto const& kv : static_stream_map_) { | |
462 kv.second->flow_controller()->set_auto_tune_receive_window(true); | |
463 } | |
464 for (auto const& kv : dynamic_stream_map_) { | |
465 kv.second->flow_controller()->set_auto_tune_receive_window(true); | |
466 } | |
467 } | |
468 | |
469 void QuicSession::AdjustInitialFlowControlWindows(size_t stream_window) { | |
470 const float session_window_multiplier = | |
471 config_.GetInitialStreamFlowControlWindowToSend() | |
472 ? static_cast<float>( | |
473 config_.GetInitialSessionFlowControlWindowToSend()) / | |
474 config_.GetInitialStreamFlowControlWindowToSend() | |
475 : 1.0; | |
476 DVLOG(1) << ENDPOINT << "Set stream receive window to " << stream_window; | |
477 config_.SetInitialStreamFlowControlWindowToSend(stream_window); | |
478 // Reduce the session window as well, motivation is reducing resource waste | |
479 // and denial of service vulnerability, as with the stream window. Session | |
480 // size is set according to the ratio between session and stream window size | |
481 // previous to auto-tuning. Note that the ratio may change dynamically, since | |
482 // auto-tuning acts independently for each flow controller. | |
483 size_t session_window = session_window_multiplier * stream_window; | |
484 DVLOG(1) << ENDPOINT << "Set session receive window to " << session_window; | |
485 config_.SetInitialSessionFlowControlWindowToSend(session_window); | |
486 flow_controller_.UpdateReceiveWindowSize(session_window); | |
487 // Inform all existing streams about the new window. | |
488 for (auto const& kv : static_stream_map_) { | |
489 kv.second->flow_controller()->UpdateReceiveWindowSize(stream_window); | |
490 } | |
491 for (auto const& kv : dynamic_stream_map_) { | |
492 kv.second->flow_controller()->UpdateReceiveWindowSize(stream_window); | |
493 } | |
494 } | |
495 | |
496 void QuicSession::HandleFrameOnNonexistentOutgoingStream( | 434 void QuicSession::HandleFrameOnNonexistentOutgoingStream( |
497 QuicStreamId stream_id) { | 435 QuicStreamId stream_id) { |
498 DCHECK(!IsClosedStream(stream_id)); | 436 DCHECK(!IsClosedStream(stream_id)); |
499 // Received a frame for a locally-created stream that is not currently | 437 // Received a frame for a locally-created stream that is not currently |
500 // active. This is an error. | 438 // active. This is an error. |
501 connection()->CloseConnection( | 439 connection()->CloseConnection( |
502 QUIC_INVALID_STREAM_ID, "Data for nonexistent stream", | 440 QUIC_INVALID_STREAM_ID, "Data for nonexistent stream", |
503 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 441 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
504 } | 442 } |
505 | 443 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 765 |
828 size_t QuicSession::MaxAvailableStreams() const { | 766 size_t QuicSession::MaxAvailableStreams() const { |
829 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 767 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
830 } | 768 } |
831 | 769 |
832 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 770 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
833 return id % 2 != next_outgoing_stream_id_ % 2; | 771 return id % 2 != next_outgoing_stream_id_ % 2; |
834 } | 772 } |
835 | 773 |
836 } // namespace net | 774 } // namespace net |
OLD | NEW |