Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: trunk/src/net/quic/quic_session.cc

Issue 16374004: Revert 204046 "Land Recent QUIC changes." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/net/quic/quic_session.h ('k') | trunk/src/net/quic/quic_stream_factory_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic_connection.h" 8 #include "net/quic/quic_connection.h"
9 9
10 using base::StringPiece; 10 using base::StringPiece;
11 using base::hash_map; 11 using base::hash_map;
12 using base::hash_set; 12 using base::hash_set;
13 using std::vector; 13 using std::vector;
14 14
15 namespace net { 15 namespace net {
16 16
17 #define ENDPOINT (is_server_ ? "Server: " : " Client: ")
18
19 // We want to make sure we delete any closed streams in a safe manner. 17 // We want to make sure we delete any closed streams in a safe manner.
20 // To avoid deleting a stream in mid-operation, we have a simple shim between 18 // To avoid deleting a stream in mid-operation, we have a simple shim between
21 // us and the stream, so we can delete any streams when we return from 19 // us and the stream, so we can delete any streams when we return from
22 // processing. 20 // processing.
23 // 21 //
24 // We could just override the base methods, but this makes it easier to make 22 // We could just override the base methods, but this makes it easier to make
25 // sure we don't miss any. 23 // sure we don't miss any.
26 class VisitorShim : public QuicConnectionVisitorInterface { 24 class VisitorShim : public QuicConnectionVisitorInterface {
27 public: 25 public:
28 explicit VisitorShim(QuicSession* session) : session_(session) {} 26 explicit VisitorShim(QuicSession* session) : session_(session) {}
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 QuicSession::QuicSession(QuicConnection* connection, 67 QuicSession::QuicSession(QuicConnection* connection,
70 const QuicConfig& config, 68 const QuicConfig& config,
71 bool is_server) 69 bool is_server)
72 : connection_(connection), 70 : connection_(connection),
73 visitor_shim_(new VisitorShim(this)), 71 visitor_shim_(new VisitorShim(this)),
74 config_(config), 72 config_(config),
75 max_open_streams_(kDefaultMaxStreamsPerConnection), 73 max_open_streams_(kDefaultMaxStreamsPerConnection),
76 next_stream_id_(is_server ? 2 : 3), 74 next_stream_id_(is_server ? 2 : 3),
77 is_server_(is_server), 75 is_server_(is_server),
78 largest_peer_created_stream_id_(0), 76 largest_peer_created_stream_id_(0),
79 error_(QUIC_NO_ERROR),
80 goaway_received_(false), 77 goaway_received_(false),
81 goaway_sent_(false) { 78 goaway_sent_(false) {
82 set_max_open_streams(config_.max_streams_per_connection()); 79 set_max_open_streams(config_.max_streams_per_connection());
83 80
84 connection_->set_visitor(visitor_shim_.get()); 81 connection_->set_visitor(visitor_shim_.get());
85 connection_->SetIdleNetworkTimeout(config_.idle_connection_state_lifetime()); 82 connection_->SetIdleNetworkTimeout(config_.idle_connection_state_lifetime());
86 connection_->SetOverallConnectionTimeout( 83 connection_->SetOverallConnectionTimeout(
87 config_.max_time_before_crypto_handshake()); 84 config_.max_time_before_crypto_handshake());
88 // TODO(satyamshekhar): Set congestion control and ICSL also. 85 // TODO(satyamshekhar): Set congestion control and ICSL also.
89 } 86 }
90 87
91 QuicSession::~QuicSession() { 88 QuicSession::~QuicSession() {
92 STLDeleteElements(&closed_streams_); 89 STLDeleteElements(&closed_streams_);
93 STLDeleteValues(&stream_map_); 90 STLDeleteValues(&stream_map_);
94 } 91 }
95 92
96 bool QuicSession::OnPacket(const IPEndPoint& self_address, 93 bool QuicSession::OnPacket(const IPEndPoint& self_address,
97 const IPEndPoint& peer_address, 94 const IPEndPoint& peer_address,
98 const QuicPacketHeader& header, 95 const QuicPacketHeader& header,
99 const vector<QuicStreamFrame>& frames) { 96 const vector<QuicStreamFrame>& frames) {
100 if (header.public_header.guid != connection()->guid()) { 97 if (header.public_header.guid != connection()->guid()) {
101 DLOG(INFO) << ENDPOINT << "Got packet header for invalid GUID: " 98 DLOG(INFO) << "Got packet header for invalid GUID: "
102 << header.public_header.guid; 99 << header.public_header.guid;
103 return false; 100 return false;
104 } 101 }
105 for (size_t i = 0; i < frames.size(); ++i) { 102 for (size_t i = 0; i < frames.size(); ++i) {
106 // TODO(rch) deal with the error case of stream id 0 103 // TODO(rch) deal with the error case of stream id 0
107 if (IsClosedStream(frames[i].stream_id)) continue; 104 if (IsClosedStream(frames[i].stream_id)) continue;
108 105
109 ReliableQuicStream* stream = GetStream(frames[i].stream_id); 106 ReliableQuicStream* stream = GetStream(frames[i].stream_id);
110 if (stream == NULL) return false; 107 if (stream == NULL) return false;
111 if (!stream->WillAcceptStreamFrame(frames[i])) return false; 108 if (!stream->WillAcceptStreamFrame(frames[i])) return false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 142 }
146 stream->OnStreamReset(frame.error_code); 143 stream->OnStreamReset(frame.error_code);
147 } 144 }
148 145
149 void QuicSession::OnGoAway(const QuicGoAwayFrame& frame) { 146 void QuicSession::OnGoAway(const QuicGoAwayFrame& frame) {
150 DCHECK(frame.last_good_stream_id < next_stream_id_); 147 DCHECK(frame.last_good_stream_id < next_stream_id_);
151 goaway_received_ = true; 148 goaway_received_ = true;
152 } 149 }
153 150
154 void QuicSession::ConnectionClose(QuicErrorCode error, bool from_peer) { 151 void QuicSession::ConnectionClose(QuicErrorCode error, bool from_peer) {
155 if (error_ == QUIC_NO_ERROR) {
156 error_ = error;
157 }
158
159 while (stream_map_.size() != 0) { 152 while (stream_map_.size() != 0) {
160 ReliableStreamMap::iterator it = stream_map_.begin(); 153 ReliableStreamMap::iterator it = stream_map_.begin();
161 QuicStreamId id = it->first; 154 QuicStreamId id = it->first;
162 it->second->ConnectionClose(error, from_peer); 155 it->second->ConnectionClose(error, from_peer);
163 // The stream should call CloseStream as part of ConnectionClose. 156 // The stream should call CloseStream as part of ConnectionClose.
164 if (stream_map_.find(id) != stream_map_.end()) { 157 if (stream_map_.find(id) != stream_map_.end()) {
165 LOG(DFATAL) << ENDPOINT << "Stream failed to close under ConnectionClose"; 158 LOG(DFATAL) << "Stream failed to close under ConnectionClose";
166 CloseStream(id); 159 CloseStream(id);
167 } 160 }
168 } 161 }
169 } 162 }
170 163
171 bool QuicSession::OnCanWrite() { 164 bool QuicSession::OnCanWrite() {
172 // We latch this here rather than doing a traditional loop, because streams 165 // We latch this here rather than doing a traditional loop, because streams
173 // may be modifying the list as we loop. 166 // may be modifying the list as we loop.
174 int remaining_writes = write_blocked_streams_.NumObjects(); 167 int remaining_writes = write_blocked_streams_.NumObjects();
175 168
(...skipping 25 matching lines...) Expand all
201 connection_->SendRstStream(id, error); 194 connection_->SendRstStream(id, error);
202 CloseStream(id); 195 CloseStream(id);
203 } 196 }
204 197
205 void QuicSession::SendGoAway(QuicErrorCode error_code, const string& reason) { 198 void QuicSession::SendGoAway(QuicErrorCode error_code, const string& reason) {
206 goaway_sent_ = true; 199 goaway_sent_ = true;
207 connection_->SendGoAway(error_code, largest_peer_created_stream_id_, reason); 200 connection_->SendGoAway(error_code, largest_peer_created_stream_id_, reason);
208 } 201 }
209 202
210 void QuicSession::CloseStream(QuicStreamId stream_id) { 203 void QuicSession::CloseStream(QuicStreamId stream_id) {
211 DLOG(INFO) << ENDPOINT << "Closing stream " << stream_id; 204 DLOG(INFO) << "Closing stream " << stream_id;
212 205
213 ReliableStreamMap::iterator it = stream_map_.find(stream_id); 206 ReliableStreamMap::iterator it = stream_map_.find(stream_id);
214 if (it == stream_map_.end()) { 207 if (it == stream_map_.end()) {
215 DLOG(INFO) << ENDPOINT << "Stream is already closed: " << stream_id; 208 DLOG(INFO) << "Stream is already closed: " << stream_id;
216 return; 209 return;
217 } 210 }
218 ReliableQuicStream* stream = it->second; 211 ReliableQuicStream* stream = it->second;
219 closed_streams_.push_back(it->second); 212 closed_streams_.push_back(it->second);
220 stream_map_.erase(it); 213 stream_map_.erase(it);
221 stream->OnClose(); 214 stream->OnClose();
222 } 215 }
223 216
224 bool QuicSession::IsEncryptionEstablished() { 217 bool QuicSession::IsEncryptionEstablished() {
225 return GetCryptoStream()->encryption_established(); 218 return GetCryptoStream()->encryption_established();
(...skipping 11 matching lines...) Expand all
237 break; 230 break;
238 231
239 case ENCRYPTION_REESTABLISHED: 232 case ENCRYPTION_REESTABLISHED:
240 // Retransmit originally packets that were sent, since they can't be 233 // Retransmit originally packets that were sent, since they can't be
241 // decrypted by the peer. 234 // decrypted by the peer.
242 connection_->RetransmitUnackedPackets( 235 connection_->RetransmitUnackedPackets(
243 QuicConnection::INITIAL_ENCRYPTION_ONLY); 236 QuicConnection::INITIAL_ENCRYPTION_ONLY);
244 break; 237 break;
245 238
246 case HANDSHAKE_CONFIRMED: 239 case HANDSHAKE_CONFIRMED:
247 LOG_IF(DFATAL, !config_.negotiated()) << ENDPOINT 240 LOG_IF(DFATAL, !config_.negotiated())
248 << "Handshake confirmed without parameter negotiation."; 241 << "Handshake confirmed without parameter negotiation.";
249 connection_->SetIdleNetworkTimeout( 242 connection_->SetIdleNetworkTimeout(
250 config_.idle_connection_state_lifetime()); 243 config_.idle_connection_state_lifetime());
251 connection_->SetOverallConnectionTimeout(QuicTime::Delta::Infinite()); 244 connection_->SetOverallConnectionTimeout(QuicTime::Delta::Infinite());
252 max_open_streams_ = config_.max_streams_per_connection(); 245 max_open_streams_ = config_.max_streams_per_connection();
253 break; 246 break;
254 247
255 default: 248 default:
256 LOG(ERROR) << ENDPOINT << "Got unknown handshake event: " << event; 249 LOG(ERROR) << "Got unknown handshake event: " << event;
257 } 250 }
258 } 251 }
259 252
260 QuicConfig* QuicSession::config() { 253 QuicConfig* QuicSession::config() {
261 return &config_; 254 return &config_;
262 } 255 }
263 256
264 void QuicSession::ActivateStream(ReliableQuicStream* stream) { 257 void QuicSession::ActivateStream(ReliableQuicStream* stream) {
265 DLOG(INFO) << ENDPOINT << "num_streams: " << stream_map_.size() 258 DLOG(INFO) << "num_streams: " << stream_map_.size()
266 << ". activating " << stream->id(); 259 << ". activating " << stream->id();
267 DCHECK(stream_map_.count(stream->id()) == 0); 260 DCHECK(stream_map_.count(stream->id()) == 0);
268 stream_map_[stream->id()] = stream; 261 stream_map_[stream->id()] = stream;
269 } 262 }
270 263
271 QuicStreamId QuicSession::GetNextStreamId() { 264 QuicStreamId QuicSession::GetNextStreamId() {
272 QuicStreamId id = next_stream_id_; 265 QuicStreamId id = next_stream_id_;
273 next_stream_id_ += 2; 266 next_stream_id_ += 2;
274 return id; 267 return id;
275 } 268 }
276 269
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 QuicStreamId stream_id) { 359 QuicStreamId stream_id) {
367 decompression_blocked_streams_[header_id] = stream_id; 360 decompression_blocked_streams_[header_id] = stream_id;
368 } 361 }
369 362
370 void QuicSession::PostProcessAfterData() { 363 void QuicSession::PostProcessAfterData() {
371 STLDeleteElements(&closed_streams_); 364 STLDeleteElements(&closed_streams_);
372 closed_streams_.clear(); 365 closed_streams_.clear();
373 } 366 }
374 367
375 } // namespace net 368 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/quic/quic_session.h ('k') | trunk/src/net/quic/quic_stream_factory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698