| 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 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 visitor_->OnWriteBlocked(); | 1105 visitor_->OnWriteBlocked(); |
| 1106 return; | 1106 return; |
| 1107 } | 1107 } |
| 1108 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" | 1108 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" |
| 1109 << QuicVersionVectorToString(framer_.supported_versions()) << "}"; | 1109 << QuicVersionVectorToString(framer_.supported_versions()) << "}"; |
| 1110 scoped_ptr<QuicEncryptedPacket> version_packet( | 1110 scoped_ptr<QuicEncryptedPacket> version_packet( |
| 1111 packet_generator_.SerializeVersionNegotiationPacket( | 1111 packet_generator_.SerializeVersionNegotiationPacket( |
| 1112 framer_.supported_versions())); | 1112 framer_.supported_versions())); |
| 1113 WriteResult result = | 1113 WriteResult result = |
| 1114 writer_->WritePacket(version_packet->data(), version_packet->length(), | 1114 writer_->WritePacket(version_packet->data(), version_packet->length(), |
| 1115 self_address().address(), peer_address()); | 1115 self_address().address().bytes(), peer_address()); |
| 1116 | 1116 |
| 1117 if (result.status == WRITE_STATUS_ERROR) { | 1117 if (result.status == WRITE_STATUS_ERROR) { |
| 1118 OnWriteError(result.error_code); | 1118 OnWriteError(result.error_code); |
| 1119 return; | 1119 return; |
| 1120 } | 1120 } |
| 1121 if (result.status == WRITE_STATUS_BLOCKED) { | 1121 if (result.status == WRITE_STATUS_BLOCKED) { |
| 1122 visitor_->OnWriteBlocked(); | 1122 visitor_->OnWriteBlocked(); |
| 1123 if (writer_->IsWriteBlockedDataBuffered()) { | 1123 if (writer_->IsWriteBlockedDataBuffered()) { |
| 1124 pending_version_negotiation_packet_ = false; | 1124 pending_version_negotiation_packet_ = false; |
| 1125 } | 1125 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 } | 1293 } |
| 1294 if (self_address_.address().empty()) { | 1294 if (self_address_.address().empty()) { |
| 1295 self_address_ = self_address; | 1295 self_address_ = self_address; |
| 1296 } | 1296 } |
| 1297 | 1297 |
| 1298 if (!peer_address.address().empty() && !peer_address_.address().empty()) { | 1298 if (!peer_address.address().empty() && !peer_address_.address().empty()) { |
| 1299 peer_ip_changed_ = (peer_address.address() != peer_address_.address()); | 1299 peer_ip_changed_ = (peer_address.address() != peer_address_.address()); |
| 1300 peer_port_changed_ = (peer_address.port() != peer_address_.port()); | 1300 peer_port_changed_ = (peer_address.port() != peer_address_.port()); |
| 1301 | 1301 |
| 1302 // Store in case we want to migrate connection in ProcessValidatedPacket. | 1302 // Store in case we want to migrate connection in ProcessValidatedPacket. |
| 1303 migrating_peer_ip_ = peer_address.address(); | 1303 migrating_peer_ip_ = peer_address.address().bytes(); |
| 1304 migrating_peer_port_ = peer_address.port(); | 1304 migrating_peer_port_ = peer_address.port(); |
| 1305 } | 1305 } |
| 1306 | 1306 |
| 1307 if (!self_address.address().empty() && !self_address_.address().empty()) { | 1307 if (!self_address.address().empty() && !self_address_.address().empty()) { |
| 1308 self_ip_changed_ = (self_address.address() != self_address_.address()); | 1308 self_ip_changed_ = (self_address.address() != self_address_.address()); |
| 1309 self_port_changed_ = (self_address.port() != self_address_.port()); | 1309 self_port_changed_ = (self_address.port() != self_address_.port()); |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever | 1312 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever |
| 1313 // the connection is migrated, it usually ends up being on a different path, | 1313 // the connection is migrated, it usually ends up being on a different path, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 1422 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
| 1423 } | 1423 } |
| 1424 } | 1424 } |
| 1425 } | 1425 } |
| 1426 | 1426 |
| 1427 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); | 1427 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); |
| 1428 | 1428 |
| 1429 if (peer_ip_changed_ || peer_port_changed_) { | 1429 if (peer_ip_changed_ || peer_port_changed_) { |
| 1430 IPEndPoint old_peer_address = peer_address_; | 1430 IPEndPoint old_peer_address = peer_address_; |
| 1431 peer_address_ = IPEndPoint( | 1431 peer_address_ = IPEndPoint( |
| 1432 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(), | 1432 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address().bytes(), |
| 1433 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); | 1433 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); |
| 1434 | 1434 |
| 1435 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " | 1435 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " |
| 1436 << old_peer_address.ToString() << " to " | 1436 << old_peer_address.ToString() << " to " |
| 1437 << peer_address_.ToString() << ", migrating connection."; | 1437 << peer_address_.ToString() << ", migrating connection."; |
| 1438 | 1438 |
| 1439 visitor_->OnConnectionMigration(); | 1439 visitor_->OnConnectionMigration(); |
| 1440 DCHECK_NE(type, NO_CHANGE); | 1440 DCHECK_NE(type, NO_CHANGE); |
| 1441 sent_packet_manager_.OnConnectionMigration(type); | 1441 sent_packet_manager_.OnConnectionMigration(type); |
| 1442 } | 1442 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 << ", encrypted length:" << encrypted->length(); | 1641 << ", encrypted length:" << encrypted->length(); |
| 1642 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl | 1642 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl |
| 1643 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); | 1643 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
| 1644 | 1644 |
| 1645 // Measure the RTT from before the write begins to avoid underestimating the | 1645 // Measure the RTT from before the write begins to avoid underestimating the |
| 1646 // min_rtt_, especially in cases where the thread blocks or gets swapped out | 1646 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
| 1647 // during the WritePacket below. | 1647 // during the WritePacket below. |
| 1648 QuicTime packet_send_time = clock_->Now(); | 1648 QuicTime packet_send_time = clock_->Now(); |
| 1649 WriteResult result = | 1649 WriteResult result = |
| 1650 writer_->WritePacket(encrypted->data(), encrypted->length(), | 1650 writer_->WritePacket(encrypted->data(), encrypted->length(), |
| 1651 self_address().address(), peer_address()); | 1651 self_address().address().bytes(), peer_address()); |
| 1652 if (result.error_code == ERR_IO_PENDING) { | 1652 if (result.error_code == ERR_IO_PENDING) { |
| 1653 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1653 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 if (result.status == WRITE_STATUS_BLOCKED) { | 1656 if (result.status == WRITE_STATUS_BLOCKED) { |
| 1657 visitor_->OnWriteBlocked(); | 1657 visitor_->OnWriteBlocked(); |
| 1658 // If the socket buffers the the data, then the packet should not | 1658 // If the socket buffers the the data, then the packet should not |
| 1659 // be queued and sent again, which would result in an unnecessary | 1659 // be queued and sent again, which would result in an unnecessary |
| 1660 // duplicate packet being sent. The helper must call OnCanWrite | 1660 // duplicate packet being sent. The helper must call OnCanWrite |
| 1661 // when the write completes, and OnWriteError if an error occurs. | 1661 // when the write completes, and OnWriteError if an error occurs. |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2441 void QuicConnection::OnPathClosed(QuicPathId path_id) { | 2441 void QuicConnection::OnPathClosed(QuicPathId path_id) { |
| 2442 // Stop receiving packets on this path. | 2442 // Stop receiving packets on this path. |
| 2443 framer_.OnPathClosed(path_id); | 2443 framer_.OnPathClosed(path_id); |
| 2444 } | 2444 } |
| 2445 | 2445 |
| 2446 bool QuicConnection::ack_frame_updated() const { | 2446 bool QuicConnection::ack_frame_updated() const { |
| 2447 return received_packet_manager_.ack_frame_updated(); | 2447 return received_packet_manager_.ack_frame_updated(); |
| 2448 } | 2448 } |
| 2449 | 2449 |
| 2450 } // namespace net | 2450 } // namespace net |
| OLD | NEW |