QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | #ifndef QUICHE_QUIC_CORE_LEGACY_QUIC_STREAM_ID_MANAGER_H_ |
| 5 | #define QUICHE_QUIC_CORE_LEGACY_QUIC_STREAM_ID_MANAGER_H_ |
| 6 | |
| 7 | #include "net/third_party/quiche/src/quic/core/quic_stream_id_manager.h" |
| 8 | |
| 9 | namespace quic { |
| 10 | |
| 11 | namespace test { |
| 12 | class QuicSessionPeer; |
| 13 | } // namespace test |
| 14 | |
| 15 | class QuicSession; |
| 16 | |
| 17 | // Manages Google QUIC stream IDs. This manager is responsible for two |
| 18 | // questions: 1) can next outgoing stream ID be allocated (if yes, what is the |
| 19 | // next outgoing stream ID) and 2) can a new incoming stream be opened. |
| 20 | class QUIC_EXPORT_PRIVATE LegacyQuicStreamIdManager { |
| 21 | public: |
| 22 | LegacyQuicStreamIdManager(QuicSession* session, |
| 23 | size_t max_open_outgoing_streams, |
| 24 | size_t max_open_incoming_streams); |
| 25 | |
| 26 | ~LegacyQuicStreamIdManager(); |
| 27 | |
| 28 | // Returns true if the next outgoing stream ID can be allocated. |
| 29 | bool CanOpenNextOutgoingStream( |
| 30 | size_t current_num_open_outgoing_streams) const; |
| 31 | |
| 32 | // Returns true if a new incoming stream can be opened. |
| 33 | bool CanOpenIncomingStream(size_t current_num_open_incoming_streams) const; |
| 34 | |
| 35 | bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId id); |
| 36 | |
| 37 | // Returns true if |id| is still available. |
| 38 | bool IsAvailableStream(QuicStreamId id) const; |
| 39 | |
| 40 | // Returns the stream ID for a new outgoing stream, and increments the |
| 41 | // underlying counter. |
| 42 | QuicStreamId GetNextOutgoingStreamId(); |
| 43 | |
| 44 | // Return true if |id| is peer initiated. |
| 45 | bool IsIncomingStream(QuicStreamId id) const; |
| 46 | |
| 47 | size_t MaxAvailableStreams() const; |
| 48 | |
| 49 | void set_max_open_incoming_streams(size_t max_open_incoming_streams) { |
| 50 | max_open_incoming_streams_ = max_open_incoming_streams; |
| 51 | } |
| 52 | |
| 53 | void set_max_open_outgoing_streams(size_t max_open_outgoing_streams) { |
| 54 | max_open_outgoing_streams_ = max_open_outgoing_streams; |
| 55 | } |
| 56 | |
| 57 | void set_largest_peer_created_stream_id( |
| 58 | QuicStreamId largest_peer_created_stream_id) { |
| 59 | largest_peer_created_stream_id_ = largest_peer_created_stream_id; |
| 60 | } |
| 61 | |
| 62 | size_t max_open_incoming_streams() const { |
| 63 | return max_open_incoming_streams_; |
| 64 | } |
| 65 | |
| 66 | size_t max_open_outgoing_streams() const { |
| 67 | return max_open_outgoing_streams_; |
| 68 | } |
| 69 | |
| 70 | QuicStreamId next_outgoing_stream_id() const { |
| 71 | return next_outgoing_stream_id_; |
| 72 | } |
| 73 | |
| 74 | QuicStreamId largest_peer_created_stream_id() const { |
| 75 | return largest_peer_created_stream_id_; |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | friend class test::QuicSessionPeer; |
| 80 | |
| 81 | size_t GetNumAvailableStreams() const; |
| 82 | |
| 83 | // Not owned. |
| 84 | QuicSession* session_; |
| 85 | |
| 86 | // The maximum number of outgoing streams this connection can open. |
| 87 | size_t max_open_outgoing_streams_; |
| 88 | |
| 89 | // The maximum number of incoming streams this connection will allow. |
| 90 | size_t max_open_incoming_streams_; |
| 91 | |
| 92 | // The ID to use for the next outgoing stream. |
| 93 | QuicStreamId next_outgoing_stream_id_; |
| 94 | |
| 95 | // Set of stream ids that are less than the largest stream id that has been |
| 96 | // received, but are nonetheless available to be created. |
| 97 | QuicUnorderedSet<QuicStreamId> available_streams_; |
| 98 | |
| 99 | QuicStreamId largest_peer_created_stream_id_; |
| 100 | }; |
| 101 | |
| 102 | } // namespace quic |
| 103 | |
| 104 | #endif // QUICHE_QUIC_CORE_LEGACY_QUIC_STREAM_ID_MANAGER_H_ |