| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 230 } |
| 231 | 231 |
| 232 QuicConnection* connection_; | 232 QuicConnection* connection_; |
| 233 QuicByteCount probe_size_; | 233 QuicByteCount probe_size_; |
| 234 | 234 |
| 235 DISALLOW_COPY_AND_ASSIGN(MtuDiscoveryAckListener); | 235 DISALLOW_COPY_AND_ASSIGN(MtuDiscoveryAckListener); |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 } // namespace | 238 } // namespace |
| 239 | 239 |
| 240 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet, | 240 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet) |
| 241 EncryptionLevel level) | |
| 242 : serialized_packet(packet), | 241 : serialized_packet(packet), |
| 243 encryption_level(level), | |
| 244 transmission_type(NOT_RETRANSMISSION), | 242 transmission_type(NOT_RETRANSMISSION), |
| 245 original_packet_number(0) {} | 243 original_packet_number(0) {} |
| 246 | 244 |
| 247 QuicConnection::QueuedPacket::QueuedPacket( | 245 QuicConnection::QueuedPacket::QueuedPacket( |
| 248 SerializedPacket packet, | 246 SerializedPacket packet, |
| 249 EncryptionLevel level, | |
| 250 TransmissionType transmission_type, | 247 TransmissionType transmission_type, |
| 251 QuicPacketNumber original_packet_number) | 248 QuicPacketNumber original_packet_number) |
| 252 : serialized_packet(packet), | 249 : serialized_packet(packet), |
| 253 encryption_level(level), | |
| 254 transmission_type(transmission_type), | 250 transmission_type(transmission_type), |
| 255 original_packet_number(original_packet_number) {} | 251 original_packet_number(original_packet_number) {} |
| 256 | 252 |
| 257 #define ENDPOINT \ | 253 #define ENDPOINT \ |
| 258 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") | 254 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") |
| 259 | 255 |
| 260 QuicConnection::QuicConnection(QuicConnectionId connection_id, | 256 QuicConnection::QuicConnection(QuicConnectionId connection_id, |
| 261 IPEndPoint address, | 257 IPEndPoint address, |
| 262 QuicConnectionHelperInterface* helper, | 258 QuicConnectionHelperInterface* helper, |
| 263 const PacketWriterFactory& writer_factory, | 259 const PacketWriterFactory& writer_factory, |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 kMaxPacketSize); | 1458 kMaxPacketSize); |
| 1463 if (serialized_packet.packet == nullptr) { | 1459 if (serialized_packet.packet == nullptr) { |
| 1464 // We failed to serialize the packet, so close the connection. | 1460 // We failed to serialize the packet, so close the connection. |
| 1465 // CloseConnection does not send close packet, so no infinite loop here. | 1461 // CloseConnection does not send close packet, so no infinite loop here. |
| 1466 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1462 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
| 1467 return; | 1463 return; |
| 1468 } | 1464 } |
| 1469 | 1465 |
| 1470 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.packet_number << " as " | 1466 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.packet_number << " as " |
| 1471 << serialized_packet.packet_number; | 1467 << serialized_packet.packet_number; |
| 1472 SendOrQueuePacket(QueuedPacket( | 1468 SendOrQueuePacket(QueuedPacket(serialized_packet, pending.transmission_type, |
| 1473 serialized_packet, pending.retransmittable_frames.encryption_level(), | 1469 pending.packet_number)); |
| 1474 pending.transmission_type, pending.packet_number)); | |
| 1475 } | 1470 } |
| 1476 } | 1471 } |
| 1477 | 1472 |
| 1478 void QuicConnection::RetransmitUnackedPackets( | 1473 void QuicConnection::RetransmitUnackedPackets( |
| 1479 TransmissionType retransmission_type) { | 1474 TransmissionType retransmission_type) { |
| 1480 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type); | 1475 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type); |
| 1481 | 1476 |
| 1482 WriteIfNotBlocked(); | 1477 WriteIfNotBlocked(); |
| 1483 } | 1478 } |
| 1484 | 1479 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 | 1585 |
| 1591 DCHECK_LE(encrypted->length(), kMaxPacketSize); | 1586 DCHECK_LE(encrypted->length(), kMaxPacketSize); |
| 1592 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); | 1587 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); |
| 1593 DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : " | 1588 DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : " |
| 1594 << (packet->serialized_packet.is_fec_packet | 1589 << (packet->serialized_packet.is_fec_packet |
| 1595 ? "FEC " | 1590 ? "FEC " |
| 1596 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA | 1591 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA |
| 1597 ? "data bearing " | 1592 ? "data bearing " |
| 1598 : " ack only ")) | 1593 : " ack only ")) |
| 1599 << ", encryption level: " | 1594 << ", encryption level: " |
| 1600 << QuicUtils::EncryptionLevelToString(packet->encryption_level) | 1595 << QuicUtils::EncryptionLevelToString( |
| 1596 packet->serialized_packet.encryption_level) |
| 1601 << ", encrypted length:" << encrypted->length(); | 1597 << ", encrypted length:" << encrypted->length(); |
| 1602 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl | 1598 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl |
| 1603 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); | 1599 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
| 1604 | 1600 |
| 1605 // Measure the RTT from before the write begins to avoid underestimating the | 1601 // Measure the RTT from before the write begins to avoid underestimating the |
| 1606 // min_rtt_, especially in cases where the thread blocks or gets swapped out | 1602 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
| 1607 // during the WritePacket below. | 1603 // during the WritePacket below. |
| 1608 QuicTime packet_send_time = clock_->Now(); | 1604 QuicTime packet_send_time = clock_->Now(); |
| 1609 WriteResult result = writer_->WritePacket(encrypted->data(), | 1605 WriteResult result = writer_->WritePacket(encrypted->data(), |
| 1610 encrypted->length(), | 1606 encrypted->length(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1621 // duplicate packet being sent. The helper must call OnCanWrite | 1617 // duplicate packet being sent. The helper must call OnCanWrite |
| 1622 // when the write completes, and OnWriteError if an error occurs. | 1618 // when the write completes, and OnWriteError if an error occurs. |
| 1623 if (!writer_->IsWriteBlockedDataBuffered()) { | 1619 if (!writer_->IsWriteBlockedDataBuffered()) { |
| 1624 return false; | 1620 return false; |
| 1625 } | 1621 } |
| 1626 } | 1622 } |
| 1627 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { | 1623 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { |
| 1628 // Pass the write result to the visitor. | 1624 // Pass the write result to the visitor. |
| 1629 debug_visitor_->OnPacketSent( | 1625 debug_visitor_->OnPacketSent( |
| 1630 packet->serialized_packet, packet->original_packet_number, | 1626 packet->serialized_packet, packet->original_packet_number, |
| 1631 packet->encryption_level, packet->transmission_type, | 1627 packet->transmission_type, encrypted->length(), packet_send_time); |
| 1632 encrypted->length(), packet_send_time); | |
| 1633 } | 1628 } |
| 1634 if (packet->transmission_type == NOT_RETRANSMISSION) { | 1629 if (packet->transmission_type == NOT_RETRANSMISSION) { |
| 1635 time_of_last_sent_new_packet_ = packet_send_time; | 1630 time_of_last_sent_new_packet_ = packet_send_time; |
| 1636 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && | 1631 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && |
| 1637 last_send_for_timeout_ <= time_of_last_received_packet_) { | 1632 last_send_for_timeout_ <= time_of_last_received_packet_) { |
| 1638 last_send_for_timeout_ = packet_send_time; | 1633 last_send_for_timeout_ = packet_send_time; |
| 1639 } | 1634 } |
| 1640 } | 1635 } |
| 1641 SetPingAlarm(); | 1636 SetPingAlarm(); |
| 1642 MaybeSetFecAlarm(packet_number); | 1637 MaybeSetFecAlarm(packet_number); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 | 1678 |
| 1684 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { | 1679 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { |
| 1685 if (!connected_) { | 1680 if (!connected_) { |
| 1686 DVLOG(1) << ENDPOINT | 1681 DVLOG(1) << ENDPOINT |
| 1687 << "Not sending packet as connection is disconnected."; | 1682 << "Not sending packet as connection is disconnected."; |
| 1688 return true; | 1683 return true; |
| 1689 } | 1684 } |
| 1690 | 1685 |
| 1691 QuicPacketNumber packet_number = packet.serialized_packet.packet_number; | 1686 QuicPacketNumber packet_number = packet.serialized_packet.packet_number; |
| 1692 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE && | 1687 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE && |
| 1693 packet.encryption_level == ENCRYPTION_NONE) { | 1688 packet.serialized_packet.encryption_level == ENCRYPTION_NONE) { |
| 1694 // Drop packets that are NULL encrypted since the peer won't accept them | 1689 // Drop packets that are NULL encrypted since the peer won't accept them |
| 1695 // anymore. | 1690 // anymore. |
| 1696 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " << packet_number | 1691 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " << packet_number |
| 1697 << " since the connection is forward secure."; | 1692 << " since the connection is forward secure."; |
| 1698 return true; | 1693 return true; |
| 1699 } | 1694 } |
| 1700 | 1695 |
| 1701 // If a retransmission has been acked before sending, don't send it. | 1696 // If a retransmission has been acked before sending, don't send it. |
| 1702 // This occurs if a packet gets serialized, queued, then discarded. | 1697 // This occurs if a packet gets serialized, queued, then discarded. |
| 1703 if (packet.transmission_type != NOT_RETRANSMISSION && | 1698 if (packet.transmission_type != NOT_RETRANSMISSION && |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1724 if (serialized_packet.packet == nullptr) { | 1719 if (serialized_packet.packet == nullptr) { |
| 1725 // We failed to serialize the packet, so close the connection. | 1720 // We failed to serialize the packet, so close the connection. |
| 1726 // CloseConnection does not send close packet, so no infinite loop here. | 1721 // CloseConnection does not send close packet, so no infinite loop here. |
| 1727 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1722 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
| 1728 return; | 1723 return; |
| 1729 } | 1724 } |
| 1730 if (serialized_packet.is_fec_packet && fec_alarm_->IsSet()) { | 1725 if (serialized_packet.is_fec_packet && fec_alarm_->IsSet()) { |
| 1731 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. | 1726 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. |
| 1732 fec_alarm_->Cancel(); | 1727 fec_alarm_->Cancel(); |
| 1733 } | 1728 } |
| 1734 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); | 1729 SendOrQueuePacket(QueuedPacket(serialized_packet)); |
| 1735 } | 1730 } |
| 1736 | 1731 |
| 1737 void QuicConnection::OnResetFecGroup() { | 1732 void QuicConnection::OnResetFecGroup() { |
| 1738 if (!fec_alarm_->IsSet()) { | 1733 if (!fec_alarm_->IsSet()) { |
| 1739 return; | 1734 return; |
| 1740 } | 1735 } |
| 1741 // If an FEC Group is closed with the FEC alarm set, cancel the alarm. | 1736 // If an FEC Group is closed with the FEC alarm set, cancel the alarm. |
| 1742 fec_alarm_->Cancel(); | 1737 fec_alarm_->Cancel(); |
| 1743 } | 1738 } |
| 1744 | 1739 |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2388 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; | 2383 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; |
| 2389 ++mtu_probe_count_; | 2384 ++mtu_probe_count_; |
| 2390 | 2385 |
| 2391 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; | 2386 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; |
| 2392 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2387 SendMtuDiscoveryPacket(mtu_discovery_target_); |
| 2393 | 2388 |
| 2394 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2389 DCHECK(!mtu_discovery_alarm_->IsSet()); |
| 2395 } | 2390 } |
| 2396 | 2391 |
| 2397 } // namespace net | 2392 } // namespace net |
| OLD | NEW |