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> |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 size_t get_max_open_streams() const { return max_open_streams_; } | 199 size_t get_max_open_streams() const { return max_open_streams_; } |
200 | 200 |
201 size_t get_max_available_streams() const { | 201 size_t get_max_available_streams() const { |
202 return max_open_streams_ * kMaxAvailableStreamsMultiplier; | 202 return max_open_streams_ * kMaxAvailableStreamsMultiplier; |
203 } | 203 } |
204 | 204 |
205 ReliableQuicStream* GetStream(const QuicStreamId stream_id); | 205 ReliableQuicStream* GetStream(const QuicStreamId stream_id); |
206 | 206 |
207 // Mark a stream as draining. | 207 // Mark a stream as draining. |
208 void StreamDraining(QuicStreamId id); | 208 virtual void StreamDraining(QuicStreamId id); |
209 | 209 |
210 // Close the connection, if it is not already closed. | 210 // Close the connection, if it is not already closed. |
211 void CloseConnectionWithDetails(QuicErrorCode error, const char* details); | 211 void CloseConnectionWithDetails(QuicErrorCode error, const char* details); |
212 | 212 |
213 protected: | 213 protected: |
214 typedef base::hash_map<QuicStreamId, ReliableQuicStream*> StreamMap; | 214 typedef base::hash_map<QuicStreamId, ReliableQuicStream*> StreamMap; |
215 | 215 |
216 // Creates a new stream, owned by the caller, to handle a peer-initiated | 216 // Creates a new stream, owned by the caller, to handle a peer-initiated |
217 // stream. Returns nullptr and does error handling if the stream can not be | 217 // stream. Returns nullptr and does error handling if the stream can not be |
218 // created. | 218 // created. |
(...skipping 20 matching lines...) Expand all Loading... |
239 // returned. However if |stream_id| is a locally-created id and no such stream | 239 // returned. However if |stream_id| is a locally-created id and no such stream |
240 // exists, the connection is closed. | 240 // exists, the connection is closed. |
241 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id); | 241 ReliableQuicStream* GetOrCreateDynamicStream(QuicStreamId stream_id); |
242 | 242 |
243 // This is called after every call other than OnConnectionClose from the | 243 // This is called after every call other than OnConnectionClose from the |
244 // QuicConnectionVisitor to allow post-processing once the work has been done. | 244 // QuicConnectionVisitor to allow post-processing once the work has been done. |
245 // In this case, it deletes streams given that it's safe to do so (no other | 245 // In this case, it deletes streams given that it's safe to do so (no other |
246 // operations are being done on the streams at this time) | 246 // operations are being done on the streams at this time) |
247 virtual void PostProcessAfterData(); | 247 virtual void PostProcessAfterData(); |
248 | 248 |
| 249 // Performs the work required to close |stream_id|. If |locally_reset| |
| 250 // then the stream has been reset by this endpoint, not by the peer. |
| 251 virtual void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); |
| 252 |
| 253 // When a stream is closed locally, it may not yet know how many bytes the |
| 254 // peer sent on that stream. |
| 255 // When this data arrives (via stream frame w. FIN, or RST) this method |
| 256 // is called, and correctly updates the connection level flow controller. |
| 257 void UpdateFlowControlOnFinalReceivedByteOffset( |
| 258 QuicStreamId id, |
| 259 QuicStreamOffset final_byte_offset); |
| 260 |
| 261 // Return true if given stream is peer initiated. |
| 262 bool IsIncomingStream(QuicStreamId id) const; |
| 263 |
249 StreamMap& static_streams() { return static_stream_map_; } | 264 StreamMap& static_streams() { return static_stream_map_; } |
250 const StreamMap& static_streams() const { return static_stream_map_; } | 265 const StreamMap& static_streams() const { return static_stream_map_; } |
251 | 266 |
252 StreamMap& dynamic_streams() { return dynamic_stream_map_; } | 267 StreamMap& dynamic_streams() { return dynamic_stream_map_; } |
253 const StreamMap& dynamic_streams() const { return dynamic_stream_map_; } | 268 const StreamMap& dynamic_streams() const { return dynamic_stream_map_; } |
254 | 269 |
255 std::vector<ReliableQuicStream*>* closed_streams() { | 270 std::vector<ReliableQuicStream*>* closed_streams() { |
256 return &closed_streams_; | 271 return &closed_streams_; |
257 } | 272 } |
258 | 273 |
(...skipping 11 matching lines...) Expand all Loading... |
270 size_t GetNumDynamicOutgoingStreams() const; | 285 size_t GetNumDynamicOutgoingStreams() const; |
271 | 286 |
272 size_t GetNumDrainingOutgoingStreams() const; | 287 size_t GetNumDrainingOutgoingStreams() const; |
273 | 288 |
274 size_t num_locally_closed_incoming_streams_highest_offset() const { | 289 size_t num_locally_closed_incoming_streams_highest_offset() const { |
275 return num_locally_closed_incoming_streams_highest_offset_; | 290 return num_locally_closed_incoming_streams_highest_offset_; |
276 } | 291 } |
277 | 292 |
278 size_t GetNumLocallyClosedOutgoingStreamsHighestOffset() const; | 293 size_t GetNumLocallyClosedOutgoingStreamsHighestOffset() const; |
279 | 294 |
| 295 QuicStreamId next_outgoing_stream_id() const { |
| 296 return next_outgoing_stream_id_; |
| 297 } |
| 298 |
| 299 // Close connection when receive a frame for a locally-created nonexistant |
| 300 // stream. |
| 301 // Prerequisite: IsClosedStream(stream_id) == false |
| 302 // Server session might need to override this method to allow server push |
| 303 // stream to be promised before creating an active stream. |
| 304 virtual void HandleFrameOnNonexistentOutgoingStream(QuicStreamId stream_id); |
| 305 |
| 306 // If stream is a locally closed stream, this RST will update FIN offset. |
| 307 // Otherwise stream is a preserved stream and the behavior of it depends on |
| 308 // derived class's own implementation. |
| 309 virtual void HandleRstOnValidNonexistentStream( |
| 310 const QuicRstStreamFrame& frame); |
| 311 |
280 private: | 312 private: |
281 friend class test::QuicSessionPeer; | 313 friend class test::QuicSessionPeer; |
282 friend class VisitorShim; | 314 friend class VisitorShim; |
283 | 315 |
284 // Performs the work required to close |stream_id|. If |locally_reset| | |
285 // then the stream has been reset by this endpoint, not by the peer. | |
286 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); | |
287 | |
288 // When a stream is closed locally, it may not yet know how many bytes the | |
289 // peer sent on that stream. | |
290 // When this data arrives (via stream frame w. FIN, or RST) this method | |
291 // is called, and correctly updates the connection level flow controller. | |
292 void UpdateFlowControlOnFinalReceivedByteOffset( | |
293 QuicStreamId id, | |
294 QuicStreamOffset final_byte_offset); | |
295 | |
296 // Called in OnConfigNegotiated when we receive a new stream level flow | 316 // Called in OnConfigNegotiated when we receive a new stream level flow |
297 // control window in a negotiated config. Closes the connection if invalid. | 317 // control window in a negotiated config. Closes the connection if invalid. |
298 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); | 318 void OnNewStreamFlowControlWindow(QuicStreamOffset new_window); |
299 | 319 |
300 // Called in OnConfigNegotiated when we receive a new connection level flow | 320 // Called in OnConfigNegotiated when we receive a new connection level flow |
301 // control window in a negotiated config. Closes the connection if invalid. | 321 // control window in a negotiated config. Closes the connection if invalid. |
302 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); | 322 void OnNewSessionFlowControlWindow(QuicStreamOffset new_window); |
303 | 323 |
304 // Called in OnConfigNegotiated when auto-tuning is enabled for flow | 324 // Called in OnConfigNegotiated when auto-tuning is enabled for flow |
305 // control receive windows. | 325 // control receive windows. |
306 void EnableAutoTuneReceiveWindow(); | 326 void EnableAutoTuneReceiveWindow(); |
307 | 327 |
308 // Called in OnConfigNegotiated for finch trials to measure performance of | 328 // Called in OnConfigNegotiated for finch trials to measure performance of |
309 // starting with smaller flow control receive windows and auto-tuning. | 329 // starting with smaller flow control receive windows and auto-tuning. |
310 void AdjustInitialFlowControlWindows(size_t stream_window); | 330 void AdjustInitialFlowControlWindows(size_t stream_window); |
311 | 331 |
312 // Return true if given stream is peer initiated. | |
313 bool IsIncomingStream(QuicStreamId id) const; | |
314 | |
315 // Keep track of highest received byte offset of locally closed streams, while | 332 // Keep track of highest received byte offset of locally closed streams, while |
316 // waiting for a definitive final highest offset from the peer. | 333 // waiting for a definitive final highest offset from the peer. |
317 std::map<QuicStreamId, QuicStreamOffset> | 334 std::map<QuicStreamId, QuicStreamOffset> |
318 locally_closed_streams_highest_offset_; | 335 locally_closed_streams_highest_offset_; |
319 | 336 |
320 scoped_ptr<QuicConnection> connection_; | 337 scoped_ptr<QuicConnection> connection_; |
321 | 338 |
322 // A shim to stand between the connection and the session, to handle stream | 339 // A shim to stand between the connection and the session, to handle stream |
323 // deletions. | 340 // deletions. |
324 scoped_ptr<VisitorShim> visitor_shim_; | 341 scoped_ptr<VisitorShim> visitor_shim_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 386 |
370 // Used for connection-level flow control. | 387 // Used for connection-level flow control. |
371 QuicFlowController flow_controller_; | 388 QuicFlowController flow_controller_; |
372 | 389 |
373 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 390 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
374 }; | 391 }; |
375 | 392 |
376 } // namespace net | 393 } // namespace net |
377 | 394 |
378 #endif // NET_QUIC_QUIC_SESSION_H_ | 395 #endif // NET_QUIC_QUIC_SESSION_H_ |
OLD | NEW |