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 26 matching lines...) Expand all Loading... |
37 num_draining_incoming_streams_(0), | 37 num_draining_incoming_streams_(0), |
38 num_locally_closed_incoming_streams_highest_offset_(0), | 38 num_locally_closed_incoming_streams_highest_offset_(0), |
39 error_(QUIC_NO_ERROR), | 39 error_(QUIC_NO_ERROR), |
40 flow_controller_(connection_, | 40 flow_controller_(connection_, |
41 0, | 41 0, |
42 perspective(), | 42 perspective(), |
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 respect_goaway_(true) {} |
48 | 49 |
49 void QuicSession::Initialize() { | 50 void QuicSession::Initialize() { |
50 connection_->set_visitor(this); | 51 connection_->set_visitor(this); |
51 connection_->SetFromConfig(config_); | 52 connection_->SetFromConfig(config_); |
52 | 53 |
53 DCHECK_EQ(kCryptoStreamId, GetMutableCryptoStream()->id()); | 54 DCHECK_EQ(kCryptoStreamId, GetMutableCryptoStream()->id()); |
54 static_stream_map_[kCryptoStreamId] = GetMutableCryptoStream(); | 55 static_stream_map_[kCryptoStreamId] = GetMutableCryptoStream(); |
55 } | 56 } |
56 | 57 |
57 QuicSession::~QuicSession() { | 58 QuicSession::~QuicSession() { |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 if (!IsIncomingStream(stream_id)) { | 714 if (!IsIncomingStream(stream_id)) { |
714 HandleFrameOnNonexistentOutgoingStream(stream_id); | 715 HandleFrameOnNonexistentOutgoingStream(stream_id); |
715 return nullptr; | 716 return nullptr; |
716 } | 717 } |
717 | 718 |
718 available_streams_.erase(stream_id); | 719 available_streams_.erase(stream_id); |
719 | 720 |
720 if (!MaybeIncreaseLargestPeerStreamId(stream_id)) { | 721 if (!MaybeIncreaseLargestPeerStreamId(stream_id)) { |
721 return nullptr; | 722 return nullptr; |
722 } | 723 } |
| 724 |
| 725 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 726 return MaybeCreateIncomingDynamicStream(stream_id); |
| 727 } |
| 728 |
723 // Check if the new number of open streams would cause the number of | 729 // Check if the new number of open streams would cause the number of |
724 // open streams to exceed the limit. | 730 // open streams to exceed the limit. |
725 if (GetNumOpenIncomingStreams() >= max_open_incoming_streams()) { | 731 if (GetNumOpenIncomingStreams() >= max_open_incoming_streams()) { |
726 // Refuse to open the stream. | 732 // Refuse to open the stream. |
727 SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0); | 733 SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0); |
728 return nullptr; | 734 return nullptr; |
729 } | 735 } |
730 | 736 |
731 return CreateIncomingDynamicStream(stream_id); | 737 return CreateIncomingDynamicStream(stream_id); |
732 } | 738 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 } | 865 } |
860 | 866 |
861 size_t QuicSession::MaxAvailableStreams() const { | 867 size_t QuicSession::MaxAvailableStreams() const { |
862 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 868 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
863 } | 869 } |
864 | 870 |
865 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 871 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
866 return id % 2 != next_outgoing_stream_id_ % 2; | 872 return id % 2 != next_outgoing_stream_id_ % 2; |
867 } | 873 } |
868 | 874 |
| 875 bool QuicSession::ShouldCreateIncomingDynamicStream2(QuicStreamId id) { |
| 876 DCHECK(FLAGS_quic_reloadable_flag_quic_refactor_stream_creation); |
| 877 if (goaway_received() && respect_goaway_) { |
| 878 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 879 << "Already received goaway."; |
| 880 return false; |
| 881 } |
| 882 if (!IsIncomingStream(id)) { |
| 883 QUIC_DLOG(INFO) << "invalid incoming stream id: " << id; |
| 884 return false; |
| 885 } |
| 886 if (!connection()->connected()) { |
| 887 QUIC_DLOG(INFO) |
| 888 << "ShouldCreateIncomingDynamicStream called when disconnected"; |
| 889 return false; |
| 890 } |
| 891 if (GetNumOpenIncomingStreams() >= max_open_incoming_streams()) { |
| 892 DVLOG(1) << "Reset stream (refused) " << id; |
| 893 SendRstStream(id, QUIC_REFUSED_STREAM, 0); |
| 894 return false; |
| 895 } |
| 896 |
| 897 return true; |
| 898 } |
| 899 |
| 900 bool QuicSession::ShouldCreateOutgoingDynamicStream2() { |
| 901 DCHECK(FLAGS_quic_reloadable_flag_quic_refactor_stream_creation); |
| 902 if (!connection()->connected()) { |
| 903 QUIC_DLOG(INFO) |
| 904 << "ShouldCreateOutgoingDynamicStream called when disconnected"; |
| 905 return false; |
| 906 } |
| 907 if (!IsEncryptionEstablished()) { |
| 908 QUIC_DLOG(INFO) << "Encryption not established so no outgoing stream " |
| 909 << "created."; |
| 910 return false; |
| 911 } |
| 912 if (goaway_received() && respect_goaway_) { |
| 913 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 914 << "Already received goaway."; |
| 915 return false; |
| 916 } |
| 917 if (GetNumOpenOutgoingStreams() >= max_open_outgoing_streams()) { |
| 918 QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. " |
| 919 << "Already " << GetNumOpenOutgoingStreams() << " open."; |
| 920 return false; |
| 921 } |
| 922 return true; |
| 923 } |
| 924 |
| 925 QuicStream* QuicSession::MaybeCreateIncomingDynamicStream(QuicStreamId id) { |
| 926 if (!ShouldCreateIncomingDynamicStream2(id)) { |
| 927 return nullptr; |
| 928 } |
| 929 return CreateAndActivateStream(id); |
| 930 } |
| 931 |
| 932 QuicStream* QuicSession::MaybeCreateOutgoingDynamicStream( |
| 933 SpdyPriority priority) { |
| 934 if (!ShouldCreateOutgoingDynamicStream2()) { |
| 935 return nullptr; |
| 936 } |
| 937 return CreateAndActivateStream(GetNextOutgoingStreamId()); |
| 938 } |
| 939 |
| 940 QuicStream* QuicSession::CreateAndActivateStream(QuicStreamId id) { |
| 941 std::unique_ptr<QuicStream> stream = CreateStream(id); |
| 942 QuicStream* stream_ptr = stream.get(); |
| 943 ActivateStream(std::move(stream)); |
| 944 return stream_ptr; |
| 945 } |
| 946 |
869 } // namespace net | 947 } // namespace net |
OLD | NEW |