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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 856 |
858 size_t QuicSession::MaxAvailableStreams() const { | 857 size_t QuicSession::MaxAvailableStreams() const { |
859 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 858 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
860 } | 859 } |
861 | 860 |
862 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 861 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
863 return id % 2 != next_outgoing_stream_id_ % 2; | 862 return id % 2 != next_outgoing_stream_id_ % 2; |
864 } | 863 } |
865 | 864 |
866 } // namespace net | 865 } // namespace net |
OLD | NEW |