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 | |
| 5 | #ifndef QUICHE_QUIC_CORE_UBER_QUIC_STREAM_ID_MANAGER_H_ |
| 6 | #define QUICHE_QUIC_CORE_UBER_QUIC_STREAM_ID_MANAGER_H_ |
| 7 | |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 8 | #include "quic/core/quic_stream_id_manager.h" |
| 9 | #include "quic/core/quic_types.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 11 | namespace quic { |
| 12 | |
| 13 | namespace test { |
| 14 | class QuicSessionPeer; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 15 | class UberQuicStreamIdManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | } // namespace test |
| 17 | |
| 18 | class QuicSession; |
| 19 | |
| 20 | // This class comprises two QuicStreamIdManagers, which manage bidirectional and |
| 21 | // unidirectional stream IDs, respectively. |
| 22 | class QUIC_EXPORT_PRIVATE UberQuicStreamIdManager { |
| 23 | public: |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 24 | UberQuicStreamIdManager( |
rch | d40f903 | 2019-09-23 07:27:04 -0700 | [diff] [blame] | 25 | Perspective perspective, |
| 26 | ParsedQuicVersion version, |
| 27 | QuicStreamIdManager::DelegateInterface* delegate, |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 28 | QuicStreamCount max_open_outgoing_bidirectional_streams, |
| 29 | QuicStreamCount max_open_outgoing_unidirectional_streams, |
| 30 | QuicStreamCount max_open_incoming_bidirectional_streams, |
| 31 | QuicStreamCount max_open_incoming_unidirectional_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 32 | |
renjietang | ab9039a | 2020-03-30 14:53:19 -0700 | [diff] [blame] | 33 | // Called on |max_open_streams| outgoing streams can be created because of 1) |
| 34 | // config negotiated or 2) MAX_STREAMS received. Returns true if new |
| 35 | // streams can be created. |
| 36 | bool MaybeAllowNewOutgoingBidirectionalStreams( |
renjietang | 52e1338 | 2019-12-16 15:58:04 -0800 | [diff] [blame] | 37 | QuicStreamCount max_open_streams); |
renjietang | ab9039a | 2020-03-30 14:53:19 -0700 | [diff] [blame] | 38 | bool MaybeAllowNewOutgoingUnidirectionalStreams( |
| 39 | QuicStreamCount max_open_streams); |
| 40 | |
| 41 | // Sets the limits to max_open_streams. |
renjietang | 52e1338 | 2019-12-16 15:58:04 -0800 | [diff] [blame] | 42 | void SetMaxOpenIncomingBidirectionalStreams(QuicStreamCount max_open_streams); |
| 43 | void SetMaxOpenIncomingUnidirectionalStreams( |
| 44 | QuicStreamCount max_open_streams); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 45 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 46 | // Returns true if next outgoing bidirectional stream ID can be allocated. |
fayang | 769172b | 2020-03-19 14:27:39 -0700 | [diff] [blame] | 47 | bool CanOpenNextOutgoingBidirectionalStream() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | |
| 49 | // Returns true if next outgoing unidirectional stream ID can be allocated. |
fayang | 769172b | 2020-03-19 14:27:39 -0700 | [diff] [blame] | 50 | bool CanOpenNextOutgoingUnidirectionalStream() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 51 | |
| 52 | // Returns the next outgoing bidirectional stream id. |
| 53 | QuicStreamId GetNextOutgoingBidirectionalStreamId(); |
| 54 | |
| 55 | // Returns the next outgoing unidirectional stream id. |
| 56 | QuicStreamId GetNextOutgoingUnidirectionalStreamId(); |
| 57 | |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 58 | // Returns true if the incoming |id| is within the limit. |
renjietang | 7133ea9 | 2020-04-01 12:49:36 -0700 | [diff] [blame] | 59 | bool MaybeIncreaseLargestPeerStreamId(QuicStreamId id, |
| 60 | std::string* error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | |
| 62 | // Called when |id| is released. |
| 63 | void OnStreamClosed(QuicStreamId id); |
| 64 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 65 | // Called when a STREAMS_BLOCKED frame is received. |
renjietang | 7133ea9 | 2020-04-01 12:49:36 -0700 | [diff] [blame] | 66 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame, |
| 67 | std::string* error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 68 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 69 | // Returns true if |id| is still available. |
| 70 | bool IsAvailableStream(QuicStreamId id) const; |
| 71 | |
renjietang | 52e1338 | 2019-12-16 15:58:04 -0800 | [diff] [blame] | 72 | QuicStreamCount GetMaxAllowdIncomingBidirectionalStreams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 73 | |
renjietang | 52e1338 | 2019-12-16 15:58:04 -0800 | [diff] [blame] | 74 | QuicStreamCount GetMaxAllowdIncomingUnidirectionalStreams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 75 | |
renjietang | 686ce58 | 2019-10-17 14:28:16 -0700 | [diff] [blame] | 76 | QuicStreamId GetLargestPeerCreatedStreamId(bool unidirectional) const; |
| 77 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 78 | QuicStreamId next_outgoing_bidirectional_stream_id() const; |
| 79 | QuicStreamId next_outgoing_unidirectional_stream_id() const; |
| 80 | |
renjietang | 52e1338 | 2019-12-16 15:58:04 -0800 | [diff] [blame] | 81 | QuicStreamCount max_outgoing_bidirectional_streams() const; |
| 82 | QuicStreamCount max_outgoing_unidirectional_streams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 83 | |
ianswett | d141453 | 2019-09-18 20:12:59 -0700 | [diff] [blame] | 84 | QuicStreamCount max_incoming_bidirectional_streams() const; |
| 85 | QuicStreamCount max_incoming_unidirectional_streams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 86 | |
ianswett | d141453 | 2019-09-18 20:12:59 -0700 | [diff] [blame] | 87 | QuicStreamCount advertised_max_incoming_bidirectional_streams() const; |
| 88 | QuicStreamCount advertised_max_incoming_unidirectional_streams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 89 | |
renjietang | faf8b02 | 2020-06-08 20:06:44 -0700 | [diff] [blame] | 90 | QuicStreamCount outgoing_bidirectional_stream_count() const; |
| 91 | QuicStreamCount outgoing_unidirectional_stream_count() const; |
| 92 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 93 | private: |
| 94 | friend class test::QuicSessionPeer; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 95 | friend class test::UberQuicStreamIdManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 96 | |
renjietang | d262e25 | 2020-06-19 15:11:24 -0700 | [diff] [blame] | 97 | ParsedQuicVersion version_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 98 | // Manages stream IDs of bidirectional streams. |
| 99 | QuicStreamIdManager bidirectional_stream_id_manager_; |
| 100 | |
| 101 | // Manages stream IDs of unidirectional streams. |
| 102 | QuicStreamIdManager unidirectional_stream_id_manager_; |
| 103 | }; |
| 104 | |
| 105 | } // namespace quic |
| 106 | |
| 107 | #endif // QUICHE_QUIC_CORE_UBER_QUIC_STREAM_ID_MANAGER_H_ |