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) {} | |
49 | 48 |
50 void QuicSession::Initialize() { | 49 void QuicSession::Initialize() { |
51 connection_->set_visitor(this); | 50 connection_->set_visitor(this); |
52 connection_->SetFromConfig(config_); | 51 connection_->SetFromConfig(config_); |
53 | 52 |
54 DCHECK_EQ(kCryptoStreamId, GetMutableCryptoStream()->id()); | 53 DCHECK_EQ(kCryptoStreamId, GetMutableCryptoStream()->id()); |
55 static_stream_map_[kCryptoStreamId] = GetMutableCryptoStream(); | 54 static_stream_map_[kCryptoStreamId] = GetMutableCryptoStream(); |
56 } | 55 } |
57 | 56 |
58 QuicSession::~QuicSession() { | 57 QuicSession::~QuicSession() { |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 if (!IsIncomingStream(stream_id)) { | 713 if (!IsIncomingStream(stream_id)) { |
715 HandleFrameOnNonexistentOutgoingStream(stream_id); | 714 HandleFrameOnNonexistentOutgoingStream(stream_id); |
716 return nullptr; | 715 return nullptr; |
717 } | 716 } |
718 | 717 |
719 available_streams_.erase(stream_id); | 718 available_streams_.erase(stream_id); |
720 | 719 |
721 if (!MaybeIncreaseLargestPeerStreamId(stream_id)) { | 720 if (!MaybeIncreaseLargestPeerStreamId(stream_id)) { |
722 return nullptr; | 721 return nullptr; |
723 } | 722 } |
724 | |
725 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { | |
726 return MaybeCreateIncomingDynamicStream(stream_id); | |
727 } | |
728 | |
729 // Check if the new number of open streams would cause the number of | 723 // Check if the new number of open streams would cause the number of |
730 // open streams to exceed the limit. | 724 // open streams to exceed the limit. |
731 if (GetNumOpenIncomingStreams() >= max_open_incoming_streams()) { | 725 if (GetNumOpenIncomingStreams() >= max_open_incoming_streams()) { |
732 // Refuse to open the stream. | 726 // Refuse to open the stream. |
733 SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0); | 727 SendRstStream(stream_id, QUIC_REFUSED_STREAM, 0); |
734 return nullptr; | 728 return nullptr; |
735 } | 729 } |
736 | 730 |
737 return CreateIncomingDynamicStream(stream_id); | 731 return CreateIncomingDynamicStream(stream_id); |
738 } | 732 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 } | 859 } |
866 | 860 |
867 size_t QuicSession::MaxAvailableStreams() const { | 861 size_t QuicSession::MaxAvailableStreams() const { |
868 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; | 862 return max_open_incoming_streams_ * kMaxAvailableStreamsMultiplier; |
869 } | 863 } |
870 | 864 |
871 bool QuicSession::IsIncomingStream(QuicStreamId id) const { | 865 bool QuicSession::IsIncomingStream(QuicStreamId id) const { |
872 return id % 2 != next_outgoing_stream_id_ % 2; | 866 return id % 2 != next_outgoing_stream_id_ % 2; |
873 } | 867 } |
874 | 868 |
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 | |
947 } // namespace net | 869 } // namespace net |
OLD | NEW |