blob: 41fa12be99bd90ce2aa91e0660ac7c09c30024fe [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
10namespace quic {
11
12namespace test {
13class QuicSessionPeer;
fkastenholz3c4eabf2019-04-22 07:49:59 -070014class UberQuicStreamIdManagerPeer;
QUICHE teama6ef0a62019-03-07 20:34:33 -050015} // namespace test
16
17class QuicSession;
18
19// This class comprises two QuicStreamIdManagers, which manage bidirectional and
20// unidirectional stream IDs, respectively.
21class QUIC_EXPORT_PRIVATE UberQuicStreamIdManager {
22 public:
23 UberQuicStreamIdManager(QuicSession* session,
fkastenholz3c4eabf2019-04-22 07:49:59 -070024 QuicStreamCount max_open_outgoing_streams,
25 QuicStreamCount max_open_incoming_streams);
QUICHE teama6ef0a62019-03-07 20:34:33 -050026
27 // Called when a stream with |stream_id| is registered as a static stream.
28 void RegisterStaticStream(QuicStreamId id);
29
fkastenholz3c4eabf2019-04-22 07:49:59 -070030 // 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 teama6ef0a62019-03-07 20:34:33 -050034
fkastenholz3c4eabf2019-04-22 07:49:59 -070035 // 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 teama6ef0a62019-03-07 20:34:33 -050048
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
fkastenholz3c4eabf2019-04-22 07:49:59 -070067 // Called when a MAX_STREAMS frame is received.
68 bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame);
QUICHE teama6ef0a62019-03-07 20:34:33 -050069
fkastenholz3c4eabf2019-04-22 07:49:59 -070070 // Called when a STREAMS_BLOCKED frame is received.
71 bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame);
QUICHE teama6ef0a62019-03-07 20:34:33 -050072
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 teama6ef0a62019-03-07 20:34:33 -050089 size_t max_allowed_outgoing_bidirectional_streams() const;
90 size_t max_allowed_outgoing_unidirectional_streams() const;
91
fkastenholz3c4eabf2019-04-22 07:49:59 -070092 QuicStreamCount actual_max_allowed_incoming_bidirectional_streams() const;
93 QuicStreamCount actual_max_allowed_incoming_unidirectional_streams() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050094
fkastenholz3c4eabf2019-04-22 07:49:59 -070095 QuicStreamCount advertised_max_allowed_incoming_bidirectional_streams() const;
96 QuicStreamCount advertised_max_allowed_incoming_unidirectional_streams()
97 const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050098
99 private:
100 friend class test::QuicSessionPeer;
fkastenholz3c4eabf2019-04-22 07:49:59 -0700101 friend class test::UberQuicStreamIdManagerPeer;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500102
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_