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 #ifdef TEMP_INSTRUMENTATION_473893 | 8 #ifdef TEMP_INSTRUMENTATION_473893 |
9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #endif | 10 #endif |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // limit sent to the client. This helps avoid early connection termination | 418 // limit sent to the client. This helps avoid early connection termination |
419 // when FIN/RSTs for old streams are lost or arrive out of order. | 419 // when FIN/RSTs for old streams are lost or arrive out of order. |
420 // Use a minimum number of additional streams, or a percentage increase, | 420 // Use a minimum number of additional streams, or a percentage increase, |
421 // whichever is larger. | 421 // whichever is larger. |
422 max_streams = | 422 max_streams = |
423 max(max_streams + kMaxStreamsMinimumIncrement, | 423 max(max_streams + kMaxStreamsMinimumIncrement, |
424 static_cast<uint32>(max_streams * kMaxStreamsMultiplier)); | 424 static_cast<uint32>(max_streams * kMaxStreamsMultiplier)); |
425 | 425 |
426 if (config_.HasReceivedConnectionOptions()) { | 426 if (config_.HasReceivedConnectionOptions()) { |
427 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kAFCW)) { | 427 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kAFCW)) { |
| 428 // The following variations change the initial receive flow control |
| 429 // window sizes. |
| 430 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW5)) { |
| 431 AdjustInitialFlowControlWindows(32 * 1024); |
| 432 } |
| 433 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW6)) { |
| 434 AdjustInitialFlowControlWindows(64 * 1024); |
| 435 } |
| 436 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW7)) { |
| 437 AdjustInitialFlowControlWindows(128 * 1024); |
| 438 } |
428 EnableAutoTuneReceiveWindow(); | 439 EnableAutoTuneReceiveWindow(); |
429 } | 440 } |
430 // The following variations change the initial receive flow control window | |
431 // size for streams. For simplicity reasons, do not try to effect | |
432 // existing streams but only future ones. | |
433 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW5)) { | |
434 config_.SetInitialStreamFlowControlWindowToSend(32 * 1024); | |
435 } | |
436 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW6)) { | |
437 config_.SetInitialStreamFlowControlWindowToSend(64 * 1024); | |
438 } | |
439 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW7)) { | |
440 config_.SetInitialStreamFlowControlWindowToSend(128 * 1024); | |
441 } | |
442 } | 441 } |
443 } | 442 } |
444 set_max_open_streams(max_streams); | 443 set_max_open_streams(max_streams); |
445 | 444 |
446 if (config_.HasReceivedInitialStreamFlowControlWindowBytes()) { | 445 if (config_.HasReceivedInitialStreamFlowControlWindowBytes()) { |
447 // Streams which were created before the SHLO was received (0-RTT | 446 // Streams which were created before the SHLO was received (0-RTT |
448 // requests) are now informed of the peer's initial flow control window. | 447 // requests) are now informed of the peer's initial flow control window. |
449 OnNewStreamFlowControlWindow( | 448 OnNewStreamFlowControlWindow( |
450 config_.ReceivedInitialStreamFlowControlWindowBytes()); | 449 config_.ReceivedInitialStreamFlowControlWindowBytes()); |
451 } | 450 } |
452 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) { | 451 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) { |
453 OnNewSessionFlowControlWindow( | 452 OnNewSessionFlowControlWindow( |
454 config_.ReceivedInitialSessionFlowControlWindowBytes()); | 453 config_.ReceivedInitialSessionFlowControlWindowBytes()); |
455 } | 454 } |
456 } | 455 } |
457 | 456 |
458 void QuicSession::EnableAutoTuneReceiveWindow() { | 457 void QuicSession::EnableAutoTuneReceiveWindow() { |
| 458 DVLOG(1) << ENDPOINT << "Enable auto tune receive windows"; |
459 flow_controller_.set_auto_tune_receive_window(true); | 459 flow_controller_.set_auto_tune_receive_window(true); |
460 // Inform all existing streams about the new window. | 460 // Inform all existing streams about the new window. |
461 for (auto const& kv : static_stream_map_) { | 461 for (auto const& kv : static_stream_map_) { |
462 kv.second->flow_controller()->set_auto_tune_receive_window(true); | 462 kv.second->flow_controller()->set_auto_tune_receive_window(true); |
463 } | 463 } |
464 for (auto const& kv : dynamic_stream_map_) { | 464 for (auto const& kv : dynamic_stream_map_) { |
465 kv.second->flow_controller()->set_auto_tune_receive_window(true); | 465 kv.second->flow_controller()->set_auto_tune_receive_window(true); |
466 } | 466 } |
467 } | 467 } |
468 | 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 |
469 void QuicSession::OnNewStreamFlowControlWindow(QuicStreamOffset new_window) { | 496 void QuicSession::OnNewStreamFlowControlWindow(QuicStreamOffset new_window) { |
470 if (new_window < kMinimumFlowControlSendWindow) { | 497 if (new_window < kMinimumFlowControlSendWindow) { |
471 LOG(ERROR) << "Peer sent us an invalid stream flow control send window: " | 498 LOG(ERROR) << "Peer sent us an invalid stream flow control send window: " |
472 << new_window | 499 << new_window |
473 << ", below default: " << kMinimumFlowControlSendWindow; | 500 << ", below default: " << kMinimumFlowControlSendWindow; |
474 if (connection_->connected()) { | 501 if (connection_->connected()) { |
475 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW); | 502 connection_->SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW); |
476 } | 503 } |
477 return; | 504 return; |
478 } | 505 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 base::debug::StackTrace stack_trace = stack_trace_; | 788 base::debug::StackTrace stack_trace = stack_trace_; |
762 | 789 |
763 base::debug::Alias(&liveness); | 790 base::debug::Alias(&liveness); |
764 base::debug::Alias(&stack_trace); | 791 base::debug::Alias(&stack_trace); |
765 | 792 |
766 CHECK_EQ(ALIVE, liveness); | 793 CHECK_EQ(ALIVE, liveness); |
767 #endif | 794 #endif |
768 } | 795 } |
769 | 796 |
770 } // namespace net | 797 } // namespace net |
OLD | NEW |