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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 224 } |
225 | 225 |
226 QuicConnection* connection_; | 226 QuicConnection* connection_; |
227 QuicByteCount probe_size_; | 227 QuicByteCount probe_size_; |
228 | 228 |
229 DISALLOW_COPY_AND_ASSIGN(MtuDiscoveryAckListener); | 229 DISALLOW_COPY_AND_ASSIGN(MtuDiscoveryAckListener); |
230 }; | 230 }; |
231 | 231 |
232 } // namespace | 232 } // namespace |
233 | 233 |
234 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet) | |
235 : serialized_packet(packet), | |
236 transmission_type(NOT_RETRANSMISSION), | |
237 original_packet_number(0) {} | |
238 | |
239 QuicConnection::QueuedPacket::QueuedPacket( | |
240 SerializedPacket packet, | |
241 TransmissionType transmission_type, | |
242 QuicPacketNumber original_packet_number) | |
243 : serialized_packet(packet), | |
244 transmission_type(transmission_type), | |
245 original_packet_number(original_packet_number) {} | |
246 | |
247 #define ENDPOINT \ | 234 #define ENDPOINT \ |
248 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") | 235 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") |
249 | 236 |
250 QuicConnection::QuicConnection(QuicConnectionId connection_id, | 237 QuicConnection::QuicConnection(QuicConnectionId connection_id, |
251 IPEndPoint address, | 238 IPEndPoint address, |
252 QuicConnectionHelperInterface* helper, | 239 QuicConnectionHelperInterface* helper, |
253 const PacketWriterFactory& writer_factory, | 240 const PacketWriterFactory& writer_factory, |
254 bool owns_writer, | 241 bool owns_writer, |
255 Perspective perspective, | 242 Perspective perspective, |
256 const QuicVersionVector& supported_versions) | 243 const QuicVersionVector& supported_versions) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (termination_packets_.get() != nullptr) { | 339 if (termination_packets_.get() != nullptr) { |
353 STLDeleteElements(termination_packets_.get()); | 340 STLDeleteElements(termination_packets_.get()); |
354 } | 341 } |
355 STLDeleteValues(&group_map_); | 342 STLDeleteValues(&group_map_); |
356 ClearQueuedPackets(); | 343 ClearQueuedPackets(); |
357 } | 344 } |
358 | 345 |
359 void QuicConnection::ClearQueuedPackets() { | 346 void QuicConnection::ClearQueuedPackets() { |
360 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 347 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
361 it != queued_packets_.end(); ++it) { | 348 it != queued_packets_.end(); ++it) { |
362 delete it->serialized_packet.retransmittable_frames; | 349 delete it->retransmittable_frames; |
363 delete it->serialized_packet.packet; | 350 delete it->packet; |
364 } | 351 } |
365 queued_packets_.clear(); | 352 queued_packets_.clear(); |
366 } | 353 } |
367 | 354 |
368 void QuicConnection::SetFromConfig(const QuicConfig& config) { | 355 void QuicConnection::SetFromConfig(const QuicConfig& config) { |
369 if (config.negotiated()) { | 356 if (config.negotiated()) { |
370 SetNetworkTimeouts(QuicTime::Delta::Infinite(), | 357 SetNetworkTimeouts(QuicTime::Delta::Infinite(), |
371 config.IdleConnectionStateLifetime()); | 358 config.IdleConnectionStateLifetime()); |
372 if (config.SilentClose()) { | 359 if (config.SilentClose()) { |
373 silent_close_enabled_ = true; | 360 silent_close_enabled_ = true; |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 // All data for streams which are reset with QUIC_STREAM_NO_ERROR must | 1141 // All data for streams which are reset with QUIC_STREAM_NO_ERROR must |
1155 // be received by the peer. | 1142 // be received by the peer. |
1156 return; | 1143 return; |
1157 } | 1144 } |
1158 | 1145 |
1159 sent_packet_manager_.CancelRetransmissionsForStream(id); | 1146 sent_packet_manager_.CancelRetransmissionsForStream(id); |
1160 // Remove all queued packets which only contain data for the reset stream. | 1147 // Remove all queued packets which only contain data for the reset stream. |
1161 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); | 1148 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); |
1162 while (packet_iterator != queued_packets_.end()) { | 1149 while (packet_iterator != queued_packets_.end()) { |
1163 RetransmittableFrames* retransmittable_frames = | 1150 RetransmittableFrames* retransmittable_frames = |
1164 packet_iterator->serialized_packet.retransmittable_frames; | 1151 packet_iterator->retransmittable_frames; |
1165 if (!retransmittable_frames) { | 1152 if (!retransmittable_frames) { |
1166 ++packet_iterator; | 1153 ++packet_iterator; |
1167 continue; | 1154 continue; |
1168 } | 1155 } |
1169 retransmittable_frames->RemoveFramesForStream(id); | 1156 retransmittable_frames->RemoveFramesForStream(id); |
1170 if (!retransmittable_frames->frames().empty()) { | 1157 if (!retransmittable_frames->frames().empty()) { |
1171 ++packet_iterator; | 1158 ++packet_iterator; |
1172 continue; | 1159 continue; |
1173 } | 1160 } |
1174 delete packet_iterator->serialized_packet.retransmittable_frames; | 1161 delete packet_iterator->retransmittable_frames; |
1175 delete packet_iterator->serialized_packet.packet; | 1162 delete packet_iterator->packet; |
1176 packet_iterator->serialized_packet.retransmittable_frames = nullptr; | 1163 packet_iterator->retransmittable_frames = nullptr; |
1177 packet_iterator->serialized_packet.packet = nullptr; | 1164 packet_iterator->packet = nullptr; |
1178 packet_iterator = queued_packets_.erase(packet_iterator); | 1165 packet_iterator = queued_packets_.erase(packet_iterator); |
1179 } | 1166 } |
1180 } | 1167 } |
1181 | 1168 |
1182 void QuicConnection::SendWindowUpdate(QuicStreamId id, | 1169 void QuicConnection::SendWindowUpdate(QuicStreamId id, |
1183 QuicStreamOffset byte_offset) { | 1170 QuicStreamOffset byte_offset) { |
1184 // Opportunistically bundle an ack with this outgoing packet. | 1171 // Opportunistically bundle an ack with this outgoing packet. |
1185 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1172 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); |
1186 packet_generator_.AddControlFrame( | 1173 packet_generator_.AddControlFrame( |
1187 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); | 1174 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that | 1451 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that |
1465 // does not require the creator to be flushed. | 1452 // does not require the creator to be flushed. |
1466 packet_generator_.FlushAllQueuedFrames(); | 1453 packet_generator_.FlushAllQueuedFrames(); |
1467 char buffer[kMaxPacketSize]; | 1454 char buffer[kMaxPacketSize]; |
1468 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( | 1455 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( |
1469 pending.retransmittable_frames, pending.encryption_level, | 1456 pending.retransmittable_frames, pending.encryption_level, |
1470 pending.packet_number_length, buffer, kMaxPacketSize); | 1457 pending.packet_number_length, buffer, kMaxPacketSize); |
1471 if (serialized_packet.packet == nullptr) { | 1458 if (serialized_packet.packet == nullptr) { |
1472 // We failed to serialize the packet, so close the connection. | 1459 // We failed to serialize the packet, so close the connection. |
1473 // CloseConnection does not send close packet, so no infinite loop here. | 1460 // CloseConnection does not send close packet, so no infinite loop here. |
| 1461 // TODO(ianswett): This is actually an internal error, not an encryption |
| 1462 // failure. |
1474 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1463 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
1475 return; | 1464 return; |
1476 } | 1465 } |
1477 | 1466 |
1478 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.packet_number << " as " | 1467 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.packet_number << " as " |
1479 << serialized_packet.packet_number; | 1468 << serialized_packet.packet_number; |
1480 SendOrQueuePacket(QueuedPacket(serialized_packet, pending.transmission_type, | 1469 serialized_packet.original_packet_number = pending.packet_number; |
1481 pending.packet_number)); | 1470 serialized_packet.transmission_type = pending.transmission_type; |
| 1471 SendOrQueuePacket(&serialized_packet); |
1482 } | 1472 } |
1483 } | 1473 } |
1484 | 1474 |
1485 void QuicConnection::RetransmitUnackedPackets( | 1475 void QuicConnection::RetransmitUnackedPackets( |
1486 TransmissionType retransmission_type) { | 1476 TransmissionType retransmission_type) { |
1487 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type); | 1477 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type); |
1488 | 1478 |
1489 WriteIfNotBlocked(); | 1479 WriteIfNotBlocked(); |
1490 } | 1480 } |
1491 | 1481 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 DVLOG(1) << ENDPOINT << "Delaying sending " << delay.ToMilliseconds() | 1534 DVLOG(1) << ENDPOINT << "Delaying sending " << delay.ToMilliseconds() |
1545 << "ms"; | 1535 << "ms"; |
1546 return false; | 1536 return false; |
1547 } | 1537 } |
1548 if (!FLAGS_quic_respect_send_alarm2) { | 1538 if (!FLAGS_quic_respect_send_alarm2) { |
1549 send_alarm_->Cancel(); | 1539 send_alarm_->Cancel(); |
1550 } | 1540 } |
1551 return true; | 1541 return true; |
1552 } | 1542 } |
1553 | 1543 |
1554 bool QuicConnection::WritePacket(QueuedPacket* packet) { | 1544 bool QuicConnection::WritePacket(SerializedPacket* packet) { |
1555 if (!WritePacketInner(packet)) { | 1545 if (!WritePacketInner(packet)) { |
1556 return false; | 1546 return false; |
1557 } | 1547 } |
1558 delete packet->serialized_packet.retransmittable_frames; | 1548 delete packet->retransmittable_frames; |
1559 delete packet->serialized_packet.packet; | 1549 delete packet->packet; |
1560 packet->serialized_packet.retransmittable_frames = nullptr; | 1550 packet->retransmittable_frames = nullptr; |
1561 packet->serialized_packet.packet = nullptr; | 1551 packet->packet = nullptr; |
1562 return true; | 1552 return true; |
1563 } | 1553 } |
1564 | 1554 |
1565 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { | 1555 bool QuicConnection::WritePacketInner(SerializedPacket* packet) { |
1566 if (packet->serialized_packet.packet_number < | 1556 if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) { |
1567 sent_packet_manager_.largest_sent_packet()) { | 1557 LOG(DFATAL) << "Attempt to write packet:" << packet->packet_number |
1568 LOG(DFATAL) << "Attempt to write packet:" | |
1569 << packet->serialized_packet.packet_number | |
1570 << " after:" << sent_packet_manager_.largest_sent_packet(); | 1558 << " after:" << sent_packet_manager_.largest_sent_packet(); |
1571 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, | 1559 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, |
1572 "Packet written out of order."); | 1560 "Packet written out of order."); |
1573 return true; | 1561 return true; |
1574 } | 1562 } |
1575 if (ShouldDiscardPacket(*packet)) { | 1563 if (ShouldDiscardPacket(*packet)) { |
1576 ++stats_.packets_discarded; | 1564 ++stats_.packets_discarded; |
1577 return true; | 1565 return true; |
1578 } | 1566 } |
1579 // Termination packets are encrypted and saved, so don't exit early. | 1567 // Termination packets are encrypted and saved, so don't exit early. |
1580 const bool is_termination_packet = IsTerminationPacket(*packet); | 1568 const bool is_termination_packet = IsTerminationPacket(*packet); |
1581 if (writer_->IsWriteBlocked() && !is_termination_packet) { | 1569 if (writer_->IsWriteBlocked() && !is_termination_packet) { |
1582 return false; | 1570 return false; |
1583 } | 1571 } |
1584 | 1572 |
1585 QuicPacketNumber packet_number = packet->serialized_packet.packet_number; | 1573 QuicPacketNumber packet_number = packet->packet_number; |
1586 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); | 1574 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); |
1587 packet_number_of_last_sent_packet_ = packet_number; | 1575 packet_number_of_last_sent_packet_ = packet_number; |
1588 | 1576 |
1589 QuicEncryptedPacket* encrypted = packet->serialized_packet.packet; | 1577 QuicEncryptedPacket* encrypted = packet->packet; |
1590 // Termination packets are eventually owned by TimeWaitListManager. | 1578 // Termination packets are eventually owned by TimeWaitListManager. |
1591 // Others are deleted at the end of this call. | 1579 // Others are deleted at the end of this call. |
1592 if (is_termination_packet) { | 1580 if (is_termination_packet) { |
1593 if (termination_packets_.get() == nullptr) { | 1581 if (termination_packets_.get() == nullptr) { |
1594 termination_packets_.reset(new std::vector<QuicEncryptedPacket*>); | 1582 termination_packets_.reset(new std::vector<QuicEncryptedPacket*>); |
1595 } | 1583 } |
1596 // Clone the packet so it's owned in the future. | 1584 // Clone the packet so it's owned in the future. |
1597 termination_packets_->push_back(encrypted->Clone()); | 1585 termination_packets_->push_back(encrypted->Clone()); |
1598 // This assures we won't try to write *forced* packets when blocked. | 1586 // This assures we won't try to write *forced* packets when blocked. |
1599 // Return true to stop processing. | 1587 // Return true to stop processing. |
1600 if (writer_->IsWriteBlocked()) { | 1588 if (writer_->IsWriteBlocked()) { |
1601 visitor_->OnWriteBlocked(); | 1589 visitor_->OnWriteBlocked(); |
1602 return true; | 1590 return true; |
1603 } | 1591 } |
1604 } | 1592 } |
1605 | 1593 |
1606 DCHECK_LE(encrypted->length(), kMaxPacketSize); | 1594 DCHECK_LE(encrypted->length(), kMaxPacketSize); |
1607 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); | 1595 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); |
1608 DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : " | 1596 DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : " |
1609 << (packet->serialized_packet.is_fec_packet | 1597 << (packet->is_fec_packet |
1610 ? "FEC " | 1598 ? "FEC " |
1611 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA | 1599 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA |
1612 ? "data bearing " | 1600 ? "data bearing " |
1613 : " ack only ")) | 1601 : " ack only ")) |
1614 << ", encryption level: " | 1602 << ", encryption level: " |
1615 << QuicUtils::EncryptionLevelToString( | 1603 << QuicUtils::EncryptionLevelToString(packet->encryption_level) |
1616 packet->serialized_packet.encryption_level) | |
1617 << ", encrypted length:" << encrypted->length(); | 1604 << ", encrypted length:" << encrypted->length(); |
1618 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl | 1605 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl |
1619 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); | 1606 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
1620 | 1607 |
1621 // Measure the RTT from before the write begins to avoid underestimating the | 1608 // Measure the RTT from before the write begins to avoid underestimating the |
1622 // min_rtt_, especially in cases where the thread blocks or gets swapped out | 1609 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
1623 // during the WritePacket below. | 1610 // during the WritePacket below. |
1624 QuicTime packet_send_time = clock_->Now(); | 1611 QuicTime packet_send_time = clock_->Now(); |
1625 WriteResult result = | 1612 WriteResult result = |
1626 writer_->WritePacket(encrypted->data(), encrypted->length(), | 1613 writer_->WritePacket(encrypted->data(), encrypted->length(), |
1627 self_address().address(), peer_address()); | 1614 self_address().address(), peer_address()); |
1628 if (result.error_code == ERR_IO_PENDING) { | 1615 if (result.error_code == ERR_IO_PENDING) { |
1629 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); | 1616 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); |
1630 } | 1617 } |
1631 | 1618 |
1632 if (result.status == WRITE_STATUS_BLOCKED) { | 1619 if (result.status == WRITE_STATUS_BLOCKED) { |
1633 visitor_->OnWriteBlocked(); | 1620 visitor_->OnWriteBlocked(); |
1634 // If the socket buffers the the data, then the packet should not | 1621 // If the socket buffers the the data, then the packet should not |
1635 // be queued and sent again, which would result in an unnecessary | 1622 // be queued and sent again, which would result in an unnecessary |
1636 // duplicate packet being sent. The helper must call OnCanWrite | 1623 // duplicate packet being sent. The helper must call OnCanWrite |
1637 // when the write completes, and OnWriteError if an error occurs. | 1624 // when the write completes, and OnWriteError if an error occurs. |
1638 if (!writer_->IsWriteBlockedDataBuffered()) { | 1625 if (!writer_->IsWriteBlockedDataBuffered()) { |
1639 return false; | 1626 return false; |
1640 } | 1627 } |
1641 } | 1628 } |
1642 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { | 1629 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { |
1643 // Pass the write result to the visitor. | 1630 // Pass the write result to the visitor. |
1644 debug_visitor_->OnPacketSent( | 1631 debug_visitor_->OnPacketSent(*packet, packet->original_packet_number, |
1645 packet->serialized_packet, packet->original_packet_number, | 1632 packet->transmission_type, encrypted->length(), |
1646 packet->transmission_type, encrypted->length(), packet_send_time); | 1633 packet_send_time); |
1647 } | 1634 } |
1648 if (packet->transmission_type == NOT_RETRANSMISSION) { | 1635 if (packet->transmission_type == NOT_RETRANSMISSION) { |
1649 time_of_last_sent_new_packet_ = packet_send_time; | 1636 time_of_last_sent_new_packet_ = packet_send_time; |
1650 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && | 1637 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && |
1651 last_send_for_timeout_ <= time_of_last_received_packet_) { | 1638 last_send_for_timeout_ <= time_of_last_received_packet_) { |
1652 last_send_for_timeout_ = packet_send_time; | 1639 last_send_for_timeout_ = packet_send_time; |
1653 } | 1640 } |
1654 } | 1641 } |
1655 SetPingAlarm(); | 1642 SetPingAlarm(); |
1656 MaybeSetFecAlarm(packet_number); | 1643 MaybeSetFecAlarm(packet_number); |
1657 MaybeSetMtuAlarm(); | 1644 MaybeSetMtuAlarm(); |
1658 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " | 1645 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " |
1659 << packet_send_time.ToDebuggingValue(); | 1646 << packet_send_time.ToDebuggingValue(); |
1660 | 1647 |
1661 // TODO(ianswett): Change the packet number length and other packet creator | 1648 // TODO(ianswett): Change the packet number length and other packet creator |
1662 // options by a more explicit API than setting a struct value directly, | 1649 // options by a more explicit API than setting a struct value directly, |
1663 // perhaps via the NetworkChangeVisitor. | 1650 // perhaps via the NetworkChangeVisitor. |
1664 packet_generator_.UpdateSequenceNumberLength( | 1651 packet_generator_.UpdateSequenceNumberLength( |
1665 sent_packet_manager_.least_packet_awaited_by_peer(), | 1652 sent_packet_manager_.least_packet_awaited_by_peer(), |
1666 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); | 1653 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); |
1667 | 1654 |
1668 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( | 1655 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( |
1669 &packet->serialized_packet, packet->original_packet_number, | 1656 packet, packet->original_packet_number, packet_send_time, |
1670 packet_send_time, encrypted->length(), packet->transmission_type, | 1657 encrypted->length(), packet->transmission_type, |
1671 IsRetransmittable(*packet)); | 1658 IsRetransmittable(*packet)); |
1672 | 1659 |
1673 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { | 1660 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { |
1674 SetRetransmissionAlarm(); | 1661 SetRetransmissionAlarm(); |
1675 } | 1662 } |
1676 | 1663 |
1677 stats_.bytes_sent += result.bytes_written; | 1664 stats_.bytes_sent += result.bytes_written; |
1678 ++stats_.packets_sent; | 1665 ++stats_.packets_sent; |
1679 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1666 if (packet->transmission_type != NOT_RETRANSMISSION) { |
1680 stats_.bytes_retransmitted += result.bytes_written; | 1667 stats_.bytes_retransmitted += result.bytes_written; |
1681 ++stats_.packets_retransmitted; | 1668 ++stats_.packets_retransmitted; |
1682 } | 1669 } |
1683 | 1670 |
1684 if (result.status == WRITE_STATUS_ERROR) { | 1671 if (result.status == WRITE_STATUS_ERROR) { |
1685 OnWriteError(result.error_code); | 1672 OnWriteError(result.error_code); |
1686 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() | 1673 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() |
1687 << " bytes " | 1674 << " bytes " |
1688 << " from host " << (self_address().address().empty() | 1675 << " from host " << (self_address().address().empty() |
1689 ? " empty address " | 1676 ? " empty address " |
1690 : self_address().ToStringWithoutPort()) | 1677 : self_address().ToStringWithoutPort()) |
1691 << " to address " << peer_address().ToString(); | 1678 << " to address " << peer_address().ToString(); |
1692 return false; | 1679 return false; |
1693 } | 1680 } |
1694 | 1681 |
1695 return true; | 1682 return true; |
1696 } | 1683 } |
1697 | 1684 |
1698 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { | 1685 bool QuicConnection::ShouldDiscardPacket(const SerializedPacket& packet) { |
1699 if (!connected_) { | 1686 if (!connected_) { |
1700 DVLOG(1) << ENDPOINT << "Not sending packet as connection is disconnected."; | 1687 DVLOG(1) << ENDPOINT << "Not sending packet as connection is disconnected."; |
1701 return true; | 1688 return true; |
1702 } | 1689 } |
1703 | 1690 |
1704 QuicPacketNumber packet_number = packet.serialized_packet.packet_number; | 1691 QuicPacketNumber packet_number = packet.packet_number; |
1705 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE && | 1692 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE && |
1706 packet.serialized_packet.encryption_level == ENCRYPTION_NONE) { | 1693 packet.encryption_level == ENCRYPTION_NONE) { |
1707 // Drop packets that are NULL encrypted since the peer won't accept them | 1694 // Drop packets that are NULL encrypted since the peer won't accept them |
1708 // anymore. | 1695 // anymore. |
1709 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " << packet_number | 1696 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " << packet_number |
1710 << " since the connection is forward secure."; | 1697 << " since the connection is forward secure."; |
1711 return true; | 1698 return true; |
1712 } | 1699 } |
1713 | 1700 |
1714 // If a retransmission has been acked before sending, don't send it. | 1701 // If a retransmission has been acked before sending, don't send it. |
1715 // This occurs if a packet gets serialized, queued, then discarded. | 1702 // This occurs if a packet gets serialized, queued, then discarded. |
1716 if (packet.transmission_type != NOT_RETRANSMISSION && | 1703 if (packet.transmission_type != NOT_RETRANSMISSION && |
(...skipping 13 matching lines...) Expand all Loading... |
1730 << ErrorToString(error_code) << ")"; | 1717 << ErrorToString(error_code) << ")"; |
1731 // We can't send an error as the socket is presumably borked. | 1718 // We can't send an error as the socket is presumably borked. |
1732 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); | 1719 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); |
1733 } | 1720 } |
1734 | 1721 |
1735 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) { | 1722 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) { |
1736 DCHECK_NE(kInvalidPathId, serialized_packet->path_id); | 1723 DCHECK_NE(kInvalidPathId, serialized_packet->path_id); |
1737 if (serialized_packet->packet == nullptr) { | 1724 if (serialized_packet->packet == nullptr) { |
1738 // We failed to serialize the packet, so close the connection. | 1725 // We failed to serialize the packet, so close the connection. |
1739 // CloseConnection does not send close packet, so no infinite loop here. | 1726 // CloseConnection does not send close packet, so no infinite loop here. |
| 1727 // TODO(ianswett): This is actually an internal error, not an encryption |
| 1728 // failure. |
1740 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1729 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
1741 return; | 1730 return; |
1742 } | 1731 } |
1743 if (serialized_packet->is_fec_packet && fec_alarm_->IsSet()) { | 1732 if (serialized_packet->is_fec_packet && fec_alarm_->IsSet()) { |
1744 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. | 1733 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. |
1745 fec_alarm_->Cancel(); | 1734 fec_alarm_->Cancel(); |
1746 } | 1735 } |
1747 SendOrQueuePacket(QueuedPacket(*serialized_packet)); | 1736 SendOrQueuePacket(serialized_packet); |
1748 } | 1737 } |
1749 | 1738 |
1750 void QuicConnection::OnResetFecGroup() { | 1739 void QuicConnection::OnResetFecGroup() { |
1751 if (!fec_alarm_->IsSet()) { | 1740 if (!fec_alarm_->IsSet()) { |
1752 return; | 1741 return; |
1753 } | 1742 } |
1754 // If an FEC Group is closed with the FEC alarm set, cancel the alarm. | 1743 // If an FEC Group is closed with the FEC alarm set, cancel the alarm. |
1755 fec_alarm_->Cancel(); | 1744 fec_alarm_->Cancel(); |
1756 } | 1745 } |
1757 | 1746 |
(...skipping 19 matching lines...) Expand all Loading... |
1777 sent_packet_manager_.SetHandshakeConfirmed(); | 1766 sent_packet_manager_.SetHandshakeConfirmed(); |
1778 // The client should immediately ack the SHLO to confirm the handshake is | 1767 // The client should immediately ack the SHLO to confirm the handshake is |
1779 // complete with the server. | 1768 // complete with the server. |
1780 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ && | 1769 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ && |
1781 ack_frame_updated()) { | 1770 ack_frame_updated()) { |
1782 ack_alarm_->Cancel(); | 1771 ack_alarm_->Cancel(); |
1783 ack_alarm_->Set(clock_->ApproximateNow()); | 1772 ack_alarm_->Set(clock_->ApproximateNow()); |
1784 } | 1773 } |
1785 } | 1774 } |
1786 | 1775 |
1787 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) { | 1776 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) { |
1788 // The caller of this function is responsible for checking CanWrite(). | 1777 // The caller of this function is responsible for checking CanWrite(). |
1789 if (packet.serialized_packet.packet == nullptr) { | 1778 if (packet->packet == nullptr) { |
1790 LOG(DFATAL) | 1779 LOG(DFATAL) << "packet.packet == nullptr in to SendOrQueuePacket"; |
1791 << "packet.serialized_packet.packet == nullptr in to SendOrQueuePacket"; | |
1792 return; | 1780 return; |
1793 } | 1781 } |
1794 | 1782 |
1795 sent_entropy_manager_.RecordPacketEntropyHash( | 1783 sent_entropy_manager_.RecordPacketEntropyHash(packet->packet_number, |
1796 packet.serialized_packet.packet_number, | 1784 packet->entropy_hash); |
1797 packet.serialized_packet.entropy_hash); | |
1798 // If there are already queued packets, queue this one immediately to ensure | 1785 // If there are already queued packets, queue this one immediately to ensure |
1799 // it's written in sequence number order. | 1786 // it's written in sequence number order. |
1800 if (!queued_packets_.empty() || !WritePacket(&packet)) { | 1787 if (!queued_packets_.empty() || !WritePacket(packet)) { |
1801 // Take ownership of the underlying encrypted packet. | 1788 // Take ownership of the underlying encrypted packet. |
1802 if (!packet.serialized_packet.packet->owns_buffer()) { | 1789 if (!packet->packet->owns_buffer()) { |
1803 scoped_ptr<QuicEncryptedPacket> encrypted_deleter( | 1790 scoped_ptr<QuicEncryptedPacket> encrypted_deleter(packet->packet); |
1804 packet.serialized_packet.packet); | 1791 packet->packet = packet->packet->Clone(); |
1805 packet.serialized_packet.packet = | |
1806 packet.serialized_packet.packet->Clone(); | |
1807 } | 1792 } |
1808 queued_packets_.push_back(packet); | 1793 queued_packets_.push_back(*packet); |
1809 } | 1794 } |
1810 | 1795 |
1811 // If a forward-secure encrypter is available but is not being used and the | 1796 // If a forward-secure encrypter is available but is not being used and the |
1812 // next packet number is the first packet which requires | 1797 // next packet number is the first packet which requires |
1813 // forward security, start using the forward-secure encrypter. | 1798 // forward security, start using the forward-secure encrypter. |
1814 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | 1799 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && |
1815 has_forward_secure_encrypter_ && | 1800 has_forward_secure_encrypter_ && |
1816 packet.serialized_packet.packet_number >= | 1801 packet->packet_number >= first_required_forward_secure_packet_ - 1) { |
1817 first_required_forward_secure_packet_ - 1) { | |
1818 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | 1802 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
1819 } | 1803 } |
1820 } | 1804 } |
1821 | 1805 |
1822 PeerAddressChangeType QuicConnection::DeterminePeerAddressChangeType() { | 1806 PeerAddressChangeType QuicConnection::DeterminePeerAddressChangeType() { |
1823 return UNKNOWN; | 1807 return UNKNOWN; |
1824 } | 1808 } |
1825 | 1809 |
1826 void QuicConnection::SendPing() { | 1810 void QuicConnection::SendPing() { |
1827 if (retransmission_alarm_->IsSet()) { | 1811 if (retransmission_alarm_->IsSet()) { |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 return; | 2305 return; |
2322 } | 2306 } |
2323 connection_->delay_setting_retransmission_alarm_ = false; | 2307 connection_->delay_setting_retransmission_alarm_ = false; |
2324 if (connection_->pending_retransmission_alarm_) { | 2308 if (connection_->pending_retransmission_alarm_) { |
2325 connection_->SetRetransmissionAlarm(); | 2309 connection_->SetRetransmissionAlarm(); |
2326 connection_->pending_retransmission_alarm_ = false; | 2310 connection_->pending_retransmission_alarm_ = false; |
2327 } | 2311 } |
2328 } | 2312 } |
2329 | 2313 |
2330 HasRetransmittableData QuicConnection::IsRetransmittable( | 2314 HasRetransmittableData QuicConnection::IsRetransmittable( |
2331 const QueuedPacket& packet) { | 2315 const SerializedPacket& packet) { |
2332 // Retransmitted packets retransmittable frames are owned by the unacked | 2316 // Retransmitted packets retransmittable frames are owned by the unacked |
2333 // packet map, but are not present in the serialized packet. | 2317 // packet map, but are not present in the serialized packet. |
2334 if (packet.transmission_type != NOT_RETRANSMISSION || | 2318 if (packet.transmission_type != NOT_RETRANSMISSION || |
2335 packet.serialized_packet.retransmittable_frames != nullptr) { | 2319 packet.retransmittable_frames != nullptr) { |
2336 return HAS_RETRANSMITTABLE_DATA; | 2320 return HAS_RETRANSMITTABLE_DATA; |
2337 } else { | 2321 } else { |
2338 return NO_RETRANSMITTABLE_DATA; | 2322 return NO_RETRANSMITTABLE_DATA; |
2339 } | 2323 } |
2340 } | 2324 } |
2341 | 2325 |
2342 bool QuicConnection::IsTerminationPacket(const QueuedPacket& packet) { | 2326 bool QuicConnection::IsTerminationPacket(const SerializedPacket& packet) { |
2343 const RetransmittableFrames* retransmittable_frames = | 2327 if (packet.retransmittable_frames == nullptr) { |
2344 packet.serialized_packet.retransmittable_frames; | |
2345 if (retransmittable_frames == nullptr) { | |
2346 return false; | 2328 return false; |
2347 } | 2329 } |
2348 for (const QuicFrame& frame : retransmittable_frames->frames()) { | 2330 for (const QuicFrame& frame : packet.retransmittable_frames->frames()) { |
2349 if (frame.type == CONNECTION_CLOSE_FRAME) { | 2331 if (frame.type == CONNECTION_CLOSE_FRAME) { |
2350 return true; | 2332 return true; |
2351 } | 2333 } |
2352 if (save_crypto_packets_as_termination_packets_ && | 2334 if (save_crypto_packets_as_termination_packets_ && |
2353 frame.type == STREAM_FRAME && | 2335 frame.type == STREAM_FRAME && |
2354 frame.stream_frame->stream_id == kCryptoStreamId) { | 2336 frame.stream_frame->stream_id == kCryptoStreamId) { |
2355 return true; | 2337 return true; |
2356 } | 2338 } |
2357 } | 2339 } |
2358 return false; | 2340 return false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2418 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2400 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2419 | 2401 |
2420 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2402 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2421 } | 2403 } |
2422 | 2404 |
2423 bool QuicConnection::ack_frame_updated() const { | 2405 bool QuicConnection::ack_frame_updated() const { |
2424 return received_packet_manager_.ack_frame_updated(); | 2406 return received_packet_manager_.ack_frame_updated(); |
2425 } | 2407 } |
2426 | 2408 |
2427 } // namespace net | 2409 } // namespace net |
OLD | NEW |