blob: 01315872fb804354971468fc8c72b17df51b8ea2 [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#ifndef QUICHE_QUIC_CORE_LEGACY_QUIC_STREAM_ID_MANAGER_H_
5#define QUICHE_QUIC_CORE_LEGACY_QUIC_STREAM_ID_MANAGER_H_
6
7#include "net/third_party/quiche/src/quic/core/quic_stream_id_manager.h"
ianswettc1f530d2019-12-10 05:14:30 -08008#include "net/third_party/quiche/src/quic/core/quic_types.h"
9#include "net/third_party/quiche/src/quic/core/quic_versions.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
11namespace quic {
12
13namespace test {
14class QuicSessionPeer;
15} // namespace test
16
17class QuicSession;
18
19// Manages Google QUIC stream IDs. This manager is responsible for two
20// questions: 1) can next outgoing stream ID be allocated (if yes, what is the
21// next outgoing stream ID) and 2) can a new incoming stream be opened.
22class QUIC_EXPORT_PRIVATE LegacyQuicStreamIdManager {
23 public:
ianswettc1f530d2019-12-10 05:14:30 -080024 LegacyQuicStreamIdManager(Perspective perspective,
25 QuicTransportVersion transport_version,
QUICHE teama6ef0a62019-03-07 20:34:33 -050026 size_t max_open_outgoing_streams,
27 size_t max_open_incoming_streams);
28
29 ~LegacyQuicStreamIdManager();
30
31 // Returns true if the next outgoing stream ID can be allocated.
fayangbd94f4c2020-06-01 14:36:37 -070032 bool CanOpenNextOutgoingStream() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050033
34 // Returns true if a new incoming stream can be opened.
fayangbd94f4c2020-06-01 14:36:37 -070035 bool CanOpenIncomingStream() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050036
ianswettc1f530d2019-12-10 05:14:30 -080037 // Returns false when increasing the largest created stream id to |id| would
38 // violate the limit, so the connection should be closed.
QUICHE teama6ef0a62019-03-07 20:34:33 -050039 bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId id);
40
41 // Returns true if |id| is still available.
42 bool IsAvailableStream(QuicStreamId id) const;
43
44 // Returns the stream ID for a new outgoing stream, and increments the
45 // underlying counter.
46 QuicStreamId GetNextOutgoingStreamId();
47
fayang01591ae2020-04-23 14:14:56 -070048 // Called when a new stream is open.
49 void ActivateStream(bool is_incoming);
50
51 // Called when a stream ID is closed.
52 void OnStreamClosed(bool is_incoming);
53
QUICHE teama6ef0a62019-03-07 20:34:33 -050054 // Return true if |id| is peer initiated.
55 bool IsIncomingStream(QuicStreamId id) const;
56
57 size_t MaxAvailableStreams() const;
58
59 void set_max_open_incoming_streams(size_t max_open_incoming_streams) {
60 max_open_incoming_streams_ = max_open_incoming_streams;
61 }
62
63 void set_max_open_outgoing_streams(size_t max_open_outgoing_streams) {
64 max_open_outgoing_streams_ = max_open_outgoing_streams;
65 }
66
67 void set_largest_peer_created_stream_id(
68 QuicStreamId largest_peer_created_stream_id) {
69 largest_peer_created_stream_id_ = largest_peer_created_stream_id;
70 }
71
72 size_t max_open_incoming_streams() const {
73 return max_open_incoming_streams_;
74 }
75
76 size_t max_open_outgoing_streams() const {
77 return max_open_outgoing_streams_;
78 }
79
80 QuicStreamId next_outgoing_stream_id() const {
81 return next_outgoing_stream_id_;
82 }
83
84 QuicStreamId largest_peer_created_stream_id() const {
85 return largest_peer_created_stream_id_;
86 }
87
ianswettc1f530d2019-12-10 05:14:30 -080088 size_t GetNumAvailableStreams() const;
89
fayang01591ae2020-04-23 14:14:56 -070090 size_t num_open_incoming_streams() const {
91 return num_open_incoming_streams_;
92 }
93 size_t num_open_outgoing_streams() const {
94 return num_open_outgoing_streams_;
95 }
96
QUICHE teama6ef0a62019-03-07 20:34:33 -050097 private:
98 friend class test::QuicSessionPeer;
99
ianswettc1f530d2019-12-10 05:14:30 -0800100 const Perspective perspective_;
101 const QuicTransportVersion transport_version_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500102
103 // The maximum number of outgoing streams this connection can open.
104 size_t max_open_outgoing_streams_;
105
106 // The maximum number of incoming streams this connection will allow.
107 size_t max_open_incoming_streams_;
108
109 // The ID to use for the next outgoing stream.
110 QuicStreamId next_outgoing_stream_id_;
111
112 // Set of stream ids that are less than the largest stream id that has been
113 // received, but are nonetheless available to be created.
wubb4810d52020-04-23 06:55:15 -0700114 QuicHashSet<QuicStreamId> available_streams_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500115
116 QuicStreamId largest_peer_created_stream_id_;
fayang01591ae2020-04-23 14:14:56 -0700117
fayangbd94f4c2020-06-01 14:36:37 -0700118 // A counter for peer initiated open streams.
fayang01591ae2020-04-23 14:14:56 -0700119 size_t num_open_incoming_streams_;
120
fayangbd94f4c2020-06-01 14:36:37 -0700121 // A counter for self initiated open streams.
fayang01591ae2020-04-23 14:14:56 -0700122 size_t num_open_outgoing_streams_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500123};
124
125} // namespace quic
126
127#endif // QUICHE_QUIC_CORE_LEGACY_QUIC_STREAM_ID_MANAGER_H_