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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1255 self_port_changed_ = false; | 1255 self_port_changed_ = false; |
1256 | 1256 |
1257 if (peer_address_.address().empty()) { | 1257 if (peer_address_.address().empty()) { |
1258 peer_address_ = peer_address; | 1258 peer_address_ = peer_address; |
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_ = |
1266 (peer_address.address().bytes() != peer_address_.address().bytes()); | |
eroman
2016/01/13 23:19:42
note that IPAddress already defines operator==. I
martijnc
2016/01/14 22:48:17
Done.
| |
1266 peer_port_changed_ = (peer_address.port() != peer_address_.port()); | 1267 peer_port_changed_ = (peer_address.port() != peer_address_.port()); |
1267 | 1268 |
1268 // Store in case we want to migrate connection in ProcessValidatedPacket. | 1269 // Store in case we want to migrate connection in ProcessValidatedPacket. |
1269 migrating_peer_ip_ = peer_address.address(); | 1270 migrating_peer_ip_ = peer_address.address().bytes(); |
1270 migrating_peer_port_ = peer_address.port(); | 1271 migrating_peer_port_ = peer_address.port(); |
1271 } | 1272 } |
1272 | 1273 |
1273 if (!self_address.address().empty() && !self_address_.address().empty()) { | 1274 if (!self_address.address().empty() && !self_address_.address().empty()) { |
1274 self_ip_changed_ = (self_address.address() != self_address_.address()); | 1275 self_ip_changed_ = |
1276 (self_address.address().bytes() != self_address_.address().bytes()); | |
1275 self_port_changed_ = (self_address.port() != self_address_.port()); | 1277 self_port_changed_ = (self_address.port() != self_address_.port()); |
1276 } | 1278 } |
1277 | 1279 |
1278 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever | 1280 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever |
1279 // the connection is migrated, it usually ends up being on a different path, | 1281 // the connection is migrated, it usually ends up being on a different path, |
1280 // with possibly smaller MTU. This means the max packet size has to be reset | 1282 // with possibly smaller MTU. This means the max packet size has to be reset |
1281 // and MTU discovery mechanism re-initialized. The main reason the code does | 1283 // and MTU discovery mechanism re-initialized. The main reason the code does |
1282 // not do it now is that the retransmission code currently cannot deal with | 1284 // not do it now is that the retransmission code currently cannot deal with |
1283 // the case when it needs to resend a packet created with larger MTU (see | 1285 // the case when it needs to resend a packet created with larger MTU (see |
1284 // b/22172803). | 1286 // b/22172803). |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1388 debug_visitor_->OnSuccessfulVersionNegotiation(version()); | 1390 debug_visitor_->OnSuccessfulVersionNegotiation(version()); |
1389 } | 1391 } |
1390 } | 1392 } |
1391 } | 1393 } |
1392 | 1394 |
1393 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); | 1395 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); |
1394 | 1396 |
1395 if (peer_ip_changed_ || peer_port_changed_) { | 1397 if (peer_ip_changed_ || peer_port_changed_) { |
1396 IPEndPoint old_peer_address = peer_address_; | 1398 IPEndPoint old_peer_address = peer_address_; |
1397 peer_address_ = IPEndPoint( | 1399 peer_address_ = IPEndPoint( |
1398 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(), | 1400 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address().bytes(), |
1399 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); | 1401 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); |
1400 | 1402 |
1401 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " | 1403 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " |
1402 << old_peer_address.ToString() << " to " | 1404 << old_peer_address.ToString() << " to " |
1403 << peer_address_.ToString() << ", migrating connection."; | 1405 << peer_address_.ToString() << ", migrating connection."; |
1404 | 1406 |
1405 visitor_->OnConnectionMigration(); | 1407 visitor_->OnConnectionMigration(); |
1406 DCHECK_NE(type, NO_CHANGE); | 1408 DCHECK_NE(type, NO_CHANGE); |
1407 sent_packet_manager_.OnConnectionMigration(type); | 1409 sent_packet_manager_.OnConnectionMigration(type); |
1408 } | 1410 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1608 << ", encrypted length:" << encrypted->length(); | 1610 << ", encrypted length:" << encrypted->length(); |
1609 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl | 1611 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl |
1610 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); | 1612 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
1611 | 1613 |
1612 // Measure the RTT from before the write begins to avoid underestimating the | 1614 // 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 | 1615 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
1614 // during the WritePacket below. | 1616 // during the WritePacket below. |
1615 QuicTime packet_send_time = clock_->Now(); | 1617 QuicTime packet_send_time = clock_->Now(); |
1616 WriteResult result = | 1618 WriteResult result = |
1617 writer_->WritePacket(encrypted->data(), encrypted->length(), | 1619 writer_->WritePacket(encrypted->data(), encrypted->length(), |
1618 self_address().address(), peer_address()); | 1620 self_address().address().bytes(), peer_address()); |
1619 if (result.error_code == ERR_IO_PENDING) { | 1621 if (result.error_code == ERR_IO_PENDING) { |
1620 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1622 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
1621 } | 1623 } |
1622 | 1624 |
1623 if (result.status == WRITE_STATUS_BLOCKED) { | 1625 if (result.status == WRITE_STATUS_BLOCKED) { |
1624 visitor_->OnWriteBlocked(); | 1626 visitor_->OnWriteBlocked(); |
1625 // If the socket buffers the the data, then the packet should not | 1627 // If the socket buffers the the data, then the packet should not |
1626 // be queued and sent again, which would result in an unnecessary | 1628 // be queued and sent again, which would result in an unnecessary |
1627 // duplicate packet being sent. The helper must call OnCanWrite | 1629 // duplicate packet being sent. The helper must call OnCanWrite |
1628 // when the write completes, and OnWriteError if an error occurs. | 1630 // when the write completes, and OnWriteError if an error occurs. |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2400 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2402 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2401 | 2403 |
2402 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2404 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2403 } | 2405 } |
2404 | 2406 |
2405 bool QuicConnection::ack_frame_updated() const { | 2407 bool QuicConnection::ack_frame_updated() const { |
2406 return received_packet_manager_.ack_frame_updated(); | 2408 return received_packet_manager_.ack_frame_updated(); |
2407 } | 2409 } |
2408 | 2410 |
2409 } // namespace net | 2411 } // namespace net |
OLD | NEW |