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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 // Locally created streams are strictly in-order. If the id is in the | 705 // Locally created streams are strictly in-order. If the id is in the |
706 // range of created streams and it's not active, it must have been closed. | 706 // range of created streams and it's not active, it must have been closed. |
707 return id < next_outgoing_stream_id_; | 707 return id < next_outgoing_stream_id_; |
708 } | 708 } |
709 // For peer created streams, we also need to consider available streams. | 709 // For peer created streams, we also need to consider available streams. |
710 return id <= largest_peer_created_stream_id_ && | 710 return id <= largest_peer_created_stream_id_ && |
711 !ContainsKey(available_streams_, id); | 711 !ContainsKey(available_streams_, id); |
712 } | 712 } |
713 | 713 |
714 size_t QuicSession::GetNumOpenStreams() const { | 714 size_t QuicSession::GetNumOpenStreams() const { |
715 if (FLAGS_quic_count_unfinished_as_open_streams) { | 715 if (FLAGS_allow_many_available_streams) { |
716 if (FLAGS_allow_many_available_streams) { | 716 return dynamic_stream_map_.size() - draining_streams_.size() + |
717 return dynamic_stream_map_.size() - draining_streams_.size() + | 717 locally_closed_streams_highest_offset_.size(); |
718 locally_closed_streams_highest_offset_.size(); | |
719 } else { | |
720 return dynamic_stream_map_.size() + available_streams_.size() - | |
721 draining_streams_.size() + | |
722 locally_closed_streams_highest_offset_.size(); | |
723 } | |
724 } else { | 718 } else { |
725 if (FLAGS_allow_many_available_streams) { | 719 return dynamic_stream_map_.size() + available_streams_.size() - |
726 return dynamic_stream_map_.size() - draining_streams_.size(); | 720 draining_streams_.size() + |
727 } else { | 721 locally_closed_streams_highest_offset_.size(); |
728 return dynamic_stream_map_.size() + available_streams_.size() - | |
729 draining_streams_.size(); | |
730 } | |
731 } | 722 } |
732 } | 723 } |
733 | 724 |
734 size_t QuicSession::GetNumActiveStreams() const { | 725 size_t QuicSession::GetNumActiveStreams() const { |
735 if (FLAGS_quic_count_unfinished_as_open_streams) { | 726 return GetNumOpenStreams() - locally_closed_streams_highest_offset_.size(); |
736 return GetNumOpenStreams() - locally_closed_streams_highest_offset_.size(); | |
737 } else { | |
738 return GetNumOpenStreams(); | |
739 } | |
740 } | 727 } |
741 | 728 |
742 size_t QuicSession::GetNumAvailableStreams() const { | 729 size_t QuicSession::GetNumAvailableStreams() const { |
743 return available_streams_.size(); | 730 return available_streams_.size(); |
744 } | 731 } |
745 | 732 |
746 void QuicSession::MarkConnectionLevelWriteBlocked(QuicStreamId id, | 733 void QuicSession::MarkConnectionLevelWriteBlocked(QuicStreamId id, |
747 QuicPriority priority) { | 734 QuicPriority priority) { |
748 #ifndef NDEBUG | 735 #ifndef NDEBUG |
749 ReliableQuicStream* stream = GetStream(id); | 736 ReliableQuicStream* stream = GetStream(id); |
(...skipping 19 matching lines...) Expand all Loading... |
769 } | 756 } |
770 | 757 |
771 bool QuicSession::HasDataToWrite() const { | 758 bool QuicSession::HasDataToWrite() const { |
772 return write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() || | 759 return write_blocked_streams_.HasWriteBlockedCryptoOrHeadersStream() || |
773 write_blocked_streams_.HasWriteBlockedDataStreams() || | 760 write_blocked_streams_.HasWriteBlockedDataStreams() || |
774 connection_->HasQueuedData(); | 761 connection_->HasQueuedData(); |
775 } | 762 } |
776 | 763 |
777 void QuicSession::PostProcessAfterData() { | 764 void QuicSession::PostProcessAfterData() { |
778 STLDeleteElements(&closed_streams_); | 765 STLDeleteElements(&closed_streams_); |
779 | 766 closed_streams_.clear(); |
780 // A buggy client may fail to send FIN/RSTs. Don't tolerate this. | |
781 if (!FLAGS_quic_count_unfinished_as_open_streams && | |
782 locally_closed_streams_highest_offset_.size() > max_open_streams_) { | |
783 CloseConnection(QUIC_TOO_MANY_UNFINISHED_STREAMS); | |
784 } | |
785 } | 767 } |
786 | 768 |
787 bool QuicSession::IsConnectionFlowControlBlocked() const { | 769 bool QuicSession::IsConnectionFlowControlBlocked() const { |
788 return flow_controller_.IsBlocked(); | 770 return flow_controller_.IsBlocked(); |
789 } | 771 } |
790 | 772 |
791 bool QuicSession::IsStreamFlowControlBlocked() { | 773 bool QuicSession::IsStreamFlowControlBlocked() { |
792 for (auto const& kv : static_stream_map_) { | 774 for (auto const& kv : static_stream_map_) { |
793 if (kv.second->flow_controller()->IsBlocked()) { | 775 if (kv.second->flow_controller()->IsBlocked()) { |
794 return true; | 776 return true; |
795 } | 777 } |
796 } | 778 } |
797 for (auto const& kv : dynamic_stream_map_) { | 779 for (auto const& kv : dynamic_stream_map_) { |
798 if (kv.second->flow_controller()->IsBlocked()) { | 780 if (kv.second->flow_controller()->IsBlocked()) { |
799 return true; | 781 return true; |
800 } | 782 } |
801 } | 783 } |
802 return false; | 784 return false; |
803 } | 785 } |
804 | 786 |
805 } // namespace net | 787 } // namespace net |
OLD | NEW |