| 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_connection.h" | 5 #include "net/quic/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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 visitor_->OnWriteBlocked(); | 1086 visitor_->OnWriteBlocked(); |
| 1087 return; | 1087 return; |
| 1088 } | 1088 } |
| 1089 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" | 1089 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" |
| 1090 << QuicVersionVectorToString(framer_.supported_versions()) << "}"; | 1090 << QuicVersionVectorToString(framer_.supported_versions()) << "}"; |
| 1091 scoped_ptr<QuicEncryptedPacket> version_packet( | 1091 scoped_ptr<QuicEncryptedPacket> version_packet( |
| 1092 packet_generator_.SerializeVersionNegotiationPacket( | 1092 packet_generator_.SerializeVersionNegotiationPacket( |
| 1093 framer_.supported_versions())); | 1093 framer_.supported_versions())); |
| 1094 WriteResult result = | 1094 WriteResult result = |
| 1095 writer_->WritePacket(version_packet->data(), version_packet->length(), | 1095 writer_->WritePacket(version_packet->data(), version_packet->length(), |
| 1096 self_address().address(), peer_address()); | 1096 self_address().address_number(), peer_address()); |
| 1097 | 1097 |
| 1098 if (result.status == WRITE_STATUS_ERROR) { | 1098 if (result.status == WRITE_STATUS_ERROR) { |
| 1099 OnWriteError(result.error_code); | 1099 OnWriteError(result.error_code); |
| 1100 return; | 1100 return; |
| 1101 } | 1101 } |
| 1102 if (result.status == WRITE_STATUS_BLOCKED) { | 1102 if (result.status == WRITE_STATUS_BLOCKED) { |
| 1103 visitor_->OnWriteBlocked(); | 1103 visitor_->OnWriteBlocked(); |
| 1104 if (writer_->IsWriteBlockedDataBuffered()) { | 1104 if (writer_->IsWriteBlockedDataBuffered()) { |
| 1105 pending_version_negotiation_packet_ = false; | 1105 pending_version_negotiation_packet_ = false; |
| 1106 } | 1106 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 SetPingAlarm(); | 1255 SetPingAlarm(); |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 void QuicConnection::CheckForAddressMigration(const IPEndPoint& self_address, | 1258 void QuicConnection::CheckForAddressMigration(const IPEndPoint& self_address, |
| 1259 const IPEndPoint& peer_address) { | 1259 const IPEndPoint& peer_address) { |
| 1260 peer_ip_changed_ = false; | 1260 peer_ip_changed_ = false; |
| 1261 peer_port_changed_ = false; | 1261 peer_port_changed_ = false; |
| 1262 self_ip_changed_ = false; | 1262 self_ip_changed_ = false; |
| 1263 self_port_changed_ = false; | 1263 self_port_changed_ = false; |
| 1264 | 1264 |
| 1265 if (peer_address_.address().empty()) { | 1265 if (peer_address_.address_number().empty()) { |
| 1266 peer_address_ = peer_address; | 1266 peer_address_ = peer_address; |
| 1267 } | 1267 } |
| 1268 if (self_address_.address().empty()) { | 1268 if (self_address_.address_number().empty()) { |
| 1269 self_address_ = self_address; | 1269 self_address_ = self_address; |
| 1270 } | 1270 } |
| 1271 | 1271 |
| 1272 if (!peer_address.address().empty() && !peer_address_.address().empty()) { | 1272 if (!peer_address.address_number().empty() && |
| 1273 peer_ip_changed_ = (peer_address.address() != peer_address_.address()); | 1273 !peer_address_.address_number().empty()) { |
| 1274 peer_ip_changed_ = |
| 1275 (peer_address.address_number() != peer_address_.address_number()); |
| 1274 peer_port_changed_ = (peer_address.port() != peer_address_.port()); | 1276 peer_port_changed_ = (peer_address.port() != peer_address_.port()); |
| 1275 | 1277 |
| 1276 // Store in case we want to migrate connection in ProcessValidatedPacket. | 1278 // Store in case we want to migrate connection in ProcessValidatedPacket. |
| 1277 migrating_peer_ip_ = peer_address.address(); | 1279 migrating_peer_ip_ = peer_address.address_number(); |
| 1278 migrating_peer_port_ = peer_address.port(); | 1280 migrating_peer_port_ = peer_address.port(); |
| 1279 } | 1281 } |
| 1280 | 1282 |
| 1281 if (!self_address.address().empty() && !self_address_.address().empty()) { | 1283 if (!self_address.address_number().empty() && |
| 1282 self_ip_changed_ = (self_address.address() != self_address_.address()); | 1284 !self_address_.address_number().empty()) { |
| 1285 self_ip_changed_ = |
| 1286 (self_address.address_number() != self_address_.address_number()); |
| 1283 self_port_changed_ = (self_address.port() != self_address_.port()); | 1287 self_port_changed_ = (self_address.port() != self_address_.port()); |
| 1284 } | 1288 } |
| 1285 | 1289 |
| 1286 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever | 1290 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever |
| 1287 // the connection is migrated, it usually ends up being on a different path, | 1291 // the connection is migrated, it usually ends up being on a different path, |
| 1288 // with possibly smaller MTU. This means the max packet size has to be reset | 1292 // with possibly smaller MTU. This means the max packet size has to be reset |
| 1289 // and MTU discovery mechanism re-initialized. The main reason the code does | 1293 // and MTU discovery mechanism re-initialized. The main reason the code does |
| 1290 // not do it now is that the retransmission code currently cannot deal with | 1294 // not do it now is that the retransmission code currently cannot deal with |
| 1291 // the case when it needs to resend a packet created with larger MTU (see | 1295 // the case when it needs to resend a packet created with larger MTU (see |
| 1292 // b/22172803). | 1296 // b/22172803). |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 1400 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
| 1397 } | 1401 } |
| 1398 } | 1402 } |
| 1399 } | 1403 } |
| 1400 | 1404 |
| 1401 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); | 1405 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); |
| 1402 | 1406 |
| 1403 if (peer_ip_changed_ || peer_port_changed_) { | 1407 if (peer_ip_changed_ || peer_port_changed_) { |
| 1404 IPEndPoint old_peer_address = peer_address_; | 1408 IPEndPoint old_peer_address = peer_address_; |
| 1405 peer_address_ = IPEndPoint( | 1409 peer_address_ = IPEndPoint( |
| 1406 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(), | 1410 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address_number(), |
| 1407 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); | 1411 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); |
| 1408 | 1412 |
| 1409 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " | 1413 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " |
| 1410 << old_peer_address.ToString() << " to " | 1414 << old_peer_address.ToString() << " to " |
| 1411 << peer_address_.ToString() << ", migrating connection."; | 1415 << peer_address_.ToString() << ", migrating connection."; |
| 1412 | 1416 |
| 1413 visitor_->OnConnectionMigration(); | 1417 visitor_->OnConnectionMigration(); |
| 1414 DCHECK_NE(type, NO_CHANGE); | 1418 DCHECK_NE(type, NO_CHANGE); |
| 1415 sent_packet_manager_.OnConnectionMigration(type); | 1419 sent_packet_manager_.OnConnectionMigration(type); |
| 1416 } | 1420 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1616 << ", encrypted length:" << encrypted->length(); | 1620 << ", encrypted length:" << encrypted->length(); |
| 1617 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl | 1621 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl |
| 1618 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); | 1622 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
| 1619 | 1623 |
| 1620 // Measure the RTT from before the write begins to avoid underestimating the | 1624 // Measure the RTT from before the write begins to avoid underestimating the |
| 1621 // min_rtt_, especially in cases where the thread blocks or gets swapped out | 1625 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
| 1622 // during the WritePacket below. | 1626 // during the WritePacket below. |
| 1623 QuicTime packet_send_time = clock_->Now(); | 1627 QuicTime packet_send_time = clock_->Now(); |
| 1624 WriteResult result = | 1628 WriteResult result = |
| 1625 writer_->WritePacket(encrypted->data(), encrypted->length(), | 1629 writer_->WritePacket(encrypted->data(), encrypted->length(), |
| 1626 self_address().address(), peer_address()); | 1630 self_address().address_number(), peer_address()); |
| 1627 if (result.error_code == ERR_IO_PENDING) { | 1631 if (result.error_code == ERR_IO_PENDING) { |
| 1628 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1632 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
| 1629 } | 1633 } |
| 1630 | 1634 |
| 1631 if (result.status == WRITE_STATUS_BLOCKED) { | 1635 if (result.status == WRITE_STATUS_BLOCKED) { |
| 1632 visitor_->OnWriteBlocked(); | 1636 visitor_->OnWriteBlocked(); |
| 1633 // If the socket buffers the the data, then the packet should not | 1637 // If the socket buffers the the data, then the packet should not |
| 1634 // be queued and sent again, which would result in an unnecessary | 1638 // be queued and sent again, which would result in an unnecessary |
| 1635 // duplicate packet being sent. The helper must call OnCanWrite | 1639 // duplicate packet being sent. The helper must call OnCanWrite |
| 1636 // when the write completes, and OnWriteError if an error occurs. | 1640 // when the write completes, and OnWriteError if an error occurs. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 ++stats_.packets_sent; | 1681 ++stats_.packets_sent; |
| 1678 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1682 if (packet->transmission_type != NOT_RETRANSMISSION) { |
| 1679 stats_.bytes_retransmitted += result.bytes_written; | 1683 stats_.bytes_retransmitted += result.bytes_written; |
| 1680 ++stats_.packets_retransmitted; | 1684 ++stats_.packets_retransmitted; |
| 1681 } | 1685 } |
| 1682 | 1686 |
| 1683 if (result.status == WRITE_STATUS_ERROR) { | 1687 if (result.status == WRITE_STATUS_ERROR) { |
| 1684 OnWriteError(result.error_code); | 1688 OnWriteError(result.error_code); |
| 1685 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() | 1689 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() |
| 1686 << " bytes " | 1690 << " bytes " |
| 1687 << " from host " << (self_address().address().empty() | 1691 << " from host " << (self_address().address_number().empty() |
| 1688 ? " empty address " | 1692 ? " empty address " |
| 1689 : self_address().ToStringWithoutPort()) | 1693 : self_address().ToStringWithoutPort()) |
| 1690 << " to address " << peer_address().ToString(); | 1694 << " to address " << peer_address().ToString(); |
| 1691 return false; | 1695 return false; |
| 1692 } | 1696 } |
| 1693 | 1697 |
| 1694 return true; | 1698 return true; |
| 1695 } | 1699 } |
| 1696 | 1700 |
| 1697 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { | 1701 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 } | 2356 } |
| 2353 return false; | 2357 return false; |
| 2354 } | 2358 } |
| 2355 | 2359 |
| 2356 void QuicConnection::SetMtuDiscoveryTarget(QuicByteCount target) { | 2360 void QuicConnection::SetMtuDiscoveryTarget(QuicByteCount target) { |
| 2357 mtu_discovery_target_ = LimitMaxPacketSize(target); | 2361 mtu_discovery_target_ = LimitMaxPacketSize(target); |
| 2358 } | 2362 } |
| 2359 | 2363 |
| 2360 QuicByteCount QuicConnection::LimitMaxPacketSize( | 2364 QuicByteCount QuicConnection::LimitMaxPacketSize( |
| 2361 QuicByteCount suggested_max_packet_size) { | 2365 QuicByteCount suggested_max_packet_size) { |
| 2362 if (peer_address_.address().empty()) { | 2366 if (peer_address_.address_number().empty()) { |
| 2363 LOG(DFATAL) << "Attempted to use a connection without a valid peer address"; | 2367 LOG(DFATAL) << "Attempted to use a connection without a valid peer address"; |
| 2364 return suggested_max_packet_size; | 2368 return suggested_max_packet_size; |
| 2365 } | 2369 } |
| 2366 | 2370 |
| 2367 const QuicByteCount writer_limit = writer_->GetMaxPacketSize(peer_address()); | 2371 const QuicByteCount writer_limit = writer_->GetMaxPacketSize(peer_address()); |
| 2368 | 2372 |
| 2369 QuicByteCount max_packet_size = suggested_max_packet_size; | 2373 QuicByteCount max_packet_size = suggested_max_packet_size; |
| 2370 if (max_packet_size > writer_limit) { | 2374 if (max_packet_size > writer_limit) { |
| 2371 max_packet_size = writer_limit; | 2375 max_packet_size = writer_limit; |
| 2372 } | 2376 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2413 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2417 SendMtuDiscoveryPacket(mtu_discovery_target_); |
| 2414 | 2418 |
| 2415 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2419 DCHECK(!mtu_discovery_alarm_->IsSet()); |
| 2416 } | 2420 } |
| 2417 | 2421 |
| 2418 bool QuicConnection::ack_frame_updated() const { | 2422 bool QuicConnection::ack_frame_updated() const { |
| 2419 return received_packet_manager_.ack_frame_updated(); | 2423 return received_packet_manager_.ack_frame_updated(); |
| 2420 } | 2424 } |
| 2421 | 2425 |
| 2422 } // namespace net | 2426 } // namespace net |
| OLD | NEW |