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: |
| 23 | UberQuicStreamIdManager(QuicSession* session, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 24 | QuicStreamCount max_open_outgoing_streams, |
| 25 | QuicStreamCount max_open_incoming_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 26 | |
| 27 | // Called when a stream with |stream_id| is registered as a static stream. |
| 28 | void RegisterStaticStream(QuicStreamId id); |
| 29 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 30 | // Sets the maximum outgoing stream count as a result of doing the transport |
| 31 | // configuration negotiation. Forces the limit to max_streams, regardless of |
| 32 | // static streams. |
| 33 | void ConfigureMaxOpenOutgoingStreams(size_t max_streams); |
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 limits to max_open_streams + number of static streams |
| 36 | // in existence. SetMaxOpenOutgoingStreams will QUIC_BUG if it is called |
| 37 | // after getting the first MAX_STREAMS frame. |
| 38 | // TODO(fkastenholz): SetMax is cognizant of the number of static streams and |
| 39 | // sets the maximum to be max_streams + number_of_statics. This should |
| 40 | // eventually be removed from IETF QUIC. |
| 41 | void SetMaxOpenOutgoingStreams(size_t max_open_streams); |
| 42 | void SetMaxOpenIncomingStreams(size_t max_open_streams); |
| 43 | |
| 44 | // Sets the outgoing stream count to the number of static streams + max |
| 45 | // outgoing streams. Unlike SetMaxOpenOutgoingStreams, this method will |
| 46 | // not QUIC_BUG if called after getting the first MAX_STREAMS frame. |
| 47 | void AdjustMaxOpenOutgoingStreams(size_t max_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | |
| 49 | // Returns true if next outgoing bidirectional stream ID can be allocated. |
| 50 | bool CanOpenNextOutgoingBidirectionalStream(); |
| 51 | |
| 52 | // Returns true if next outgoing unidirectional stream ID can be allocated. |
| 53 | bool CanOpenNextOutgoingUnidirectionalStream(); |
| 54 | |
| 55 | // Returns the next outgoing bidirectional stream id. |
| 56 | QuicStreamId GetNextOutgoingBidirectionalStreamId(); |
| 57 | |
| 58 | // Returns the next outgoing unidirectional stream id. |
| 59 | QuicStreamId GetNextOutgoingUnidirectionalStreamId(); |
| 60 | |
| 61 | // Returns true if allow to open the incoming |id|. |
| 62 | bool MaybeIncreaseLargestPeerStreamId(QuicStreamId id); |
| 63 | |
| 64 | // Called when |id| is released. |
| 65 | void OnStreamClosed(QuicStreamId id); |
| 66 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 67 | // Called when a MAX_STREAMS frame is received. |
| 68 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 69 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 70 | // Called when a STREAMS_BLOCKED frame is received. |
| 71 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | |
| 73 | // Return true if |id| is peer initiated. |
| 74 | bool IsIncomingStream(QuicStreamId id) const; |
| 75 | |
| 76 | // Returns true if |id| is still available. |
| 77 | bool IsAvailableStream(QuicStreamId id) const; |
| 78 | |
| 79 | size_t GetMaxAllowdIncomingBidirectionalStreams() const; |
| 80 | |
| 81 | size_t GetMaxAllowdIncomingUnidirectionalStreams() const; |
| 82 | |
| 83 | void SetLargestPeerCreatedStreamId( |
| 84 | QuicStreamId largest_peer_created_stream_id); |
| 85 | |
| 86 | QuicStreamId next_outgoing_bidirectional_stream_id() const; |
| 87 | QuicStreamId next_outgoing_unidirectional_stream_id() const; |
| 88 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 89 | size_t max_allowed_outgoing_bidirectional_streams() const; |
| 90 | size_t max_allowed_outgoing_unidirectional_streams() const; |
| 91 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 92 | QuicStreamCount actual_max_allowed_incoming_bidirectional_streams() const; |
| 93 | QuicStreamCount actual_max_allowed_incoming_unidirectional_streams() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 94 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 95 | QuicStreamCount advertised_max_allowed_incoming_bidirectional_streams() const; |
| 96 | QuicStreamCount advertised_max_allowed_incoming_unidirectional_streams() |
| 97 | const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 98 | |
| 99 | private: |
| 100 | friend class test::QuicSessionPeer; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame^] | 101 | friend class test::UberQuicStreamIdManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | |
| 103 | // Manages stream IDs of bidirectional streams. |
| 104 | QuicStreamIdManager bidirectional_stream_id_manager_; |
| 105 | |
| 106 | // Manages stream IDs of unidirectional streams. |
| 107 | QuicStreamIdManager unidirectional_stream_id_manager_; |
| 108 | }; |
| 109 | |
| 110 | } // namespace quic |
| 111 | |
| 112 | #endif // QUICHE_QUIC_CORE_UBER_QUIC_STREAM_ID_MANAGER_H_ |