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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 QuicStreamId id, | 288 QuicStreamId id, |
289 QuicIOVector iov, | 289 QuicIOVector iov, |
290 QuicStreamOffset offset, | 290 QuicStreamOffset offset, |
291 bool fin, | 291 bool fin, |
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. |
(...skipping 109 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 uint32_t max_streams = 0; | 439 uint32_t max_streams = 0; |
440 if (config_.HasReceivedMaxIncomingDynamicStreams()) { | 440 if (config_.HasReceivedMaxIncomingDynamicStreams()) { |
441 max_streams = config_.ReceivedMaxIncomingDynamicStreams(); | 441 max_streams = config_.ReceivedMaxIncomingDynamicStreams(); |
442 } else { | 442 } else { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 857 |
858 size_t QuicSession::MaxAvailableStreams() const { | 858 size_t QuicSession::MaxAvailableStreams() const { |
859 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 859 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
860 } | 860 } |
861 | 861 |
862 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 862 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
863 return id % 2 != next_outgoing_stream_id_ % 2; | 863 return id % 2 != next_outgoing_stream_id_ % 2; |
864 } | 864 } |
865 | 865 |
866 } // namespace net | 866 } // namespace net |
OLD | NEW |