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 #include "net/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "net/quic/crypto/proof_verifier.h" | 8 #include "net/quic/crypto/proof_verifier.h" |
9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
10 #include "net/ssl/ssl_info.h" | 10 #include "net/ssl/ssl_info.h" |
11 | 11 |
12 using base::StringPiece; | 12 using base::StringPiece; |
13 using base::hash_map; | 13 using base::hash_map; |
14 using base::hash_set; | 14 using base::hash_set; |
15 using std::make_pair; | 15 using std::make_pair; |
16 using std::vector; | 16 using std::vector; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 const size_t kMaxPrematurelyClosedStreamsTracked = 20; | 20 const size_t kMaxPrematurelyClosedStreamsTracked = 20; |
21 const size_t kMaxZombieStreams = 20; | 21 const size_t kMaxZombieStreams = 20; |
22 | 22 |
23 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") | 23 #define ENDPOINT (is_server() ? "Server: " : " Client: ") |
24 | 24 |
25 // We want to make sure we delete any closed streams in a safe manner. | 25 // We want to make sure we delete any closed streams in a safe manner. |
26 // To avoid deleting a stream in mid-operation, we have a simple shim between | 26 // To avoid deleting a stream in mid-operation, we have a simple shim between |
27 // us and the stream, so we can delete any streams when we return from | 27 // us and the stream, so we can delete any streams when we return from |
28 // processing. | 28 // processing. |
29 // | 29 // |
30 // We could just override the base methods, but this makes it easier to make | 30 // We could just override the base methods, but this makes it easier to make |
31 // sure we don't miss any. | 31 // sure we don't miss any. |
32 class VisitorShim : public QuicConnectionVisitorInterface { | 32 class VisitorShim : public QuicConnectionVisitorInterface { |
33 public: | 33 public: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 virtual bool HasPendingHandshake() const OVERRIDE { | 72 virtual bool HasPendingHandshake() const OVERRIDE { |
73 return session_->HasPendingHandshake(); | 73 return session_->HasPendingHandshake(); |
74 } | 74 } |
75 | 75 |
76 private: | 76 private: |
77 QuicSession* session_; | 77 QuicSession* session_; |
78 }; | 78 }; |
79 | 79 |
80 QuicSession::QuicSession(QuicConnection* connection, | 80 QuicSession::QuicSession(QuicConnection* connection, |
81 const QuicConfig& config, | 81 const QuicConfig& config) |
82 bool is_server) | |
83 : connection_(connection), | 82 : connection_(connection), |
84 visitor_shim_(new VisitorShim(this)), | 83 visitor_shim_(new VisitorShim(this)), |
85 config_(config), | 84 config_(config), |
86 max_open_streams_(config_.max_streams_per_connection()), | 85 max_open_streams_(config_.max_streams_per_connection()), |
87 next_stream_id_(is_server ? 2 : 3), | 86 next_stream_id_(is_server() ? 2 : 3), |
88 is_server_(is_server), | |
89 largest_peer_created_stream_id_(0), | 87 largest_peer_created_stream_id_(0), |
90 error_(QUIC_NO_ERROR), | 88 error_(QUIC_NO_ERROR), |
91 goaway_received_(false), | 89 goaway_received_(false), |
92 goaway_sent_(false), | 90 goaway_sent_(false), |
93 has_pending_handshake_(false) { | 91 has_pending_handshake_(false) { |
94 | 92 |
95 connection_->set_visitor(visitor_shim_.get()); | 93 connection_->set_visitor(visitor_shim_.get()); |
96 connection_->SetFromConfig(config_); | 94 connection_->SetFromConfig(config_); |
97 if (connection_->connected()) { | 95 if (connection_->connected()) { |
98 connection_->SetOverallConnectionTimeout( | 96 connection_->SetOverallConnectionTimeout( |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (it == stream_map_.end()) { | 284 if (it == stream_map_.end()) { |
287 DVLOG(1) << ENDPOINT << "Stream is already closed: " << stream_id; | 285 DVLOG(1) << ENDPOINT << "Stream is already closed: " << stream_id; |
288 return; | 286 return; |
289 } | 287 } |
290 QuicDataStream* stream = it->second; | 288 QuicDataStream* stream = it->second; |
291 if (connection_->connected() && !stream->headers_decompressed()) { | 289 if (connection_->connected() && !stream->headers_decompressed()) { |
292 // If the stream is being closed locally (for example a client cancelling | 290 // If the stream is being closed locally (for example a client cancelling |
293 // a request before receiving the response) then we need to make sure that | 291 // a request before receiving the response) then we need to make sure that |
294 // we keep the stream alive long enough to process any response or | 292 // we keep the stream alive long enough to process any response or |
295 // RST_STREAM frames. | 293 // RST_STREAM frames. |
296 if (locally_reset && !is_server_) { | 294 if (locally_reset && !is_server()) { |
297 AddZombieStream(stream_id); | 295 AddZombieStream(stream_id); |
298 return; | 296 return; |
299 } | 297 } |
300 | 298 |
301 // This stream has been closed before the headers were decompressed. | 299 // This stream has been closed before the headers were decompressed. |
302 // This might cause problems with head of line blocking of headers. | 300 // This might cause problems with head of line blocking of headers. |
303 // If the peer sent headers which were lost but we now close the stream | 301 // If the peer sent headers which were lost but we now close the stream |
304 // we will never be able to decompress headers for other streams. | 302 // we will never be able to decompress headers for other streams. |
305 // To deal with this, we keep track of streams which have been closed | 303 // To deal with this, we keep track of streams which have been closed |
306 // prematurely. If we ever receive data frames for this steam, then we | 304 // prematurely. If we ever receive data frames for this steam, then we |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 NOTIMPLEMENTED(); | 530 NOTIMPLEMENTED(); |
533 return false; | 531 return false; |
534 } | 532 } |
535 | 533 |
536 void QuicSession::PostProcessAfterData() { | 534 void QuicSession::PostProcessAfterData() { |
537 STLDeleteElements(&closed_streams_); | 535 STLDeleteElements(&closed_streams_); |
538 closed_streams_.clear(); | 536 closed_streams_.clear(); |
539 } | 537 } |
540 | 538 |
541 } // namespace net | 539 } // namespace net |
OLD | NEW |