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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 visitor_->OnWriteBlocked(); | 1078 visitor_->OnWriteBlocked(); |
1079 return; | 1079 return; |
1080 } | 1080 } |
1081 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" | 1081 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {" |
1082 << QuicVersionVectorToString(framer_.supported_versions()) << "}"; | 1082 << QuicVersionVectorToString(framer_.supported_versions()) << "}"; |
1083 scoped_ptr<QuicEncryptedPacket> version_packet( | 1083 scoped_ptr<QuicEncryptedPacket> version_packet( |
1084 packet_generator_.SerializeVersionNegotiationPacket( | 1084 packet_generator_.SerializeVersionNegotiationPacket( |
1085 framer_.supported_versions())); | 1085 framer_.supported_versions())); |
1086 WriteResult result = | 1086 WriteResult result = |
1087 writer_->WritePacket(version_packet->data(), version_packet->length(), | 1087 writer_->WritePacket(version_packet->data(), version_packet->length(), |
1088 self_address().address(), peer_address()); | 1088 self_address().address().bytes(), peer_address()); |
1089 | 1089 |
1090 if (result.status == WRITE_STATUS_ERROR) { | 1090 if (result.status == WRITE_STATUS_ERROR) { |
1091 OnWriteError(result.error_code); | 1091 OnWriteError(result.error_code); |
1092 return; | 1092 return; |
1093 } | 1093 } |
1094 if (result.status == WRITE_STATUS_BLOCKED) { | 1094 if (result.status == WRITE_STATUS_BLOCKED) { |
1095 visitor_->OnWriteBlocked(); | 1095 visitor_->OnWriteBlocked(); |
1096 if (writer_->IsWriteBlockedDataBuffered()) { | 1096 if (writer_->IsWriteBlockedDataBuffered()) { |
1097 pending_version_negotiation_packet_ = false; | 1097 pending_version_negotiation_packet_ = false; |
1098 } | 1098 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 } | 1259 } |
1260 if (self_address_.address().empty()) { | 1260 if (self_address_.address().empty()) { |
1261 self_address_ = self_address; | 1261 self_address_ = self_address; |
1262 } | 1262 } |
1263 | 1263 |
1264 if (!peer_address.address().empty() && !peer_address_.address().empty()) { | 1264 if (!peer_address.address().empty() && !peer_address_.address().empty()) { |
1265 peer_ip_changed_ = (peer_address.address() != peer_address_.address()); | 1265 peer_ip_changed_ = (peer_address.address() != peer_address_.address()); |
1266 peer_port_changed_ = (peer_address.port() != peer_address_.port()); | 1266 peer_port_changed_ = (peer_address.port() != peer_address_.port()); |
1267 | 1267 |
1268 // Store in case we want to migrate connection in ProcessValidatedPacket. | 1268 // Store in case we want to migrate connection in ProcessValidatedPacket. |
1269 migrating_peer_ip_ = peer_address.address(); | 1269 migrating_peer_ip_ = peer_address.address().bytes(); |
1270 migrating_peer_port_ = peer_address.port(); | 1270 migrating_peer_port_ = peer_address.port(); |
1271 } | 1271 } |
1272 | 1272 |
1273 if (!self_address.address().empty() && !self_address_.address().empty()) { | 1273 if (!self_address.address().empty() && !self_address_.address().empty()) { |
1274 self_ip_changed_ = (self_address.address() != self_address_.address()); | 1274 self_ip_changed_ = (self_address.address() != self_address_.address()); |
1275 self_port_changed_ = (self_address.port() != self_address_.port()); | 1275 self_port_changed_ = (self_address.port() != self_address_.port()); |
1276 } | 1276 } |
1277 | 1277 |
1278 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever | 1278 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever |
1279 // the connection is migrated, it usually ends up being on a different path, | 1279 // 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... |
1388 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 1388 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
1389 } | 1389 } |
1390 } | 1390 } |
1391 } | 1391 } |
1392 | 1392 |
1393 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); | 1393 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); |
1394 | 1394 |
1395 if (peer_ip_changed_ || peer_port_changed_) { | 1395 if (peer_ip_changed_ || peer_port_changed_) { |
1396 IPEndPoint old_peer_address = peer_address_; | 1396 IPEndPoint old_peer_address = peer_address_; |
1397 peer_address_ = IPEndPoint( | 1397 peer_address_ = IPEndPoint( |
1398 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(), | 1398 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address().bytes(), |
1399 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); | 1399 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); |
1400 | 1400 |
1401 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " | 1401 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " |
1402 << old_peer_address.ToString() << " to " | 1402 << old_peer_address.ToString() << " to " |
1403 << peer_address_.ToString() << ", migrating connection."; | 1403 << peer_address_.ToString() << ", migrating connection."; |
1404 | 1404 |
1405 visitor_->OnConnectionMigration(); | 1405 visitor_->OnConnectionMigration(); |
1406 DCHECK_NE(type, NO_CHANGE); | 1406 DCHECK_NE(type, NO_CHANGE); |
1407 sent_packet_manager_.OnConnectionMigration(type); | 1407 sent_packet_manager_.OnConnectionMigration(type); |
1408 } | 1408 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 << ", encrypted length:" << encrypted->length(); | 1608 << ", encrypted length:" << encrypted->length(); |
1609 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl | 1609 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl |
1610 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); | 1610 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
1611 | 1611 |
1612 // Measure the RTT from before the write begins to avoid underestimating the | 1612 // Measure the RTT from before the write begins to avoid underestimating the |
1613 // min_rtt_, especially in cases where the thread blocks or gets swapped out | 1613 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
1614 // during the WritePacket below. | 1614 // during the WritePacket below. |
1615 QuicTime packet_send_time = clock_->Now(); | 1615 QuicTime packet_send_time = clock_->Now(); |
1616 WriteResult result = | 1616 WriteResult result = |
1617 writer_->WritePacket(encrypted->data(), encrypted->length(), | 1617 writer_->WritePacket(encrypted->data(), encrypted->length(), |
1618 self_address().address(), peer_address()); | 1618 self_address().address().bytes(), peer_address()); |
1619 if (result.error_code == ERR_IO_PENDING) { | 1619 if (result.error_code == ERR_IO_PENDING) { |
1620 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1620 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
1621 } | 1621 } |
1622 | 1622 |
1623 if (result.status == WRITE_STATUS_BLOCKED) { | 1623 if (result.status == WRITE_STATUS_BLOCKED) { |
1624 visitor_->OnWriteBlocked(); | 1624 visitor_->OnWriteBlocked(); |
1625 // If the socket buffers the the data, then the packet should not | 1625 // If the socket buffers the the data, then the packet should not |
1626 // be queued and sent again, which would result in an unnecessary | 1626 // be queued and sent again, which would result in an unnecessary |
1627 // duplicate packet being sent. The helper must call OnCanWrite | 1627 // duplicate packet being sent. The helper must call OnCanWrite |
1628 // when the write completes, and OnWriteError if an error occurs. | 1628 // when the write completes, and OnWriteError if an error occurs. |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2403 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2404 | 2404 |
2405 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2405 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2406 } | 2406 } |
2407 | 2407 |
2408 bool QuicConnection::ack_frame_updated() const { | 2408 bool QuicConnection::ack_frame_updated() const { |
2409 return received_packet_manager_.ack_frame_updated(); | 2409 return received_packet_manager_.ack_frame_updated(); |
2410 } | 2410 } |
2411 | 2411 |
2412 } // namespace net | 2412 } // namespace net |
OLD | NEW |