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 | |
| 8 | #include "net/third_party/quiche/src/quic/core/quic_stream_id_manager.h" |
| 9 | |
| 10 | namespace quic { |
| 11 | |
| 12 | namespace test { |
| 13 | class QuicSessionPeer; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 14 | class UberQuicStreamIdManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | } // namespace test |
| 16 | |
| 17 | class QuicSession; |
| 18 | |
| 19 | // This class comprises two QuicStreamIdManagers, which manage bidirectional and |
| 20 | // unidirectional stream IDs, respectively. |
| 21 | class QUIC_EXPORT_PRIVATE UberQuicStreamIdManager { |
| 22 | public: |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 23 | UberQuicStreamIdManager( |
| 24 | QuicSession* session, |
| 25 | QuicStreamCount max_open_outgoing_bidirectional_streams, |
| 26 | QuicStreamCount max_open_outgoing_unidirectional_streams, |
| 27 | QuicStreamCount max_open_incoming_bidirectional_streams, |
| 28 | QuicStreamCount max_open_incoming_unidirectional_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | |
| 30 | // Called when a stream with |stream_id| is registered as a static stream. |
renjietang | 3a1bb80 | 2019-06-11 10:42:41 -0700 | [diff] [blame] | 31 | // If |stream_already_counted| is true, the static stream is already counted |
| 32 | // as an open stream earlier, so no need to count it again. |
| 33 | void RegisterStaticStream(QuicStreamId id, bool stream_already_counted); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 34 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 35 | // Sets the maximum outgoing stream count as a result of doing the transport |
| 36 | // configuration negotiation. Forces the limit to max_streams, regardless of |
| 37 | // static streams. |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 38 | void ConfigureMaxOpenOutgoingBidirectionalStreams(size_t max_streams); |
| 39 | void ConfigureMaxOpenOutgoingUnidirectionalStreams(size_t max_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 40 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 41 | // Sets the limits to max_open_streams + number of static streams |
| 42 | // in existence. SetMaxOpenOutgoingStreams will QUIC_BUG if it is called |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 43 | // after getting the first MAX_STREAMS frame or the transport configuration |
| 44 | // was done. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 45 | // TODO(fkastenholz): SetMax is cognizant of the number of static streams and |
| 46 | // sets the maximum to be max_streams + number_of_statics. This should |
| 47 | // eventually be removed from IETF QUIC. |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 48 | void SetMaxOpenOutgoingBidirectionalStreams(size_t max_open_streams); |
| 49 | void SetMaxOpenOutgoingUnidirectionalStreams(size_t max_open_streams); |
| 50 | void SetMaxOpenIncomingBidirectionalStreams(size_t max_open_streams); |
| 51 | void SetMaxOpenIncomingUnidirectionalStreams(size_t max_open_streams); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 52 | |
| 53 | // Sets the outgoing stream count to the number of static streams + max |
| 54 | // outgoing streams. Unlike SetMaxOpenOutgoingStreams, this method will |
| 55 | // not QUIC_BUG if called after getting the first MAX_STREAMS frame. |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 56 | void AdjustMaxOpenOutgoingBidirectionalStreams(size_t max_streams); |
| 57 | void AdjustMaxOpenOutgoingUnidirectionalStreams(size_t max_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 58 | |
| 59 | // Returns true if next outgoing bidirectional stream ID can be allocated. |
| 60 | bool CanOpenNextOutgoingBidirectionalStream(); |
| 61 | |
| 62 | // Returns true if next outgoing unidirectional stream ID can be allocated. |
| 63 | bool CanOpenNextOutgoingUnidirectionalStream(); |
| 64 | |
| 65 | // Returns the next outgoing bidirectional stream id. |
| 66 | QuicStreamId GetNextOutgoingBidirectionalStreamId(); |
| 67 | |
| 68 | // Returns the next outgoing unidirectional stream id. |
| 69 | QuicStreamId GetNextOutgoingUnidirectionalStreamId(); |
| 70 | |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 71 | // Returns true if the incoming |id| is within the limit. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | bool MaybeIncreaseLargestPeerStreamId(QuicStreamId id); |
| 73 | |
| 74 | // Called when |id| is released. |
| 75 | void OnStreamClosed(QuicStreamId id); |
| 76 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 77 | // Called when a MAX_STREAMS frame is received. |
| 78 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 79 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 80 | // Called when a STREAMS_BLOCKED frame is received. |
| 81 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 82 | |
| 83 | // Return true if |id| is peer initiated. |
| 84 | bool IsIncomingStream(QuicStreamId id) const; |
| 85 | |
| 86 | // Returns true if |id| is still available. |
| 87 | bool IsAvailableStream(QuicStreamId id) const; |
| 88 | |
| 89 | size_t GetMaxAllowdIncomingBidirectionalStreams() const; |
| 90 | |
| 91 | size_t GetMaxAllowdIncomingUnidirectionalStreams() const; |
| 92 | |
| 93 | void SetLargestPeerCreatedStreamId( |
| 94 | QuicStreamId largest_peer_created_stream_id); |
| 95 | |
| 96 | QuicStreamId next_outgoing_bidirectional_stream_id() const; |
| 97 | QuicStreamId next_outgoing_unidirectional_stream_id() const; |
| 98 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 99 | size_t max_allowed_outgoing_bidirectional_streams() const; |
| 100 | size_t max_allowed_outgoing_unidirectional_streams() const; |
| 101 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 102 | QuicStreamCount actual_max_allowed_incoming_bidirectional_streams() const; |
| 103 | QuicStreamCount actual_max_allowed_incoming_unidirectional_streams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 104 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 105 | QuicStreamCount advertised_max_allowed_incoming_bidirectional_streams() const; |
| 106 | QuicStreamCount advertised_max_allowed_incoming_unidirectional_streams() |
| 107 | const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | |
| 109 | private: |
| 110 | friend class test::QuicSessionPeer; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 111 | friend class test::UberQuicStreamIdManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 112 | |
| 113 | // Manages stream IDs of bidirectional streams. |
| 114 | QuicStreamIdManager bidirectional_stream_id_manager_; |
| 115 | |
| 116 | // Manages stream IDs of unidirectional streams. |
| 117 | QuicStreamIdManager unidirectional_stream_id_manager_; |
| 118 | }; |
| 119 | |
| 120 | } // namespace quic |
| 121 | |
| 122 | #endif // QUICHE_QUIC_CORE_UBER_QUIC_STREAM_ID_MANAGER_H_ |