| 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/core/quic_connection.h" | 5 #include "net/quic/core/quic_connection.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER | 331 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER |
| 332 ? kDefaultServerMaxPacketSize | 332 ? kDefaultServerMaxPacketSize |
| 333 : kDefaultMaxPacketSize); | 333 : kDefaultMaxPacketSize); |
| 334 received_packet_manager_.SetVersion(version()); | 334 received_packet_manager_.SetVersion(version()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 QuicConnection::~QuicConnection() { | 337 QuicConnection::~QuicConnection() { |
| 338 if (owns_writer_) { | 338 if (owns_writer_) { |
| 339 delete writer_; | 339 delete writer_; |
| 340 } | 340 } |
| 341 STLDeleteElements(&undecryptable_packets_); | 341 base::STLDeleteElements(&undecryptable_packets_); |
| 342 ClearQueuedPackets(); | 342 ClearQueuedPackets(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void QuicConnection::ClearQueuedPackets() { | 345 void QuicConnection::ClearQueuedPackets() { |
| 346 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 346 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
| 347 it != queued_packets_.end(); ++it) { | 347 it != queued_packets_.end(); ++it) { |
| 348 // Delete the buffer before calling ClearSerializedPacket, which sets | 348 // Delete the buffer before calling ClearSerializedPacket, which sets |
| 349 // encrypted_buffer to nullptr. | 349 // encrypted_buffer to nullptr. |
| 350 delete[] it->encrypted_buffer; | 350 delete[] it->encrypted_buffer; |
| 351 QuicUtils::ClearSerializedPacket(&(*it)); | 351 QuicUtils::ClearSerializedPacket(&(*it)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 436 } |
| 437 | 437 |
| 438 bool QuicConnection::SelectMutualVersion( | 438 bool QuicConnection::SelectMutualVersion( |
| 439 const QuicVersionVector& available_versions) { | 439 const QuicVersionVector& available_versions) { |
| 440 // Try to find the highest mutual version by iterating over supported | 440 // Try to find the highest mutual version by iterating over supported |
| 441 // versions, starting with the highest, and breaking out of the loop once we | 441 // versions, starting with the highest, and breaking out of the loop once we |
| 442 // find a matching version in the provided available_versions vector. | 442 // find a matching version in the provided available_versions vector. |
| 443 const QuicVersionVector& supported_versions = framer_.supported_versions(); | 443 const QuicVersionVector& supported_versions = framer_.supported_versions(); |
| 444 for (size_t i = 0; i < supported_versions.size(); ++i) { | 444 for (size_t i = 0; i < supported_versions.size(); ++i) { |
| 445 const QuicVersion& version = supported_versions[i]; | 445 const QuicVersion& version = supported_versions[i]; |
| 446 if (ContainsValue(available_versions, version)) { | 446 if (base::ContainsValue(available_versions, version)) { |
| 447 framer_.set_version(version); | 447 framer_.set_version(version); |
| 448 return true; | 448 return true; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 return false; | 452 return false; |
| 453 } | 453 } |
| 454 | 454 |
| 455 void QuicConnection::OnError(QuicFramer* framer) { | 455 void QuicConnection::OnError(QuicFramer* framer) { |
| 456 // Packets that we can not or have not decrypted are dropped. | 456 // Packets that we can not or have not decrypted are dropped. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 } | 555 } |
| 556 if (debug_visitor_ != nullptr) { | 556 if (debug_visitor_ != nullptr) { |
| 557 debug_visitor_->OnVersionNegotiationPacket(packet); | 557 debug_visitor_->OnVersionNegotiationPacket(packet); |
| 558 } | 558 } |
| 559 | 559 |
| 560 if (version_negotiation_state_ != START_NEGOTIATION) { | 560 if (version_negotiation_state_ != START_NEGOTIATION) { |
| 561 // Possibly a duplicate version negotiation packet. | 561 // Possibly a duplicate version negotiation packet. |
| 562 return; | 562 return; |
| 563 } | 563 } |
| 564 | 564 |
| 565 if (ContainsValue(packet.versions, version())) { | 565 if (base::ContainsValue(packet.versions, version())) { |
| 566 const string error_details = | 566 const string error_details = |
| 567 "Server already supports client's version and should have accepted the " | 567 "Server already supports client's version and should have accepted the " |
| 568 "connection."; | 568 "connection."; |
| 569 DLOG(WARNING) << error_details; | 569 DLOG(WARNING) << error_details; |
| 570 TearDownLocalConnectionState(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, | 570 TearDownLocalConnectionState(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
| 571 error_details, | 571 error_details, |
| 572 ConnectionCloseSource::FROM_SELF); | 572 ConnectionCloseSource::FROM_SELF); |
| 573 return; | 573 return; |
| 574 } | 574 } |
| 575 | 575 |
| (...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 // never be able to be decrypted. | 2017 // never be able to be decrypted. |
| 2018 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { | 2018 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { |
| 2019 if (debug_visitor_ != nullptr) { | 2019 if (debug_visitor_ != nullptr) { |
| 2020 // TODO(rtenneti): perhaps more efficient to pass the number of | 2020 // TODO(rtenneti): perhaps more efficient to pass the number of |
| 2021 // undecryptable packets as the argument to OnUndecryptablePacket so that | 2021 // undecryptable packets as the argument to OnUndecryptablePacket so that |
| 2022 // we just need to call OnUndecryptablePacket once? | 2022 // we just need to call OnUndecryptablePacket once? |
| 2023 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { | 2023 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { |
| 2024 debug_visitor_->OnUndecryptablePacket(); | 2024 debug_visitor_->OnUndecryptablePacket(); |
| 2025 } | 2025 } |
| 2026 } | 2026 } |
| 2027 STLDeleteElements(&undecryptable_packets_); | 2027 base::STLDeleteElements(&undecryptable_packets_); |
| 2028 } | 2028 } |
| 2029 } | 2029 } |
| 2030 | 2030 |
| 2031 void QuicConnection::CloseConnection( | 2031 void QuicConnection::CloseConnection( |
| 2032 QuicErrorCode error, | 2032 QuicErrorCode error, |
| 2033 const string& error_details, | 2033 const string& error_details, |
| 2034 ConnectionCloseBehavior connection_close_behavior) { | 2034 ConnectionCloseBehavior connection_close_behavior) { |
| 2035 DCHECK(!error_details.empty()); | 2035 DCHECK(!error_details.empty()); |
| 2036 if (!connected_) { | 2036 if (!connected_) { |
| 2037 DVLOG(1) << "Connection is already closed."; | 2037 DVLOG(1) << "Connection is already closed."; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 // the sender and a signaling mechanism -- if the sender uses a | 2525 // the sender and a signaling mechanism -- if the sender uses a |
| 2526 // different MinRTO, we may get spurious retransmissions. May not have | 2526 // different MinRTO, we may get spurious retransmissions. May not have |
| 2527 // any benefits, but if the delayed ack becomes a significant source | 2527 // any benefits, but if the delayed ack becomes a significant source |
| 2528 // of (likely, tail) latency, then consider such a mechanism. | 2528 // of (likely, tail) latency, then consider such a mechanism. |
| 2529 const QuicTime::Delta QuicConnection::DelayedAckTime() { | 2529 const QuicTime::Delta QuicConnection::DelayedAckTime() { |
| 2530 return QuicTime::Delta::FromMilliseconds( | 2530 return QuicTime::Delta::FromMilliseconds( |
| 2531 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2)); | 2531 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2)); |
| 2532 } | 2532 } |
| 2533 | 2533 |
| 2534 } // namespace net | 2534 } // namespace net |
| OLD | NEW |