| 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/core/quic_session.h" | 5 #include "net/quic/core/quic_session.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "net/quic/core/quic_connection.h" | 10 #include "net/quic/core/quic_connection.h" |
| 11 #include "net/quic/core/quic_flags.h" | |
| 12 #include "net/quic/core/quic_flow_controller.h" | 11 #include "net/quic/core/quic_flow_controller.h" |
| 13 #include "net/quic/platform/api/quic_bug_tracker.h" | 12 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 13 #include "net/quic/platform/api/quic_flags.h" |
| 14 #include "net/quic/platform/api/quic_logging.h" | 14 #include "net/quic/platform/api/quic_logging.h" |
| 15 #include "net/quic/platform/api/quic_map_util.h" | 15 #include "net/quic/platform/api/quic_map_util.h" |
| 16 #include "net/quic/platform/api/quic_str_cat.h" | 16 #include "net/quic/platform/api/quic_str_cat.h" |
| 17 | 17 |
| 18 using std::string; | 18 using std::string; |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 #define ENDPOINT \ | 22 #define ENDPOINT \ |
| 23 (perspective() == Perspective::IS_SERVER ? "Server: " : "Client: ") | 23 (perspective() == Perspective::IS_SERVER ? "Server: " : "Client: ") |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 kMinimumFlowControlSendWindow, | 43 kMinimumFlowControlSendWindow, |
| 44 config_.GetInitialSessionFlowControlWindowToSend(), | 44 config_.GetInitialSessionFlowControlWindowToSend(), |
| 45 perspective() == Perspective::IS_SERVER, | 45 perspective() == Perspective::IS_SERVER, |
| 46 nullptr), | 46 nullptr), |
| 47 currently_writing_stream_id_(0) {} | 47 currently_writing_stream_id_(0) {} |
| 48 | 48 |
| 49 void QuicSession::Initialize() { | 49 void QuicSession::Initialize() { |
| 50 connection_->set_visitor(this); | 50 connection_->set_visitor(this); |
| 51 connection_->SetFromConfig(config_); | 51 connection_->SetFromConfig(config_); |
| 52 | 52 |
| 53 DCHECK_EQ(kCryptoStreamId, GetCryptoStream()->id()); | 53 DCHECK_EQ(kCryptoStreamId, GetMutableCryptoStream()->id()); |
| 54 static_stream_map_[kCryptoStreamId] = GetCryptoStream(); | 54 static_stream_map_[kCryptoStreamId] = GetMutableCryptoStream(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 QuicSession::~QuicSession() { | 57 QuicSession::~QuicSession() { |
| 58 QUIC_LOG_IF(WARNING, num_locally_closed_incoming_streams_highest_offset() > | 58 QUIC_LOG_IF(WARNING, num_locally_closed_incoming_streams_highest_offset() > |
| 59 max_open_incoming_streams_) | 59 max_open_incoming_streams_) |
| 60 << "Surprisingly high number of locally closed peer initiated streams" | 60 << "Surprisingly high number of locally closed peer initiated streams" |
| 61 "still waiting for final byte offset: " | 61 "still waiting for final byte offset: " |
| 62 << num_locally_closed_incoming_streams_highest_offset(); | 62 << num_locally_closed_incoming_streams_highest_offset(); |
| 63 QUIC_LOG_IF(WARNING, GetNumLocallyClosedOutgoingStreamsHighestOffset() > | 63 QUIC_LOG_IF(WARNING, GetNumLocallyClosedOutgoingStreamsHighestOffset() > |
| 64 max_open_outgoing_streams_) | 64 max_open_outgoing_streams_) |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 const QuicSocketAddress& peer_address, | 281 const QuicSocketAddress& peer_address, |
| 282 const QuicReceivedPacket& packet) { | 282 const QuicReceivedPacket& packet) { |
| 283 connection_->ProcessUdpPacket(self_address, peer_address, packet); | 283 connection_->ProcessUdpPacket(self_address, peer_address, packet); |
| 284 } | 284 } |
| 285 | 285 |
| 286 QuicConsumedData QuicSession::WritevData( | 286 QuicConsumedData QuicSession::WritevData( |
| 287 QuicStream* stream, | 287 QuicStream* stream, |
| 288 QuicStreamId id, | 288 QuicStreamId id, |
| 289 QuicIOVector iov, | 289 QuicIOVector iov, |
| 290 QuicStreamOffset offset, | 290 QuicStreamOffset offset, |
| 291 bool fin, | 291 StreamSendingState state, |
| 292 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { | 292 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 293 // This check is an attempt to deal with potential memory corruption | 293 // This check is an attempt to deal with potential memory corruption |
| 294 // in which |id| ends up set to 1 (the crypto stream id). If this happen | 294 // in which |id| ends up set to 1 (the crypto stream id). If this happen |
| 295 // it might end up resulting in unencrypted stream data being sent. | 295 // it might end up resulting in unencrypted stream data being sent. |
| 296 // While this is impossible to avoid given sufficient corruption, this | 296 // While this is impossible to avoid given sufficient corruption, this |
| 297 // seems like a reasonable mitigation. | 297 // seems like a reasonable mitigation. |
| 298 if (id == kCryptoStreamId && stream != GetCryptoStream()) { | 298 if (id == kCryptoStreamId && stream != GetMutableCryptoStream()) { |
| 299 QUIC_BUG << "Stream id mismatch"; | 299 QUIC_BUG << "Stream id mismatch"; |
| 300 connection_->CloseConnection( | 300 connection_->CloseConnection( |
| 301 QUIC_INTERNAL_ERROR, | 301 QUIC_INTERNAL_ERROR, |
| 302 "Non-crypto stream attempted to write data as crypto stream.", | 302 "Non-crypto stream attempted to write data as crypto stream.", |
| 303 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 303 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 304 return QuicConsumedData(0, false); | 304 return QuicConsumedData(0, false); |
| 305 } | 305 } |
| 306 if (!IsEncryptionEstablished() && id != kCryptoStreamId) { | 306 if (!IsEncryptionEstablished() && id != kCryptoStreamId) { |
| 307 // Do not let streams write without encryption. The calling stream will end | 307 // Do not let streams write without encryption. The calling stream will end |
| 308 // up write blocked until OnCanWrite is next called. | 308 // up write blocked until OnCanWrite is next called. |
| 309 return QuicConsumedData(0, false); | 309 return QuicConsumedData(0, false); |
| 310 } | 310 } |
| 311 QuicConsumedData data = connection_->SendStreamData(id, iov, offset, fin, | 311 QuicConsumedData data = connection_->SendStreamData(id, iov, offset, state, |
| 312 std::move(ack_listener)); | 312 std::move(ack_listener)); |
| 313 write_blocked_streams_.UpdateBytesForStream(id, data.bytes_consumed); | 313 write_blocked_streams_.UpdateBytesForStream(id, data.bytes_consumed); |
| 314 return data; | 314 return data; |
| 315 } | 315 } |
| 316 | 316 |
| 317 void QuicSession::SendRstStream(QuicStreamId id, | 317 void QuicSession::SendRstStream(QuicStreamId id, |
| 318 QuicRstStreamErrorCode error, | 318 QuicRstStreamErrorCode error, |
| 319 QuicStreamOffset bytes_written) { | 319 QuicStreamOffset bytes_written) { |
| 320 if (QuicContainsKey(static_stream_map_, id)) { | 320 if (QuicContainsKey(static_stream_map_, id)) { |
| 321 QUIC_BUG << "Cannot send RST for a static stream with ID " << id; | 321 QUIC_BUG << "Cannot send RST for a static stream with ID " << id; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 flow_controller_.AddBytesConsumed(offset_diff); | 421 flow_controller_.AddBytesConsumed(offset_diff); |
| 422 locally_closed_streams_highest_offset_.erase(it); | 422 locally_closed_streams_highest_offset_.erase(it); |
| 423 if (IsIncomingStream(stream_id)) { | 423 if (IsIncomingStream(stream_id)) { |
| 424 --num_locally_closed_incoming_streams_highest_offset_; | 424 --num_locally_closed_incoming_streams_highest_offset_; |
| 425 } | 425 } |
| 426 } | 426 } |
| 427 | 427 |
| 428 bool QuicSession::IsEncryptionEstablished() { | 428 bool QuicSession::IsEncryptionEstablished() const { |
| 429 return GetCryptoStream()->encryption_established(); | 429 return GetCryptoStream()->encryption_established(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 bool QuicSession::IsCryptoHandshakeConfirmed() { | 432 bool QuicSession::IsCryptoHandshakeConfirmed() const { |
| 433 return GetCryptoStream()->handshake_confirmed(); | 433 return GetCryptoStream()->handshake_confirmed(); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void QuicSession::OnConfigNegotiated() { | 436 void QuicSession::OnConfigNegotiated() { |
| 437 connection_->SetFromConfig(config_); | 437 connection_->SetFromConfig(config_); |
| 438 | 438 |
| 439 const QuicVersion version = connection()->version(); | |
| 440 uint32_t max_streams = 0; | 439 uint32_t max_streams = 0; |
| 441 if (version > QUIC_VERSION_34 && | 440 if (config_.HasReceivedMaxIncomingDynamicStreams()) { |
| 442 config_.HasReceivedMaxIncomingDynamicStreams()) { | |
| 443 max_streams = config_.ReceivedMaxIncomingDynamicStreams(); | 441 max_streams = config_.ReceivedMaxIncomingDynamicStreams(); |
| 444 } else { | 442 } else { |
| 445 max_streams = config_.MaxStreamsPerConnection(); | 443 max_streams = config_.MaxStreamsPerConnection(); |
| 446 } | 444 } |
| 447 set_max_open_outgoing_streams(max_streams); | 445 set_max_open_outgoing_streams(max_streams); |
| 448 if (FLAGS_quic_reloadable_flag_quic_large_ifw_options && | 446 if (perspective() == Perspective::IS_SERVER) { |
| 449 perspective() == Perspective::IS_SERVER) { | |
| 450 if (config_.HasReceivedConnectionOptions()) { | 447 if (config_.HasReceivedConnectionOptions()) { |
| 451 // The following variations change the initial receive flow control | 448 // The following variations change the initial receive flow control |
| 452 // window sizes. | 449 // window sizes. |
| 453 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW6)) { | 450 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW6)) { |
| 454 AdjustInitialFlowControlWindows(64 * 1024); | 451 AdjustInitialFlowControlWindows(64 * 1024); |
| 455 } | 452 } |
| 456 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW7)) { | 453 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW7)) { |
| 457 AdjustInitialFlowControlWindows(128 * 1024); | 454 AdjustInitialFlowControlWindows(128 * 1024); |
| 458 } | 455 } |
| 459 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW8)) { | 456 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW8)) { |
| 460 AdjustInitialFlowControlWindows(256 * 1024); | 457 AdjustInitialFlowControlWindows(256 * 1024); |
| 461 } | 458 } |
| 462 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW9)) { | 459 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFW9)) { |
| 463 AdjustInitialFlowControlWindows(512 * 1024); | 460 AdjustInitialFlowControlWindows(512 * 1024); |
| 464 } | 461 } |
| 465 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFWA)) { | 462 if (ContainsQuicTag(config_.ReceivedConnectionOptions(), kIFWA)) { |
| 466 AdjustInitialFlowControlWindows(1024 * 1024); | 463 AdjustInitialFlowControlWindows(1024 * 1024); |
| 467 } | 464 } |
| 468 } | 465 } |
| 469 } | 466 } |
| 470 | 467 |
| 471 if (version <= QUIC_VERSION_34) { | 468 // A small number of additional incoming streams beyond the limit should be |
| 472 // A small number of additional incoming streams beyond the limit should be | 469 // allowed. This helps avoid early connection termination when FIN/RSTs for |
| 473 // allowed. This helps avoid early connection termination when FIN/RSTs for | 470 // old streams are lost or arrive out of order. |
| 474 // old streams are lost or arrive out of order. | 471 // Use a minimum number of additional streams, or a percentage increase, |
| 475 // Use a minimum number of additional streams, or a percentage increase, | 472 // whichever is larger. |
| 476 // whichever is larger. | 473 uint32_t max_incoming_streams_to_send = |
| 477 uint32_t max_incoming_streams = | 474 config_.GetMaxIncomingDynamicStreamsToSend(); |
| 478 std::max(max_streams + kMaxStreamsMinimumIncrement, | 475 uint32_t max_incoming_streams = |
| 479 static_cast<uint32_t>(max_streams * kMaxStreamsMultiplier)); | 476 std::max(max_incoming_streams_to_send + kMaxStreamsMinimumIncrement, |
| 480 set_max_open_incoming_streams(max_incoming_streams); | 477 static_cast<uint32_t>(max_incoming_streams_to_send * |
| 481 } else { | 478 kMaxStreamsMultiplier)); |
| 482 uint32_t max_incoming_streams_to_send = | 479 set_max_open_incoming_streams(max_incoming_streams); |
| 483 config_.GetMaxIncomingDynamicStreamsToSend(); | |
| 484 uint32_t max_incoming_streams = | |
| 485 std::max(max_incoming_streams_to_send + kMaxStreamsMinimumIncrement, | |
| 486 static_cast<uint32_t>(max_incoming_streams_to_send * | |
| 487 kMaxStreamsMultiplier)); | |
| 488 set_max_open_incoming_streams(max_incoming_streams); | |
| 489 } | |
| 490 | 480 |
| 491 if (config_.HasReceivedInitialStreamFlowControlWindowBytes()) { | 481 if (config_.HasReceivedInitialStreamFlowControlWindowBytes()) { |
| 492 // Streams which were created before the SHLO was received (0-RTT | 482 // Streams which were created before the SHLO was received (0-RTT |
| 493 // requests) are now informed of the peer's initial flow control window. | 483 // requests) are now informed of the peer's initial flow control window. |
| 494 OnNewStreamFlowControlWindow( | 484 OnNewStreamFlowControlWindow( |
| 495 config_.ReceivedInitialStreamFlowControlWindowBytes()); | 485 config_.ReceivedInitialStreamFlowControlWindowBytes()); |
| 496 } | 486 } |
| 497 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) { | 487 if (config_.HasReceivedInitialSessionFlowControlWindowBytes()) { |
| 498 OnNewSessionFlowControlWindow( | 488 OnNewSessionFlowControlWindow( |
| 499 config_.ReceivedInitialSessionFlowControlWindowBytes()); | 489 config_.ReceivedInitialSessionFlowControlWindowBytes()); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 | 857 |
| 868 size_t QuicSession::MaxAvailableStreams() const { | 858 size_t QuicSession::MaxAvailableStreams() const { |
| 869 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 859 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
| 870 } | 860 } |
| 871 | 861 |
| 872 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 862 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
| 873 return id % 2 != next_outgoing_stream_id_ % 2; | 863 return id % 2 != next_outgoing_stream_id_ % 2; |
| 874 } | 864 } |
| 875 | 865 |
| 876 } // namespace net | 866 } // namespace net |
| OLD | NEW |