OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_dispatcher.h" | 5 #include "net/quic/quic_dispatcher.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), | 170 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), |
171 framer_visitor_(new QuicFramerVisitor(this)) { | 171 framer_visitor_(new QuicFramerVisitor(this)) { |
172 framer_.set_visitor(framer_visitor_.get()); | 172 framer_.set_visitor(framer_visitor_.get()); |
173 } | 173 } |
174 | 174 |
175 QuicDispatcher::~QuicDispatcher() { | 175 QuicDispatcher::~QuicDispatcher() { |
176 STLDeleteValues(&session_map_); | 176 STLDeleteValues(&session_map_); |
177 STLDeleteElements(&closed_session_list_); | 177 STLDeleteElements(&closed_session_list_); |
178 } | 178 } |
179 | 179 |
180 void QuicDispatcher::Initialize(QuicPacketWriter* writer) { | 180 void QuicDispatcher::Initialize(QuicServerPacketWriter* writer) { |
181 DCHECK(writer_ == NULL); | 181 DCHECK(writer_ == NULL); |
182 writer_.reset(writer); | 182 writer_.reset(writer); |
183 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); | 183 time_wait_list_manager_.reset(CreateQuicTimeWaitListManager()); |
184 | 184 |
185 // Remove all versions > QUIC_VERSION_16 from the | 185 // Remove all versions > QUIC_VERSION_16 from the |
186 // supported_versions_no_flow_control_ vector. | 186 // supported_versions_no_flow_control_ vector. |
187 QuicVersionVector::iterator it = | 187 QuicVersionVector::iterator it = |
188 find(supported_versions_no_flow_control_.begin(), | 188 find(supported_versions_no_flow_control_.begin(), |
189 supported_versions_no_flow_control_.end(), QUIC_VERSION_17); | 189 supported_versions_no_flow_control_.end(), QUIC_VERSION_17); |
190 if (it != supported_versions_no_flow_control_.end()) { | 190 if (it != supported_versions_no_flow_control_.end()) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 connection->version(), | 294 connection->version(), |
295 connection_close_packet); | 295 connection_close_packet); |
296 session_map_.erase(it); | 296 session_map_.erase(it); |
297 } | 297 } |
298 | 298 |
299 void QuicDispatcher::DeleteSessions() { | 299 void QuicDispatcher::DeleteSessions() { |
300 STLDeleteElements(&closed_session_list_); | 300 STLDeleteElements(&closed_session_list_); |
301 } | 301 } |
302 | 302 |
303 void QuicDispatcher::OnCanWrite() { | 303 void QuicDispatcher::OnCanWrite() { |
304 // We got an EPOLLOUT: the socket should not be blocked. | 304 // We finished a write: the socket should not be blocked. |
305 writer_->SetWritable(); | 305 writer_->SetWritable(); |
306 | 306 |
307 // Give each writer one attempt to write. | 307 // Let all the blocked writers try to write, until we're blocked again or |
308 int num_writers = write_blocked_list_.size(); | 308 // there's no work left. |
309 for (int i = 0; i < num_writers; ++i) { | 309 while (!write_blocked_list_.empty() && !writer_->IsWriteBlocked()) { |
310 if (write_blocked_list_.empty()) { | |
311 return; | |
312 } | |
313 QuicBlockedWriterInterface* blocked_writer = | 310 QuicBlockedWriterInterface* blocked_writer = |
314 write_blocked_list_.begin()->first; | 311 write_blocked_list_.begin()->first; |
315 write_blocked_list_.erase(write_blocked_list_.begin()); | 312 write_blocked_list_.erase(write_blocked_list_.begin()); |
316 blocked_writer->OnCanWrite(); | 313 blocked_writer->OnCanWrite(); |
317 if (writer_->IsWriteBlocked()) { | |
318 // We were unable to write. Wait for the next EPOLLOUT. The writer is | |
319 // responsible for adding itself to the blocked list via OnWriteBlocked(). | |
320 return; | |
321 } | |
322 } | 314 } |
323 } | 315 } |
324 | 316 |
325 bool QuicDispatcher::HasPendingWrites() const { | 317 bool QuicDispatcher::HasPendingWrites() const { |
326 return !write_blocked_list_.empty(); | 318 return !write_blocked_list_.empty(); |
327 } | 319 } |
328 | 320 |
329 void QuicDispatcher::Shutdown() { | 321 void QuicDispatcher::Shutdown() { |
330 while (!session_map_.empty()) { | 322 while (!session_map_.empty()) { |
331 QuicSession* session = session_map_.begin()->second; | 323 QuicSession* session = session_map_.begin()->second; |
(...skipping 27 matching lines...) Expand all Loading... |
359 | 351 |
360 void QuicDispatcher::OnWriteBlocked(QuicBlockedWriterInterface* writer) { | 352 void QuicDispatcher::OnWriteBlocked(QuicBlockedWriterInterface* writer) { |
361 DCHECK(writer_->IsWriteBlocked()); | 353 DCHECK(writer_->IsWriteBlocked()); |
362 write_blocked_list_.insert(make_pair(writer, true)); | 354 write_blocked_list_.insert(make_pair(writer, true)); |
363 } | 355 } |
364 | 356 |
365 QuicSession* QuicDispatcher::CreateQuicSession( | 357 QuicSession* QuicDispatcher::CreateQuicSession( |
366 QuicConnectionId connection_id, | 358 QuicConnectionId connection_id, |
367 const IPEndPoint& server_address, | 359 const IPEndPoint& server_address, |
368 const IPEndPoint& client_address) { | 360 const IPEndPoint& client_address) { |
| 361 QuicPerConnectionPacketWriter* per_connection_packet_writer = |
| 362 new QuicPerConnectionPacketWriter(writer_.get()); |
| 363 QuicConnection* connection = |
| 364 CreateQuicConnection(connection_id, |
| 365 server_address, |
| 366 client_address, |
| 367 per_connection_packet_writer); |
369 QuicServerSession* session = new QuicServerSession( | 368 QuicServerSession* session = new QuicServerSession( |
370 config_, | 369 config_, |
371 CreateQuicConnection(connection_id, server_address, client_address), | 370 connection, |
| 371 per_connection_packet_writer, |
372 this); | 372 this); |
373 session->InitializeSession(crypto_config_); | 373 session->InitializeSession(crypto_config_); |
374 return session; | 374 return session; |
375 } | 375 } |
376 | 376 |
377 QuicConnection* QuicDispatcher::CreateQuicConnection( | 377 QuicConnection* QuicDispatcher::CreateQuicConnection( |
378 QuicConnectionId connection_id, | 378 QuicConnectionId connection_id, |
379 const IPEndPoint& server_address, | 379 const IPEndPoint& server_address, |
380 const IPEndPoint& client_address) { | 380 const IPEndPoint& client_address, |
| 381 QuicPerConnectionPacketWriter* writer) { |
| 382 QuicConnection* connection; |
381 if (FLAGS_enable_quic_stream_flow_control_2 && | 383 if (FLAGS_enable_quic_stream_flow_control_2 && |
382 FLAGS_enable_quic_connection_flow_control_2) { | 384 FLAGS_enable_quic_connection_flow_control_2) { |
383 DVLOG(1) << "Creating QuicDispatcher with all versions."; | 385 DVLOG(1) << "Creating QuicDispatcher with all versions."; |
384 return new QuicConnection(connection_id, client_address, helper_, | 386 connection = new QuicConnection(connection_id, client_address, helper_, |
385 writer_.get(), true, supported_versions_); | 387 writer, true, supported_versions_); |
386 } | 388 } else if (FLAGS_enable_quic_stream_flow_control_2 && |
387 | |
388 if (FLAGS_enable_quic_stream_flow_control_2 && | |
389 !FLAGS_enable_quic_connection_flow_control_2) { | 389 !FLAGS_enable_quic_connection_flow_control_2) { |
390 DVLOG(1) << "Connection flow control disabled, creating QuicDispatcher " | 390 DVLOG(1) << "Connection flow control disabled, creating QuicDispatcher " |
391 << "WITHOUT version 19 or higher."; | 391 << "WITHOUT version 19 or higher."; |
392 return new QuicConnection(connection_id, client_address, helper_, | 392 connection = new QuicConnection( |
393 writer_.get(), true, | 393 connection_id, client_address, helper_, |
394 supported_versions_no_connection_flow_control_); | 394 writer, true, |
| 395 supported_versions_no_connection_flow_control_); |
| 396 } else { |
| 397 DVLOG(1) << "Flow control disabled, creating QuicDispatcher WITHOUT " |
| 398 << "version 17 or higher."; |
| 399 connection = new QuicConnection(connection_id, client_address, helper_, |
| 400 writer, true, |
| 401 supported_versions_no_flow_control_); |
395 } | 402 } |
396 | 403 writer->set_connection(connection); |
397 DVLOG(1) << "Flow control disabled, creating QuicDispatcher WITHOUT " | 404 return connection; |
398 << "version 17 or higher."; | |
399 return new QuicConnection(connection_id, client_address, helper_, | |
400 writer_.get(), true, | |
401 supported_versions_no_flow_control_); | |
402 } | 405 } |
403 | 406 |
404 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { | 407 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { |
405 return new QuicTimeWaitListManager( | 408 return new QuicTimeWaitListManager( |
406 writer_.get(), this, helper_, supported_versions()); | 409 writer_.get(), this, helper_, supported_versions()); |
407 } | 410 } |
408 | 411 |
409 bool QuicDispatcher::HandlePacketForTimeWait( | 412 bool QuicDispatcher::HandlePacketForTimeWait( |
410 const QuicPacketPublicHeader& header) { | 413 const QuicPacketPublicHeader& header) { |
411 if (header.reset_flag) { | 414 if (header.reset_flag) { |
412 // Public reset packets do not have sequence numbers, so ignore the packet. | 415 // Public reset packets do not have sequence numbers, so ignore the packet. |
413 return false; | 416 return false; |
414 } | 417 } |
415 | 418 |
416 // Switch the framer to the correct version, so that the sequence number can | 419 // Switch the framer to the correct version, so that the sequence number can |
417 // be parsed correctly. | 420 // be parsed correctly. |
418 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( | 421 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( |
419 header.connection_id)); | 422 header.connection_id)); |
420 | 423 |
421 // Continue parsing the packet to extract the sequence number. Then | 424 // Continue parsing the packet to extract the sequence number. Then |
422 // send it to the time wait manager in OnUnathenticatedHeader. | 425 // send it to the time wait manager in OnUnathenticatedHeader. |
423 return true; | 426 return true; |
424 } | 427 } |
425 | 428 |
426 } // namespace net | 429 } // namespace net |
OLD | NEW |