diff options
Diffstat (limited to 'chromium/net/third_party/quiche/src/quic/core/quic_stream_id_manager.cc')
-rw-r--r-- | chromium/net/third_party/quiche/src/quic/core/quic_stream_id_manager.cc | 96 |
1 files changed, 32 insertions, 64 deletions
diff --git a/chromium/net/third_party/quiche/src/quic/core/quic_stream_id_manager.cc b/chromium/net/third_party/quiche/src/quic/core/quic_stream_id_manager.cc index c6869a23b12..ba31decd2b9 100644 --- a/chromium/net/third_party/quiche/src/quic/core/quic_stream_id_manager.cc +++ b/chromium/net/third_party/quiche/src/quic/core/quic_stream_id_manager.cc @@ -10,6 +10,7 @@ #include "net/third_party/quiche/src/quic/core/quic_constants.h" #include "net/third_party/quiche/src/quic/core/quic_session.h" #include "net/third_party/quiche/src/quic/core/quic_utils.h" +#include "net/third_party/quiche/src/quic/core/quic_versions.h" #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h" #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" @@ -24,40 +25,31 @@ QuicStreamIdManager::QuicStreamIdManager( DelegateInterface* delegate, bool unidirectional, Perspective perspective, - QuicTransportVersion transport_version, + ParsedQuicVersion version, QuicStreamCount max_allowed_outgoing_streams, QuicStreamCount max_allowed_incoming_streams) : delegate_(delegate), unidirectional_(unidirectional), perspective_(perspective), - transport_version_(transport_version), + version_(version), outgoing_max_streams_(max_allowed_outgoing_streams), next_outgoing_stream_id_(GetFirstOutgoingStreamId()), outgoing_stream_count_(0), incoming_actual_max_streams_(max_allowed_incoming_streams), - // Advertised max starts at actual because it's communicated in the - // handshake. incoming_advertised_max_streams_(max_allowed_incoming_streams), incoming_initial_max_open_streams_(max_allowed_incoming_streams), incoming_stream_count_(0), largest_peer_created_stream_id_( - QuicUtils::GetInvalidStreamId(transport_version)), - max_streams_window_(0) { - CalculateIncomingMaxStreamsWindow(); -} + QuicUtils::GetInvalidStreamId(version.transport_version)) {} QuicStreamIdManager::~QuicStreamIdManager() {} -// The peer sends a streams blocked frame when it can not open any more -// streams because it has runs into the limit. bool QuicStreamIdManager::OnStreamsBlockedFrame( const QuicStreamsBlockedFrame& frame, std::string* error_details) { - // Ensure that the frame has the correct directionality. DCHECK_EQ(frame.unidirectional, unidirectional_); if (frame.stream_count > incoming_advertised_max_streams_) { // Peer thinks it can send more streams that we've told it. - // This is a protocol error. *error_details = quiche::QuicheStrCat( "StreamsBlockedFrame's stream count ", frame.stream_count, " exceeds incoming max stream ", incoming_advertised_max_streams_); @@ -65,8 +57,7 @@ bool QuicStreamIdManager::OnStreamsBlockedFrame( } if (frame.stream_count < incoming_actual_max_streams_) { // Peer thinks it's blocked on a stream count that is less than our current - // max. Inform the peer of the correct stream count. Sending a MAX_STREAMS - // frame in this case is not controlled by the window. + // max. Inform the peer of the correct stream count. SendMaxStreamsFrame(); } return true; @@ -90,8 +81,9 @@ bool QuicStreamIdManager::MaybeAllowNewOutgoingStreams( void QuicStreamIdManager::SetMaxOpenIncomingStreams( QuicStreamCount max_open_streams) { QUIC_BUG_IF(incoming_stream_count_ > 0) - << "non-zero stream count when setting max incoming stream."; - QUIC_LOG_IF(WARNING, incoming_initial_max_open_streams_ != max_open_streams) + << "non-zero incoming stream count " << incoming_stream_count_ + << " when setting max incoming stream to " << max_open_streams; + QUIC_DLOG_IF(WARNING, incoming_initial_max_open_streams_ != max_open_streams) << quiche::QuicheStrCat( unidirectional_ ? "unidirectional " : "bidirectional: ", "incoming stream limit changed from ", @@ -99,12 +91,12 @@ void QuicStreamIdManager::SetMaxOpenIncomingStreams( incoming_actual_max_streams_ = max_open_streams; incoming_advertised_max_streams_ = max_open_streams; incoming_initial_max_open_streams_ = max_open_streams; - CalculateIncomingMaxStreamsWindow(); } void QuicStreamIdManager::MaybeSendMaxStreamsFrame() { if ((incoming_advertised_max_streams_ - incoming_stream_count_) > - max_streams_window_) { + (incoming_initial_max_open_streams_ / + GetQuicFlag(FLAGS_quic_max_streams_window_divisor))) { // window too large, no advertisement return; } @@ -118,39 +110,36 @@ void QuicStreamIdManager::SendMaxStreamsFrame() { void QuicStreamIdManager::OnStreamClosed(QuicStreamId stream_id) { DCHECK_NE(QuicUtils::IsBidirectionalStreamId(stream_id), unidirectional_); - if (!IsIncomingStream(stream_id)) { + if (QuicUtils::IsOutgoingStreamId(version_, stream_id, perspective_)) { // Nothing to do for outgoing streams. return; } // If the stream is inbound, we can increase the actual stream limit and maybe - // advertise the new limit to the peer. Have to check to make sure that we do - // not exceed the maximum. + // advertise the new limit to the peer. if (incoming_actual_max_streams_ == QuicUtils::GetMaxStreamCount()) { // Reached the maximum stream id value that the implementation // supports. Nothing can be done here. return; } - // One stream closed ... another can be opened. + // One stream closed, and another one can be opened. incoming_actual_max_streams_++; MaybeSendMaxStreamsFrame(); } QuicStreamId QuicStreamIdManager::GetNextOutgoingStreamId() { - // Applications should always consult CanOpenNextOutgoingStream() first. - // If they ask for stream ids that violate the limit, it's an implementation - // bug. QUIC_BUG_IF(outgoing_stream_count_ >= outgoing_max_streams_) << "Attempt to allocate a new outgoing stream that would exceed the " "limit (" << outgoing_max_streams_ << ")"; QuicStreamId id = next_outgoing_stream_id_; - next_outgoing_stream_id_ += QuicUtils::StreamIdDelta(transport_version_); + next_outgoing_stream_id_ += + QuicUtils::StreamIdDelta(version_.transport_version); outgoing_stream_count_++; return id; } bool QuicStreamIdManager::CanOpenNextOutgoingStream() const { - DCHECK(VersionHasIetfQuicFrames(transport_version_)); + DCHECK(VersionHasIetfQuicFrames(version_.transport_version)); return outgoing_stream_count_ < outgoing_max_streams_; } @@ -159,23 +148,25 @@ bool QuicStreamIdManager::MaybeIncreaseLargestPeerStreamId( std::string* error_details) { // |stream_id| must be an incoming stream of the right directionality. DCHECK_NE(QuicUtils::IsBidirectionalStreamId(stream_id), unidirectional_); - DCHECK_NE(QuicUtils::IsServerInitiatedStreamId(transport_version_, stream_id), - perspective() == Perspective::IS_SERVER); + DCHECK_NE(QuicUtils::IsServerInitiatedStreamId(version_.transport_version, + stream_id), + perspective_ == Perspective::IS_SERVER); if (available_streams_.erase(stream_id) == 1) { // stream_id is available. return true; } if (largest_peer_created_stream_id_ != - QuicUtils::GetInvalidStreamId(transport_version_)) { + QuicUtils::GetInvalidStreamId(version_.transport_version)) { DCHECK_GT(stream_id, largest_peer_created_stream_id_); } // Calculate increment of incoming_stream_count_ by creating stream_id. - const QuicStreamCount delta = QuicUtils::StreamIdDelta(transport_version_); + const QuicStreamCount delta = + QuicUtils::StreamIdDelta(version_.transport_version); const QuicStreamId least_new_stream_id = largest_peer_created_stream_id_ == - QuicUtils::GetInvalidStreamId(transport_version_) + QuicUtils::GetInvalidStreamId(version_.transport_version) ? GetFirstIncomingStreamId() : largest_peer_created_stream_id_ + delta; const QuicStreamCount stream_count_increment = @@ -203,59 +194,36 @@ bool QuicStreamIdManager::MaybeIncreaseLargestPeerStreamId( bool QuicStreamIdManager::IsAvailableStream(QuicStreamId id) const { DCHECK_NE(QuicUtils::IsBidirectionalStreamId(id), unidirectional_); - if (!IsIncomingStream(id)) { + if (QuicUtils::IsOutgoingStreamId(version_, id, perspective_)) { // Stream IDs under next_ougoing_stream_id_ are either open or previously // open but now closed. return id >= next_outgoing_stream_id_; } // For peer created streams, we also need to consider available streams. return largest_peer_created_stream_id_ == - QuicUtils::GetInvalidStreamId(transport_version_) || + QuicUtils::GetInvalidStreamId(version_.transport_version) || id > largest_peer_created_stream_id_ || QuicContainsKey(available_streams_, id); } -bool QuicStreamIdManager::IsIncomingStream(QuicStreamId id) const { - DCHECK_NE(QuicUtils::IsBidirectionalStreamId(id), unidirectional_); - // The 0x1 bit in the stream id indicates whether the stream id is - // server- or client- initiated. Next_OUTGOING_stream_id_ has that bit - // set based on whether this node is a server or client. Thus, if the stream - // id in question has the 0x1 bit set opposite of next_OUTGOING_stream_id_, - // then that stream id is incoming -- it is for streams initiated by the peer. - return (id & 0x1) != (next_outgoing_stream_id_ & 0x1); -} - QuicStreamId QuicStreamIdManager::GetFirstOutgoingStreamId() const { return (unidirectional_) ? QuicUtils::GetFirstUnidirectionalStreamId( - transport_version_, perspective()) + version_.transport_version, perspective_) : QuicUtils::GetFirstBidirectionalStreamId( - transport_version_, perspective()); + version_.transport_version, perspective_); } QuicStreamId QuicStreamIdManager::GetFirstIncomingStreamId() const { return (unidirectional_) ? QuicUtils::GetFirstUnidirectionalStreamId( - transport_version_, peer_perspective()) + version_.transport_version, + QuicUtils::InvertPerspective(perspective_)) : QuicUtils::GetFirstBidirectionalStreamId( - transport_version_, peer_perspective()); -} - -Perspective QuicStreamIdManager::perspective() const { - return perspective_; + version_.transport_version, + QuicUtils::InvertPerspective(perspective_)); } -Perspective QuicStreamIdManager::peer_perspective() const { - return QuicUtils::InvertPerspective(perspective()); -} - -QuicStreamCount QuicStreamIdManager::available_incoming_streams() { +QuicStreamCount QuicStreamIdManager::available_incoming_streams() const { return incoming_advertised_max_streams_ - incoming_stream_count_; } -void QuicStreamIdManager::CalculateIncomingMaxStreamsWindow() { - max_streams_window_ = incoming_actual_max_streams_ / kMaxStreamsWindowDivisor; - if (max_streams_window_ == 0) { - max_streams_window_ = 1; - } -} - } // namespace quic |