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 #include "net/quic/crypto/proof_verifier.h" | 8 #include "net/quic/crypto/proof_verifier.h" |
9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 stream->OnStreamFrame(frame); | 150 stream->OnStreamFrame(frame); |
151 } | 151 } |
152 | 152 |
153 void QuicSession::OnRstStream(const QuicRstStreamFrame& frame) { | 153 void QuicSession::OnRstStream(const QuicRstStreamFrame& frame) { |
154 if (ContainsKey(static_stream_map_, frame.stream_id)) { | 154 if (ContainsKey(static_stream_map_, frame.stream_id)) { |
155 connection()->SendConnectionCloseWithDetails( | 155 connection()->SendConnectionCloseWithDetails( |
156 QUIC_INVALID_STREAM_ID, "Attempt to reset a static stream"); | 156 QUIC_INVALID_STREAM_ID, "Attempt to reset a static stream"); |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 ReliableQuicStream* stream = GetDynamicStream(frame.stream_id); | 160 ReliableQuicStream* stream = GetOrCreateDynamicStream(frame.stream_id); |
161 if (!stream) { | 161 if (!stream) { |
162 // The RST frame contains the final byte offset for the stream: we can now | 162 // The RST frame contains the final byte offset for the stream: we can now |
163 // update the connection level flow controller if needed. | 163 // update the connection level flow controller if needed. |
164 UpdateFlowControlOnFinalReceivedByteOffset(frame.stream_id, | 164 UpdateFlowControlOnFinalReceivedByteOffset(frame.stream_id, |
165 frame.byte_offset); | 165 frame.byte_offset); |
166 return; // Errors are handled by GetStream. | 166 return; // Errors are handled by GetStream. |
167 } | 167 } |
168 | 168 |
169 stream->OnStreamReset(frame); | 169 stream->OnStreamReset(frame); |
170 } | 170 } |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 QuicStreamId id = next_outgoing_stream_id_; | 563 QuicStreamId id = next_outgoing_stream_id_; |
564 next_outgoing_stream_id_ += 2; | 564 next_outgoing_stream_id_ += 2; |
565 return id; | 565 return id; |
566 } | 566 } |
567 | 567 |
568 ReliableQuicStream* QuicSession::GetStream(const QuicStreamId stream_id) { | 568 ReliableQuicStream* QuicSession::GetStream(const QuicStreamId stream_id) { |
569 StreamMap::iterator it = static_stream_map_.find(stream_id); | 569 StreamMap::iterator it = static_stream_map_.find(stream_id); |
570 if (it != static_stream_map_.end()) { | 570 if (it != static_stream_map_.end()) { |
571 return it->second; | 571 return it->second; |
572 } | 572 } |
573 return GetDynamicStream(stream_id); | 573 return GetOrCreateDynamicStream(stream_id); |
574 } | 574 } |
575 | 575 |
576 void QuicSession::StreamDraining(QuicStreamId stream_id) { | 576 void QuicSession::StreamDraining(QuicStreamId stream_id) { |
577 DCHECK(ContainsKey(dynamic_stream_map_, stream_id)); | 577 DCHECK(ContainsKey(dynamic_stream_map_, stream_id)); |
578 if (!ContainsKey(draining_streams_, stream_id)) { | 578 if (!ContainsKey(draining_streams_, stream_id)) { |
579 draining_streams_.insert(stream_id); | 579 draining_streams_.insert(stream_id); |
580 } | 580 } |
581 } | 581 } |
582 | 582 |
583 void QuicSession::CloseConnection(QuicErrorCode error) { | 583 void QuicSession::CloseConnection(QuicErrorCode error) { |
584 if (connection()->connected()) { | 584 if (connection()->connected()) { |
585 connection()->SendConnectionClose(error); | 585 connection()->SendConnectionClose(error); |
586 } | 586 } |
587 } | 587 } |
588 | 588 |
589 ReliableQuicStream* QuicSession::GetDynamicStream( | 589 ReliableQuicStream* QuicSession::GetOrCreateDynamicStream( |
590 const QuicStreamId stream_id) { | 590 const QuicStreamId stream_id) { |
591 if (static_stream_map_.find(stream_id) != static_stream_map_.end()) { | 591 if (ContainsKey(static_stream_map_, stream_id)) { |
592 DLOG(FATAL) << "Attempt to call GetDynamicStream for a static stream"; | 592 DLOG(FATAL) |
| 593 << "Attempt to call GetOrCreateDynamicStream for a static stream"; |
593 return nullptr; | 594 return nullptr; |
594 } | 595 } |
595 | 596 |
596 StreamMap::iterator it = dynamic_stream_map_.find(stream_id); | 597 StreamMap::iterator it = dynamic_stream_map_.find(stream_id); |
597 if (it != dynamic_stream_map_.end()) { | 598 if (it != dynamic_stream_map_.end()) { |
598 return it->second; | 599 return it->second; |
599 } | 600 } |
600 | 601 |
601 if (IsClosedStream(stream_id)) { | 602 if (IsClosedStream(stream_id)) { |
602 return nullptr; | 603 return nullptr; |
603 } | 604 } |
604 | 605 |
605 if (stream_id % 2 == next_outgoing_stream_id_ % 2) { | 606 if (stream_id % 2 == next_outgoing_stream_id_ % 2) { |
606 // We've received a frame for a locally-created stream that is not | 607 // Received a frame for a locally-created stream that is not currently |
607 // currently active. This is an error. | 608 // active. This is an error. |
608 CloseConnection(QUIC_PACKET_FOR_NONEXISTENT_STREAM); | 609 CloseConnection(QUIC_INVALID_STREAM_ID); |
609 return nullptr; | 610 return nullptr; |
610 } | 611 } |
611 | 612 |
612 return GetIncomingDynamicStream(stream_id); | |
613 } | |
614 | |
615 ReliableQuicStream* QuicSession::GetIncomingDynamicStream( | |
616 QuicStreamId stream_id) { | |
617 if (IsClosedStream(stream_id)) { | |
618 return nullptr; | |
619 } | |
620 available_streams_.erase(stream_id); | 613 available_streams_.erase(stream_id); |
621 | 614 |
622 // Legitimate streams created by the peer are alternately-numbered. | |
623 if (FLAGS_allow_many_available_streams && | |
624 stream_id % 2 != largest_peer_created_stream_id_ % 2) { | |
625 // Close the connection. | |
626 DVLOG(1) << "Invalid incoming stream_id " << stream_id; | |
627 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); | |
628 return nullptr; | |
629 } | |
630 | |
631 if (stream_id > largest_peer_created_stream_id_) { | 615 if (stream_id > largest_peer_created_stream_id_) { |
632 if (FLAGS_allow_many_available_streams) { | 616 if (FLAGS_allow_many_available_streams) { |
633 // Check if the new number of available streams would cause the number of | 617 // Check if the new number of available streams would cause the number of |
634 // available streams to exceed the limit. Note that the peer can create | 618 // available streams to exceed the limit. Note that the peer can create |
635 // only alternately-numbered streams. | 619 // only alternately-numbered streams. |
636 size_t additional_available_streams = | 620 size_t additional_available_streams = |
637 (stream_id - largest_peer_created_stream_id_) / 2 - 1; | 621 (stream_id - largest_peer_created_stream_id_) / 2 - 1; |
638 size_t new_num_available_streams = | 622 size_t new_num_available_streams = |
639 GetNumAvailableStreams() + additional_available_streams; | 623 GetNumAvailableStreams() + additional_available_streams; |
640 if (new_num_available_streams > get_max_available_streams()) { | 624 if (new_num_available_streams > get_max_available_streams()) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 } | 796 } |
813 for (auto const& kv : dynamic_stream_map_) { | 797 for (auto const& kv : dynamic_stream_map_) { |
814 if (kv.second->flow_controller()->IsBlocked()) { | 798 if (kv.second->flow_controller()->IsBlocked()) { |
815 return true; | 799 return true; |
816 } | 800 } |
817 } | 801 } |
818 return false; | 802 return false; |
819 } | 803 } |
820 | 804 |
821 } // namespace net | 805 } // namespace net |
OLD | NEW |