| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void QuicSession::OnStreamFrame(const QuicStreamFrame& frame) { | 70 void QuicSession::OnStreamFrame(const QuicStreamFrame& frame) { |
| 71 // TODO(rch) deal with the error case of stream id 0. | 71 // TODO(rch) deal with the error case of stream id 0. |
| 72 QuicStreamId stream_id = frame.stream_id; | 72 QuicStreamId stream_id = frame.stream_id; |
| 73 QuicStream* stream = GetOrCreateStream(stream_id); | 73 QuicStream* stream = GetOrCreateStream(stream_id); |
| 74 if (!stream) { | 74 if (!stream) { |
| 75 // The stream no longer exists, but we may still be interested in the | 75 // The stream no longer exists, but we may still be interested in the |
| 76 // final stream byte offset sent by the peer. A frame with a FIN can give | 76 // final stream byte offset sent by the peer. A frame with a FIN can give |
| 77 // us this offset. | 77 // us this offset. |
| 78 if (frame.fin) { | 78 if (frame.fin) { |
| 79 QuicStreamOffset final_byte_offset = frame.offset + frame.data_length; | 79 QuicStreamOffset final_byte_offset = frame.offset + frame.data_length; |
| 80 UpdateFlowControlOnFinalReceivedByteOffset(stream_id, final_byte_offset); | 80 OnFinalByteOffsetReceived(stream_id, final_byte_offset); |
| 81 } | 81 } |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 stream->OnStreamFrame(frame); | 84 stream->OnStreamFrame(frame); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void QuicSession::OnRstStream(const QuicRstStreamFrame& frame) { | 87 void QuicSession::OnRstStream(const QuicRstStreamFrame& frame) { |
| 88 if (QuicContainsKey(static_stream_map_, frame.stream_id)) { | 88 if (QuicContainsKey(static_stream_map_, frame.stream_id)) { |
| 89 connection()->CloseConnection( | 89 connection()->CloseConnection( |
| 90 QUIC_INVALID_STREAM_ID, "Attempt to reset a static stream", | 90 QUIC_INVALID_STREAM_ID, "Attempt to reset a static stream", |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 IsIncomingStream(stream_id)) { | 387 IsIncomingStream(stream_id)) { |
| 388 --num_draining_incoming_streams_; | 388 --num_draining_incoming_streams_; |
| 389 } | 389 } |
| 390 draining_streams_.erase(stream_id); | 390 draining_streams_.erase(stream_id); |
| 391 | 391 |
| 392 stream->OnClose(); | 392 stream->OnClose(); |
| 393 // Decrease the number of streams being emulated when a new one is opened. | 393 // Decrease the number of streams being emulated when a new one is opened. |
| 394 connection_->SetNumOpenStreams(dynamic_stream_map_.size()); | 394 connection_->SetNumOpenStreams(dynamic_stream_map_.size()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void QuicSession::UpdateFlowControlOnFinalReceivedByteOffset( | 397 void QuicSession::OnFinalByteOffsetReceived( |
| 398 QuicStreamId stream_id, | 398 QuicStreamId stream_id, |
| 399 QuicStreamOffset final_byte_offset) { | 399 QuicStreamOffset final_byte_offset) { |
| 400 std::map<QuicStreamId, QuicStreamOffset>::iterator it = | 400 std::map<QuicStreamId, QuicStreamOffset>::iterator it = |
| 401 locally_closed_streams_highest_offset_.find(stream_id); | 401 locally_closed_streams_highest_offset_.find(stream_id); |
| 402 if (it == locally_closed_streams_highest_offset_.end()) { | 402 if (it == locally_closed_streams_highest_offset_.end()) { |
| 403 return; | 403 return; |
| 404 } | 404 } |
| 405 | 405 |
| 406 QUIC_DVLOG(1) << ENDPOINT << "Received final byte offset " | 406 QUIC_DVLOG(1) << ENDPOINT << "Received final byte offset " |
| 407 << final_byte_offset << " for stream " << stream_id; | 407 << final_byte_offset << " for stream " << stream_id; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 526 } |
| 527 | 527 |
| 528 void QuicSession::HandleRstOnValidNonexistentStream( | 528 void QuicSession::HandleRstOnValidNonexistentStream( |
| 529 const QuicRstStreamFrame& frame) { | 529 const QuicRstStreamFrame& frame) { |
| 530 // If the stream is neither originally in active streams nor created in | 530 // If the stream is neither originally in active streams nor created in |
| 531 // GetOrCreateDynamicStream(), it could be a closed stream in which case its | 531 // GetOrCreateDynamicStream(), it could be a closed stream in which case its |
| 532 // final received byte offset need to be updated. | 532 // final received byte offset need to be updated. |
| 533 if (IsClosedStream(frame.stream_id)) { | 533 if (IsClosedStream(frame.stream_id)) { |
| 534 // The RST frame contains the final byte offset for the stream: we can now | 534 // The RST frame contains the final byte offset for the stream: we can now |
| 535 // update the connection level flow controller if needed. | 535 // update the connection level flow controller if needed. |
| 536 UpdateFlowControlOnFinalReceivedByteOffset(frame.stream_id, | 536 OnFinalByteOffsetReceived(frame.stream_id, frame.byte_offset); |
| 537 frame.byte_offset); | |
| 538 } | 537 } |
| 539 } | 538 } |
| 540 | 539 |
| 541 void QuicSession::OnNewStreamFlowControlWindow(QuicStreamOffset new_window) { | 540 void QuicSession::OnNewStreamFlowControlWindow(QuicStreamOffset new_window) { |
| 542 if (new_window < kMinimumFlowControlSendWindow) { | 541 if (new_window < kMinimumFlowControlSendWindow) { |
| 543 QUIC_LOG_FIRST_N(ERROR, 1) | 542 QUIC_LOG_FIRST_N(ERROR, 1) |
| 544 << "Peer sent us an invalid stream flow control send window: " | 543 << "Peer sent us an invalid stream flow control send window: " |
| 545 << new_window << ", below default: " << kMinimumFlowControlSendWindow; | 544 << new_window << ", below default: " << kMinimumFlowControlSendWindow; |
| 546 if (connection_->connected()) { | 545 if (connection_->connected()) { |
| 547 connection_->CloseConnection( | 546 connection_->CloseConnection( |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 bool QuicSession::HasDataToWrite() const { | 812 bool QuicSession::HasDataToWrite() const { |
| 814 return write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() || | 813 return write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() || |
| 815 write_blocked_streams_.HasWriteBlockedDataStreams() || | 814 write_blocked_streams_.HasWriteBlockedDataStreams() || |
| 816 connection_->HasQueuedData(); | 815 connection_->HasQueuedData(); |
| 817 } | 816 } |
| 818 | 817 |
| 819 void QuicSession::PostProcessAfterData() { | 818 void QuicSession::PostProcessAfterData() { |
| 820 closed_streams_.clear(); | 819 closed_streams_.clear(); |
| 821 } | 820 } |
| 822 | 821 |
| 822 void QuicSession::OnAckNeedsRetransmittableFrame() { |
| 823 flow_controller_.SendWindowUpdate(); |
| 824 } |
| 825 |
| 823 size_t QuicSession::GetNumDynamicOutgoingStreams() const { | 826 size_t QuicSession::GetNumDynamicOutgoingStreams() const { |
| 824 DCHECK_GE(dynamic_stream_map_.size(), num_dynamic_incoming_streams_); | 827 DCHECK_GE(dynamic_stream_map_.size(), num_dynamic_incoming_streams_); |
| 825 return dynamic_stream_map_.size() - num_dynamic_incoming_streams_; | 828 return dynamic_stream_map_.size() - num_dynamic_incoming_streams_; |
| 826 } | 829 } |
| 827 | 830 |
| 828 size_t QuicSession::GetNumDrainingOutgoingStreams() const { | 831 size_t QuicSession::GetNumDrainingOutgoingStreams() const { |
| 829 DCHECK_GE(draining_streams_.size(), num_draining_incoming_streams_); | 832 DCHECK_GE(draining_streams_.size(), num_draining_incoming_streams_); |
| 830 return draining_streams_.size() - num_draining_incoming_streams_; | 833 return draining_streams_.size() - num_draining_incoming_streams_; |
| 831 } | 834 } |
| 832 | 835 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 857 | 860 |
| 858 size_t QuicSession::MaxAvailableStreams() const { | 861 size_t QuicSession::MaxAvailableStreams() const { |
| 859 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 862 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
| 860 } | 863 } |
| 861 | 864 |
| 862 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 865 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
| 863 return id % 2 != next_outgoing_stream_id_ % 2; | 866 return id % 2 != next_outgoing_stream_id_ % 2; |
| 864 } | 867 } |
| 865 | 868 |
| 866 } // namespace net | 869 } // namespace net |
| OLD | NEW |