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_CORE_QUIC_SESSION_H_ | 7 #ifndef NET_QUIC_CORE_QUIC_SESSION_H_ |
8 #define NET_QUIC_CORE_QUIC_SESSION_H_ | 8 #define NET_QUIC_CORE_QUIC_SESSION_H_ |
9 | 9 |
10 #include <cstddef> | 10 #include <cstddef> |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // then a new stream is created and returned. In all other cases, nullptr is | 243 // then a new stream is created and returned. In all other cases, nullptr is |
244 // returned. | 244 // returned. |
245 QuicStream* GetOrCreateStream(const QuicStreamId stream_id); | 245 QuicStream* GetOrCreateStream(const QuicStreamId stream_id); |
246 | 246 |
247 // Mark a stream as draining. | 247 // Mark a stream as draining. |
248 virtual void StreamDraining(QuicStreamId id); | 248 virtual void StreamDraining(QuicStreamId id); |
249 | 249 |
250 // Returns true if this stream should yield writes to another blocked stream. | 250 // Returns true if this stream should yield writes to another blocked stream. |
251 bool ShouldYield(QuicStreamId stream_id); | 251 bool ShouldYield(QuicStreamId stream_id); |
252 | 252 |
253 void set_respect_goaway(bool respect_goaway) { | |
254 respect_goaway_ = respect_goaway; | |
255 } | |
256 | |
257 protected: | 253 protected: |
258 using StaticStreamMap = QuicSmallMap<QuicStreamId, QuicStream*, 2>; | 254 using StaticStreamMap = QuicSmallMap<QuicStreamId, QuicStream*, 2>; |
259 | 255 |
260 using DynamicStreamMap = | 256 using DynamicStreamMap = |
261 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; | 257 QuicSmallMap<QuicStreamId, std::unique_ptr<QuicStream>, 10>; |
262 | 258 |
263 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; | 259 using ClosedStreams = std::vector<std::unique_ptr<QuicStream>>; |
264 | 260 |
265 // TODO(ckrasic) - For all *DynamicStream2 below, rename after | |
266 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. | |
267 | |
268 // Returns true if an incoming stream can be created. | |
269 virtual bool ShouldCreateIncomingDynamicStream2(QuicStreamId id); | |
270 | |
271 // Returns true if an outgoing stream can be created. | |
272 virtual bool ShouldCreateOutgoingDynamicStream2(); | |
273 | |
274 // Creates a new stream to handle a peer-initiated stream. | 261 // Creates a new stream to handle a peer-initiated stream. |
275 // Caller does not own the returned stream. | 262 // Caller does not own the returned stream. |
276 // Returns nullptr and does error handling if the stream can not be created. | |
277 virtual QuicStream* MaybeCreateIncomingDynamicStream(QuicStreamId id); | |
278 | |
279 // Create a new stream to handle a locally-initiated stream. | |
280 // Caller does not own the returned stream. | |
281 // Returns nullptr if max streams have already been opened. | |
282 virtual QuicStream* MaybeCreateOutgoingDynamicStream(SpdyPriority priority); | |
283 | |
284 // TODO(ckrasic) - For all Create*DynamicStream below, remove when | |
285 // quic_reloadable_flag_quic_refactor_stream_creation is deprecated. | |
286 | |
287 // Creates a new stream to handle a peer-initiated stream. | |
288 // Caller does not own the returned stream. | |
289 // Returns nullptr and does error handling if the stream can not be created. | 263 // Returns nullptr and does error handling if the stream can not be created. |
290 virtual QuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; | 264 virtual QuicStream* CreateIncomingDynamicStream(QuicStreamId id) = 0; |
291 | 265 |
292 // Create a new stream to handle a locally-initiated stream. | 266 // Create a new stream to handle a locally-initiated stream. |
293 // Caller does not own the returned stream. | 267 // Caller does not own the returned stream. |
294 // Returns nullptr if max streams have already been opened. | 268 // Returns nullptr if max streams have already been opened. |
295 virtual QuicStream* CreateOutgoingDynamicStream(SpdyPriority priority) = 0; | 269 virtual QuicStream* CreateOutgoingDynamicStream(SpdyPriority priority) = 0; |
296 | 270 |
297 // Return the reserved crypto stream. | 271 // Return the reserved crypto stream. |
298 virtual QuicCryptoStream* GetMutableCryptoStream() = 0; | 272 virtual QuicCryptoStream* GetMutableCryptoStream() = 0; |
(...skipping 23 matching lines...) Expand all Loading... |
322 // peer sent on that stream. | 296 // peer sent on that stream. |
323 // When this data arrives (via stream frame w. FIN, trailing headers, or RST) | 297 // When this data arrives (via stream frame w. FIN, trailing headers, or RST) |
324 // this method is called, and correctly updates the connection level flow | 298 // this method is called, and correctly updates the connection level flow |
325 // controller. | 299 // controller. |
326 virtual void OnFinalByteOffsetReceived(QuicStreamId id, | 300 virtual void OnFinalByteOffsetReceived(QuicStreamId id, |
327 QuicStreamOffset final_byte_offset); | 301 QuicStreamOffset final_byte_offset); |
328 | 302 |
329 // Return true if given stream is peer initiated. | 303 // Return true if given stream is peer initiated. |
330 bool IsIncomingStream(QuicStreamId id) const; | 304 bool IsIncomingStream(QuicStreamId id) const; |
331 | 305 |
332 // Unconditionally creates a stream. Subclasses should use this to | |
333 // provide streams appropriately subclassed from |QuicStream|, | |
334 // e.g. |QuicSpdySession::CreateStream()| creates a |QuicSpdyStream|. | |
335 virtual std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) = 0; | |
336 | |
337 // Creates a stream and activates it, owned by the session. | |
338 QuicStream* CreateAndActivateStream(QuicStreamId id); | |
339 | |
340 StaticStreamMap& static_streams() { return static_stream_map_; } | 306 StaticStreamMap& static_streams() { return static_stream_map_; } |
341 const StaticStreamMap& static_streams() const { return static_stream_map_; } | 307 const StaticStreamMap& static_streams() const { return static_stream_map_; } |
342 | 308 |
343 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } | 309 DynamicStreamMap& dynamic_streams() { return dynamic_stream_map_; } |
344 const DynamicStreamMap& dynamic_streams() const { | 310 const DynamicStreamMap& dynamic_streams() const { |
345 return dynamic_stream_map_; | 311 return dynamic_stream_map_; |
346 } | 312 } |
347 | 313 |
348 ClosedStreams* closed_streams() { return &closed_streams_; } | 314 ClosedStreams* closed_streams() { return &closed_streams_; } |
349 | 315 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId stream_id); | 352 bool MaybeIncreaseLargestPeerStreamId(const QuicStreamId stream_id); |
387 | 353 |
388 void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, | 354 void InsertLocallyClosedStreamsHighestOffset(const QuicStreamId id, |
389 QuicStreamOffset offset); | 355 QuicStreamOffset offset); |
390 // If stream is a locally closed stream, this RST will update FIN offset. | 356 // If stream is a locally closed stream, this RST will update FIN offset. |
391 // Otherwise stream is a preserved stream and the behavior of it depends on | 357 // Otherwise stream is a preserved stream and the behavior of it depends on |
392 // derived class's own implementation. | 358 // derived class's own implementation. |
393 virtual void HandleRstOnValidNonexistentStream( | 359 virtual void HandleRstOnValidNonexistentStream( |
394 const QuicRstStreamFrame& frame); | 360 const QuicRstStreamFrame& frame); |
395 | 361 |
396 bool respect_goaway() const { return respect_goaway_; } | |
397 | |
398 private: | 362 private: |
399 friend class test::QuicSessionPeer; | 363 friend class test::QuicSessionPeer; |
400 | 364 |
401 // Called in OnConfigNegotiated when we receive a new stream level flow | 365 // Called in OnConfigNegotiated when we receive a new stream level flow |
402 // control window in a negotiated config. Closes the connection if invalid. | 366 // control window in a negotiated config. Closes the connection if invalid. |
403 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); | 367 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); |
404 | 368 |
405 // Called in OnConfigNegotiated when we receive a new connection level flow | 369 // Called in OnConfigNegotiated when we receive a new connection level flow |
406 // control window in a negotiated config. Closes the connection if invalid. | 370 // control window in a negotiated config. Closes the connection if invalid. |
407 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); | 371 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // The latched error with which the connection was closed. | 437 // The latched error with which the connection was closed. |
474 QuicErrorCode error_; | 438 QuicErrorCode error_; |
475 | 439 |
476 // Used for connection-level flow control. | 440 // Used for connection-level flow control. |
477 QuicFlowController flow_controller_; | 441 QuicFlowController flow_controller_; |
478 | 442 |
479 // The stream id which was last popped in OnCanWrite, or 0, if not under the | 443 // The stream id which was last popped in OnCanWrite, or 0, if not under the |
480 // call stack of OnCanWrite. | 444 // call stack of OnCanWrite. |
481 QuicStreamId currently_writing_stream_id_; | 445 QuicStreamId currently_writing_stream_id_; |
482 | 446 |
483 // If this is set to false, the session will ignore peer GOAWAYs and | |
484 // allow the creation of outgoing streams regardless of the high | |
485 // chance they will fail. | |
486 bool respect_goaway_; | |
487 | |
488 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 447 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
489 }; | 448 }; |
490 | 449 |
491 } // namespace net | 450 } // namespace net |
492 | 451 |
493 #endif // NET_QUIC_CORE_QUIC_SESSION_H_ | 452 #endif // NET_QUIC_CORE_QUIC_SESSION_H_ |
OLD | NEW |