blob: 45b0d33ff467b64833396bcfe49a41117ba6e19b [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:
fkastenholzd3a1de92019-05-15 07:00:07 -070023 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 teama6ef0a62019-03-07 20:34:33 -050029
30 // Called when a stream with |stream_id| is registered as a static stream.
renjietang3a1bb802019-06-11 10:42:41 -070031 // 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 teama6ef0a62019-03-07 20:34:33 -050034
fkastenholz3c4eabf2019-04-22 07:49:59 -070035 // 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.
fkastenholzd3a1de92019-05-15 07:00:07 -070038 void ConfigureMaxOpenOutgoingBidirectionalStreams(size_t max_streams);
39 void ConfigureMaxOpenOutgoingUnidirectionalStreams(size_t max_streams);
QUICHE teama6ef0a62019-03-07 20:34:33 -050040
fkastenholz3c4eabf2019-04-22 07:49:59 -070041 // Sets the limits to max_open_streams + number of static streams
42 // in existence. SetMaxOpenOutgoingStreams will QUIC_BUG if it is called
fkastenholzd3a1de92019-05-15 07:00:07 -070043 // after getting the first MAX_STREAMS frame or the transport configuration
44 // was done.
fkastenholz3c4eabf2019-04-22 07:49:59 -070045 // 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.
fkastenholzd3a1de92019-05-15 07:00:07 -070048 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);
fkastenholz3c4eabf2019-04-22 07:49:59 -070052
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.
fkastenholzd3a1de92019-05-15 07:00:07 -070056 void AdjustMaxOpenOutgoingBidirectionalStreams(size_t max_streams);
57 void AdjustMaxOpenOutgoingUnidirectionalStreams(size_t max_streams);
QUICHE teama6ef0a62019-03-07 20:34:33 -050058
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
fkastenholzd3a1de92019-05-15 07:00:07 -070071 // Returns true if the incoming |id| is within the limit.
QUICHE teama6ef0a62019-03-07 20:34:33 -050072 bool MaybeIncreaseLargestPeerStreamId(QuicStreamId id);
73
74 // Called when |id| is released.
75 void OnStreamClosed(QuicStreamId id);
76
fkastenholz3c4eabf2019-04-22 07:49:59 -070077 // Called when a MAX_STREAMS frame is received.
78 bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame);
QUICHE teama6ef0a62019-03-07 20:34:33 -050079
fkastenholz3c4eabf2019-04-22 07:49:59 -070080 // Called when a STREAMS_BLOCKED frame is received.
81 bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame);
QUICHE teama6ef0a62019-03-07 20:34:33 -050082
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 teama6ef0a62019-03-07 20:34:33 -050099 size_t max_allowed_outgoing_bidirectional_streams() const;
100 size_t max_allowed_outgoing_unidirectional_streams() const;
101
fkastenholz3c4eabf2019-04-22 07:49:59 -0700102 QuicStreamCount actual_max_allowed_incoming_bidirectional_streams() const;
103 QuicStreamCount actual_max_allowed_incoming_unidirectional_streams() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500104
fkastenholz3c4eabf2019-04-22 07:49:59 -0700105 QuicStreamCount advertised_max_allowed_incoming_bidirectional_streams() const;
106 QuicStreamCount advertised_max_allowed_incoming_unidirectional_streams()
107 const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500108
109 private:
110 friend class test::QuicSessionPeer;
fkastenholz3c4eabf2019-04-22 07:49:59 -0700111 friend class test::UberQuicStreamIdManagerPeer;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500112
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_