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 <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
15 #include "net/base/linked_hash_map.h" | 15 #include "net/base/linked_hash_map.h" |
16 #include "net/quic/quic_connection.h" | 16 #include "net/quic/quic_connection.h" |
17 #include "net/quic/quic_crypto_stream.h" | 17 #include "net/quic/quic_crypto_stream.h" |
18 #include "net/quic/quic_data_stream.h" | 18 #include "net/quic/quic_data_stream.h" |
19 #include "net/quic/quic_headers_stream.h" | 19 #include "net/quic/quic_headers_stream.h" |
20 #include "net/quic/quic_packet_creator.h" | 20 #include "net/quic/quic_packet_creator.h" |
21 #include "net/quic/quic_protocol.h" | 21 #include "net/quic/quic_protocol.h" |
22 #include "net/quic/quic_spdy_compressor.h" | |
23 #include "net/quic/quic_spdy_decompressor.h" | |
24 #include "net/quic/quic_write_blocked_list.h" | 22 #include "net/quic/quic_write_blocked_list.h" |
25 #include "net/quic/reliable_quic_stream.h" | 23 #include "net/quic/reliable_quic_stream.h" |
26 | 24 |
27 namespace net { | 25 namespace net { |
28 | 26 |
29 class QuicCryptoStream; | 27 class QuicCryptoStream; |
30 class ReliableQuicStream; | 28 class ReliableQuicStream; |
31 class SSLInfo; | 29 class SSLInfo; |
32 class VisitorShim; | 30 class VisitorShim; |
33 | 31 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // Returns the number of currently open streams, including those which have | 174 // Returns the number of currently open streams, including those which have |
177 // been implicitly created. | 175 // been implicitly created. |
178 virtual size_t GetNumOpenStreams() const; | 176 virtual size_t GetNumOpenStreams() const; |
179 | 177 |
180 void MarkWriteBlocked(QuicStreamId id, QuicPriority priority); | 178 void MarkWriteBlocked(QuicStreamId id, QuicPriority priority); |
181 | 179 |
182 // Returns true if the session has data to be sent, either queued in the | 180 // Returns true if the session has data to be sent, either queued in the |
183 // connection, or in a write-blocked stream. | 181 // connection, or in a write-blocked stream. |
184 bool HasDataToWrite() const; | 182 bool HasDataToWrite() const; |
185 | 183 |
186 // Marks that |stream_id| is blocked waiting to decompress the | |
187 // headers identified by |decompression_id|. | |
188 void MarkDecompressionBlocked(QuicHeaderId decompression_id, | |
189 QuicStreamId stream_id); | |
190 | |
191 bool goaway_received() const { | 184 bool goaway_received() const { |
192 return goaway_received_; | 185 return goaway_received_; |
193 } | 186 } |
194 | 187 |
195 bool goaway_sent() const { | 188 bool goaway_sent() const { |
196 return goaway_sent_; | 189 return goaway_sent_; |
197 } | 190 } |
198 | 191 |
199 QuicSpdyDecompressor* decompressor() { return &decompressor_; } | |
200 QuicSpdyCompressor* compressor() { return &compressor_; } | |
201 | |
202 // Gets the SSL connection information. | 192 // Gets the SSL connection information. |
203 virtual bool GetSSLInfo(SSLInfo* ssl_info); | 193 virtual bool GetSSLInfo(SSLInfo* ssl_info); |
204 | 194 |
205 QuicErrorCode error() const { return error_; } | 195 QuicErrorCode error() const { return error_; } |
206 | 196 |
207 bool is_server() const { return connection_->is_server(); } | 197 bool is_server() const { return connection_->is_server(); } |
208 | 198 |
209 protected: | 199 protected: |
210 typedef base::hash_map<QuicStreamId, QuicDataStream*> DataStreamMap; | 200 typedef base::hash_map<QuicStreamId, QuicDataStream*> DataStreamMap; |
211 | 201 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 241 |
252 size_t get_max_open_streams() const { | 242 size_t get_max_open_streams() const { |
253 return max_open_streams_; | 243 return max_open_streams_; |
254 } | 244 } |
255 | 245 |
256 private: | 246 private: |
257 friend class test::QuicSessionPeer; | 247 friend class test::QuicSessionPeer; |
258 friend class VisitorShim; | 248 friend class VisitorShim; |
259 | 249 |
260 // Performs the work required to close |stream_id|. If |locally_reset| | 250 // Performs the work required to close |stream_id|. If |locally_reset| |
261 // then the stream has been reset by this endpoint, not by the peer. This | 251 // then the stream has been reset by this endpoint, not by the peer. |
262 // means the stream may become a zombie stream which needs to stay | |
263 // around until headers have been decompressed. | |
264 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); | 252 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset); |
265 | 253 |
266 // Adds |stream_id| to the zobmie stream map, closing the oldest | |
267 // zombie stream if the set is full. | |
268 void AddZombieStream(QuicStreamId stream_id); | |
269 | |
270 // Closes the zombie stream |stream_id| and removes it from the zombie | |
271 // stream map. | |
272 void CloseZombieStream(QuicStreamId stream_id); | |
273 | |
274 // Adds |stream_id| to the prematurely closed stream map, removing the | |
275 // oldest prematurely closed stream if the set is full. | |
276 void AddPrematurelyClosedStream(QuicStreamId stream_id); | |
277 | |
278 scoped_ptr<QuicConnection> connection_; | 254 scoped_ptr<QuicConnection> connection_; |
279 | 255 |
280 scoped_ptr<QuicHeadersStream> headers_stream_; | 256 scoped_ptr<QuicHeadersStream> headers_stream_; |
281 | 257 |
282 // Tracks the last 20 streams which closed without decompressing headers. | |
283 // This is for best-effort detection of an unrecoverable compression context. | |
284 // Ideally this would be a linked_hash_set as the boolean is unused. | |
285 linked_hash_map<QuicStreamId, bool> prematurely_closed_streams_; | |
286 | |
287 // Streams which have been locally reset before decompressing headers | |
288 // from the peer. These streams need to stay open long enough to | |
289 // process any headers from the peer. | |
290 // Ideally this would be a linked_hash_set as the boolean is unused. | |
291 linked_hash_map<QuicStreamId, bool> zombie_streams_; | |
292 | |
293 // A shim to stand between the connection and the session, to handle stream | 258 // A shim to stand between the connection and the session, to handle stream |
294 // deletions. | 259 // deletions. |
295 scoped_ptr<VisitorShim> visitor_shim_; | 260 scoped_ptr<VisitorShim> visitor_shim_; |
296 | 261 |
297 std::vector<QuicDataStream*> closed_streams_; | 262 std::vector<QuicDataStream*> closed_streams_; |
298 | 263 |
299 QuicSpdyDecompressor decompressor_; | |
300 QuicSpdyCompressor compressor_; | |
301 | |
302 QuicConfig config_; | 264 QuicConfig config_; |
303 | 265 |
304 // Returns the maximum number of streams this connection can open. | 266 // Returns the maximum number of streams this connection can open. |
305 size_t max_open_streams_; | 267 size_t max_open_streams_; |
306 | 268 |
307 // Map from StreamId to pointers to streams that are owned by the caller. | 269 // Map from StreamId to pointers to streams that are owned by the caller. |
308 DataStreamMap stream_map_; | 270 DataStreamMap stream_map_; |
309 QuicStreamId next_stream_id_; | 271 QuicStreamId next_stream_id_; |
310 | 272 |
311 // Set of stream ids that have been "implicitly created" by receipt | 273 // Set of stream ids that have been "implicitly created" by receipt |
312 // of a stream id larger than the next expected stream id. | 274 // of a stream id larger than the next expected stream id. |
313 base::hash_set<QuicStreamId> implicitly_created_streams_; | 275 base::hash_set<QuicStreamId> implicitly_created_streams_; |
314 | 276 |
315 // A list of streams which need to write more data. | 277 // A list of streams which need to write more data. |
316 QuicWriteBlockedList write_blocked_streams_; | 278 QuicWriteBlockedList write_blocked_streams_; |
317 | 279 |
318 // A map of headers waiting to be compressed, and the streams | |
319 // they are associated with. | |
320 map<uint32, QuicStreamId> decompression_blocked_streams_; | |
321 | |
322 QuicStreamId largest_peer_created_stream_id_; | 280 QuicStreamId largest_peer_created_stream_id_; |
323 | 281 |
324 // The latched error with which the connection was closed. | 282 // The latched error with which the connection was closed. |
325 QuicErrorCode error_; | 283 QuicErrorCode error_; |
326 | 284 |
327 // Whether a GoAway has been received. | 285 // Whether a GoAway has been received. |
328 bool goaway_received_; | 286 bool goaway_received_; |
329 // Whether a GoAway has been sent. | 287 // Whether a GoAway has been sent. |
330 bool goaway_sent_; | 288 bool goaway_sent_; |
331 | 289 |
332 // Indicate if there is pending data for the crypto stream. | 290 // Indicate if there is pending data for the crypto stream. |
333 bool has_pending_handshake_; | 291 bool has_pending_handshake_; |
334 | 292 |
335 DISALLOW_COPY_AND_ASSIGN(QuicSession); | 293 DISALLOW_COPY_AND_ASSIGN(QuicSession); |
336 }; | 294 }; |
337 | 295 |
338 } // namespace net | 296 } // namespace net |
339 | 297 |
340 #endif // NET_QUIC_QUIC_SESSION_H_ | 298 #endif // NET_QUIC_QUIC_SESSION_H_ |
OLD | NEW |