OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A QuicSession, which demuxes a single connection to individual streams. | 5 // A QuicSession, which demuxes a single connection to individual streams. |
6 | 6 |
7 #ifndef NET_QUIC_QUIC_SESSION_H_ | 7 #ifndef NET_QUIC_QUIC_SESSION_H_ |
8 #define NET_QUIC_QUIC_SESSION_H_ | 8 #define NET_QUIC_QUIC_SESSION_H_ |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <memory> | 13 #include <memory> |
14 #include <string> | 14 #include <string> |
15 #include <unordered_map> | 15 #include <unordered_map> |
16 #include <unordered_set> | 16 #include <unordered_set> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/containers/small_map.h" |
20 #include "base/macros.h" | 21 #include "base/macros.h" |
21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
22 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
23 #include "net/quic/quic_connection.h" | 24 #include "net/quic/quic_connection.h" |
24 #include "net/quic/quic_crypto_stream.h" | 25 #include "net/quic/quic_crypto_stream.h" |
25 #include "net/quic/quic_packet_creator.h" | 26 #include "net/quic/quic_packet_creator.h" |
26 #include "net/quic/quic_protocol.h" | 27 #include "net/quic/quic_protocol.h" |
27 #include "net/quic/quic_write_blocked_list.h" | 28 #include "net/quic/quic_write_blocked_list.h" |
28 #include "net/quic/reliable_quic_stream.h" | 29 #include "net/quic/reliable_quic_stream.h" |
29 | 30 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // returned. | 221 // returned. |
221 ReliableQuicStream* GetOrCreateStream(const QuicStreamId stream_id); | 222 ReliableQuicStream* GetOrCreateStream(const QuicStreamId stream_id); |
222 | 223 |
223 // Mark a stream as draining. | 224 // Mark a stream as draining. |
224 virtual void StreamDraining(QuicStreamId id); | 225 virtual void StreamDraining(QuicStreamId id); |
225 | 226 |
226 // Returns true if this stream should yield writes to another blocked stream. | 227 // Returns true if this stream should yield writes to another blocked stream. |
227 bool ShouldYield(QuicStreamId stream_id); | 228 bool ShouldYield(QuicStreamId stream_id); |
228 | 229 |
229 protected: | 230 protected: |
230 typedef std::unordered_map<QuicStreamId, ReliableQuicStream*> StreamMap; | 231 using StaticStreamMap = |
| 232 base::SmallMap<std::unordered_map<QuicStreamId, ReliableQuicStream*>, 2>; |
| 233 |
| 234 using DynamicStreamMap = |
| 235 base::SmallMap<std::unordered_map<QuicStreamId, ReliableQuicStream*>, 10>; |
231 | 236 |
232 // Creates a new stream to handle a peer-initiated stream. | 237 // Creates a new stream to handle a peer-initiated stream. |
233 // Caller does not own the returned stream. | 238 // Caller does not own the returned stream. |
234 // Returns nullptr and does error handling if the stream can not be created. | 239 // Returns nullptr and does error handling if the stream can not be created. |
235 virtual ReliableQuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; | 240 virtual ReliableQuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; |
236 | 241 |
237 // Create a new stream to handle a locally-initiated stream. | 242 // Create a new stream to handle a locally-initiated stream. |
238 // Caller does not own the returned stream. | 243 // Caller does not own the returned stream. |
239 // Returns nullptr if max streams have already been opened. | 244 // Returns nullptr if max streams have already been opened. |
240 virtual ReliableQuicStream* CreateOutgoingDynamicStream( | 245 virtual ReliableQuicStream* CreateOutgoingDynamicStream( |
(...skipping 25 matching lines...) Expand all Loading... |
266 // peer sent on that stream. | 271 // peer sent on that stream. |
267 // When this data arrives (via stream frame w. FIN, or RST) this method | 272 // When this data arrives (via stream frame w. FIN, or RST) this method |
268 // is called, and correctly updates the connection level flow controller. | 273 // is called, and correctly updates the connection level flow controller. |
269 void UpdateFlowControlOnFinalReceivedByteOffset( | 274 void UpdateFlowControlOnFinalReceivedByteOffset( |
270 QuicStreamId id, | 275 QuicStreamId id, |
271 QuicStreamOffset final_byte_offset); | 276 QuicStreamOffset final_byte_offset); |
272 | 277 |
273 // Return true if given stream is peer initiated. | 278 // Return true if given stream is peer initiated. |
274 bool IsIncomingStream(QuicStreamId id) const; | 279 bool IsIncomingStream(QuicStreamId id) const; |
275 | 280 |
276 StreamMap& static_streams() { return static_stream_map_; } | 281 StaticStreamMap& static_streams() { return static_stream_map_; } |
277 const StreamMap& static_streams() const { return static_stream_map_; } | 282 const StaticStreamMap& static_streams() const { return static_stream_map_; } |
278 | 283 |
279 StreamMap& dynamic_streams() { return dynamic_stream_map_; } | 284 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } |
280 const StreamMap& dynamic_streams() const { return dynamic_stream_map_; } | 285 const DynamicStreamMap& dynamic_streams() const { |
| 286 return dynamic_stream_map_; |
| 287 } |
281 | 288 |
282 std::vector<ReliableQuicStream*>* closed_streams() { | 289 std::vector<ReliableQuicStream*>* closed_streams() { |
283 return &closed_streams_; | 290 return &closed_streams_; |
284 } | 291 } |
285 | 292 |
286 void set_max_open_incoming_streams(size_t max_open_incoming_streams); | 293 void set_max_open_incoming_streams(size_t max_open_incoming_streams); |
287 void set_max_open_outgoing_streams(size_t max_open_outgoing_streams); | 294 void set_max_open_outgoing_streams(size_t max_open_outgoing_streams); |
288 | 295 |
289 void set_largest_peer_created_stream_id( | 296 void set_largest_peer_created_stream_id( |
290 QuicStreamId largest_peer_created_stream_id) { | 297 QuicStreamId largest_peer_created_stream_id) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 QuicConfig config_; | 367 QuicConfig config_; |
361 | 368 |
362 // The maximum number of outgoing streams this connection can open. | 369 // The maximum number of outgoing streams this connection can open. |
363 size_t max_open_outgoing_streams_; | 370 size_t max_open_outgoing_streams_; |
364 | 371 |
365 // The maximum number of incoming streams this connection will allow. | 372 // The maximum number of incoming streams this connection will allow. |
366 size_t max_open_incoming_streams_; | 373 size_t max_open_incoming_streams_; |
367 | 374 |
368 // Static streams, such as crypto and header streams. Owned by child classes | 375 // Static streams, such as crypto and header streams. Owned by child classes |
369 // that create these streams. | 376 // that create these streams. |
370 StreamMap static_stream_map_; | 377 StaticStreamMap static_stream_map_; |
371 | 378 |
372 // Map from StreamId to pointers to streams. Owns the streams. | 379 // Map from StreamId to pointers to streams. Owns the streams. |
373 StreamMap dynamic_stream_map_; | 380 DynamicStreamMap dynamic_stream_map_; |
374 | 381 |
375 // The ID to use for the next outgoing stream. | 382 // The ID to use for the next outgoing stream. |
376 QuicStreamId next_outgoing_stream_id_; | 383 QuicStreamId next_outgoing_stream_id_; |
377 | 384 |
378 // Set of stream ids that are less than the largest stream id that has been | 385 // Set of stream ids that are less than the largest stream id that has been |
379 // received, but are nonetheless available to be created. | 386 // received, but are nonetheless available to be created. |
380 std::unordered_set<QuicStreamId> available_streams_; | 387 std::unordered_set<QuicStreamId> available_streams_; |
381 | 388 |
382 // Set of stream ids that are "draining" -- a FIN has been sent and received, | 389 // Set of stream ids that are "draining" -- a FIN has been sent and received, |
383 // but the stream object still exists because not all the received data has | 390 // but the stream object still exists because not all the received data has |
(...skipping 24 matching lines...) Expand all Loading... |
408 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 415 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
409 // call stack of OnCanWrite. | 416 // call stack of OnCanWrite. |
410 QuicStreamId currently_writing_stream_id_; | 417 QuicStreamId currently_writing_stream_id_; |
411 | 418 |
412 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 419 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
413 }; | 420 }; |
414 | 421 |
415 } // namespace net | 422 } // namespace net |
416 | 423 |
417 #endif // NET_QUIC_QUIC_SESSION_H_ | 424 #endif // NET_QUIC_QUIC_SESSION_H_ |
OLD | NEW |