Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: net/quic/quic_connection.cc

Issue 1667003002: Replace QuicEncryptedPacket's fields with equivalents in SerializedPacket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@113395732
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (termination_packets_.get() != nullptr) { 355 if (termination_packets_.get() != nullptr) {
356 STLDeleteElements(termination_packets_.get()); 356 STLDeleteElements(termination_packets_.get());
357 } 357 }
358 STLDeleteValues(&group_map_); 358 STLDeleteValues(&group_map_);
359 ClearQueuedPackets(); 359 ClearQueuedPackets();
360 } 360 }
361 361
362 void QuicConnection::ClearQueuedPackets() { 362 void QuicConnection::ClearQueuedPackets() {
363 for (QueuedPacketList::iterator it = queued_packets_.begin(); 363 for (QueuedPacketList::iterator it = queued_packets_.begin();
364 it != queued_packets_.end(); ++it) { 364 it != queued_packets_.end(); ++it) {
365 // Delete the buffer before calling ClearSerializedPacket, which sets
366 // encrypted_buffer to nullptr.
367 delete[] it->encrypted_buffer;
365 QuicUtils::ClearSerializedPacket(&(*it)); 368 QuicUtils::ClearSerializedPacket(&(*it));
366 } 369 }
367 queued_packets_.clear(); 370 queued_packets_.clear();
368 } 371 }
369 372
370 void QuicConnection::SetFromConfig(const QuicConfig& config) { 373 void QuicConnection::SetFromConfig(const QuicConfig& config) {
371 if (config.negotiated()) { 374 if (config.negotiated()) {
372 // Handshake complete, set handshake timeout to Infinite. 375 // Handshake complete, set handshake timeout to Infinite.
373 SetNetworkTimeouts(QuicTime::Delta::Infinite(), 376 SetNetworkTimeouts(QuicTime::Delta::Infinite(),
374 config.IdleConnectionStateLifetime()); 377 config.IdleConnectionStateLifetime());
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 &packet_iterator->retransmittable_frames; 1203 &packet_iterator->retransmittable_frames;
1201 if (retransmittable_frames->empty()) { 1204 if (retransmittable_frames->empty()) {
1202 ++packet_iterator; 1205 ++packet_iterator;
1203 continue; 1206 continue;
1204 } 1207 }
1205 QuicUtils::RemoveFramesForStream(retransmittable_frames, id); 1208 QuicUtils::RemoveFramesForStream(retransmittable_frames, id);
1206 if (!retransmittable_frames->empty()) { 1209 if (!retransmittable_frames->empty()) {
1207 ++packet_iterator; 1210 ++packet_iterator;
1208 continue; 1211 continue;
1209 } 1212 }
1213 delete[] packet_iterator->encrypted_buffer;
1210 QuicUtils::ClearSerializedPacket(&(*packet_iterator)); 1214 QuicUtils::ClearSerializedPacket(&(*packet_iterator));
1211 packet_iterator = queued_packets_.erase(packet_iterator); 1215 packet_iterator = queued_packets_.erase(packet_iterator);
1212 } 1216 }
1213 } 1217 }
1214 1218
1215 void QuicConnection::SendWindowUpdate(QuicStreamId id, 1219 void QuicConnection::SendWindowUpdate(QuicStreamId id,
1216 QuicStreamOffset byte_offset) { 1220 QuicStreamOffset byte_offset) {
1217 // Opportunistically bundle an ack with this outgoing packet. 1221 // Opportunistically bundle an ack with this outgoing packet.
1218 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); 1222 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK);
1219 packet_generator_.AddControlFrame( 1223 packet_generator_.AddControlFrame(
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 void QuicConnection::WriteQueuedPackets() { 1468 void QuicConnection::WriteQueuedPackets() {
1465 DCHECK(!writer_->IsWriteBlocked()); 1469 DCHECK(!writer_->IsWriteBlocked());
1466 1470
1467 if (pending_version_negotiation_packet_) { 1471 if (pending_version_negotiation_packet_) {
1468 SendVersionNegotiationPacket(); 1472 SendVersionNegotiationPacket();
1469 } 1473 }
1470 1474
1471 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); 1475 QueuedPacketList::iterator packet_iterator = queued_packets_.begin();
1472 while (packet_iterator != queued_packets_.end() && 1476 while (packet_iterator != queued_packets_.end() &&
1473 WritePacket(&(*packet_iterator))) { 1477 WritePacket(&(*packet_iterator))) {
1478 delete[] packet_iterator->encrypted_buffer;
1479 QuicUtils::ClearSerializedPacket(&(*packet_iterator));
1474 packet_iterator = queued_packets_.erase(packet_iterator); 1480 packet_iterator = queued_packets_.erase(packet_iterator);
1475 } 1481 }
1476 } 1482 }
1477 1483
1478 void QuicConnection::WritePendingRetransmissions() { 1484 void QuicConnection::WritePendingRetransmissions() {
1479 // Keep writing as long as there's a pending retransmission which can be 1485 // Keep writing as long as there's a pending retransmission which can be
1480 // written. 1486 // written.
1481 while (sent_packet_manager_.HasPendingRetransmissions()) { 1487 while (sent_packet_manager_.HasPendingRetransmissions()) {
1482 const PendingRetransmission pending = 1488 const PendingRetransmission pending =
1483 sent_packet_manager_.NextPendingRetransmission(); 1489 sent_packet_manager_.NextPendingRetransmission();
1484 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) { 1490 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1485 break; 1491 break;
1486 } 1492 }
1487 1493
1488 // Re-packetize the frames with a new packet number for retransmission. 1494 // Re-packetize the frames with a new packet number for retransmission.
1489 // Retransmitted data packets do not use FEC, even when it's enabled. 1495 // Retransmitted data packets do not use FEC, even when it's enabled.
1490 // Retransmitted packets use the same packet number length as the 1496 // Retransmitted packets use the same packet number length as the
1491 // original. 1497 // original.
1492 // Flush the packet generator before making a new packet. 1498 // Flush the packet generator before making a new packet.
1493 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that 1499 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that
1494 // does not require the creator to be flushed. 1500 // does not require the creator to be flushed.
1495 packet_generator_.FlushAllQueuedFrames(); 1501 packet_generator_.FlushAllQueuedFrames();
1496 char buffer[kMaxPacketSize]; 1502 char buffer[kMaxPacketSize];
1497 SerializedPacket serialized_packet = 1503 SerializedPacket serialized_packet =
1498 packet_generator_.ReserializeAllFrames(pending, buffer, kMaxPacketSize); 1504 packet_generator_.ReserializeAllFrames(pending, buffer, kMaxPacketSize);
1499 if (FLAGS_quic_retransmit_via_onserializedpacket) { 1505 if (FLAGS_quic_retransmit_via_onserializedpacket) {
1500 DCHECK(serialized_packet.packet == nullptr); 1506 DCHECK(serialized_packet.encrypted_buffer == nullptr);
1501 continue; 1507 continue;
1502 } 1508 }
1503 if (serialized_packet.packet == nullptr) { 1509 if (serialized_packet.encrypted_buffer == nullptr) {
1504 // We failed to serialize the packet, so close the connection. 1510 // We failed to serialize the packet, so close the connection.
1505 // CloseConnection does not send close packet, so no infinite loop here. 1511 // CloseConnection does not send close packet, so no infinite loop here.
1506 // TODO(ianswett): This is actually an internal error, not an encryption 1512 // TODO(ianswett): This is actually an internal error, not an encryption
1507 // failure. 1513 // failure.
1508 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); 1514 CloseConnection(QUIC_ENCRYPTION_FAILURE, false);
1509 return; 1515 return;
1510 } 1516 }
1511 1517
1512 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.packet_number << " as " 1518 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.packet_number << " as "
1513 << serialized_packet.packet_number; 1519 << serialized_packet.packet_number;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 << "ms"; 1586 << "ms";
1581 return false; 1587 return false;
1582 } 1588 }
1583 if (!FLAGS_quic_respect_send_alarm2) { 1589 if (!FLAGS_quic_respect_send_alarm2) {
1584 send_alarm_->Cancel(); 1590 send_alarm_->Cancel();
1585 } 1591 }
1586 return true; 1592 return true;
1587 } 1593 }
1588 1594
1589 bool QuicConnection::WritePacket(SerializedPacket* packet) { 1595 bool QuicConnection::WritePacket(SerializedPacket* packet) {
1590 if (!WritePacketInner(packet)) {
1591 return false;
1592 }
1593 QuicUtils::ClearSerializedPacket(packet);
1594 return true;
1595 }
1596
1597 bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
1598 if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) { 1596 if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) {
1599 QUIC_BUG << "Attempt to write packet:" << packet->packet_number 1597 QUIC_BUG << "Attempt to write packet:" << packet->packet_number
1600 << " after:" << sent_packet_manager_.largest_sent_packet(); 1598 << " after:" << sent_packet_manager_.largest_sent_packet();
1601 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, 1599 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR,
1602 "Packet written out of order."); 1600 "Packet written out of order.");
1603 return true; 1601 return true;
1604 } 1602 }
1605 if (ShouldDiscardPacket(*packet)) { 1603 if (ShouldDiscardPacket(*packet)) {
1606 ++stats_.packets_discarded; 1604 ++stats_.packets_discarded;
1607 return true; 1605 return true;
1608 } 1606 }
1609 // Termination packets are encrypted and saved, so don't exit early. 1607 // Termination packets are encrypted and saved, so don't exit early.
1610 const bool is_termination_packet = IsTerminationPacket(*packet); 1608 const bool is_termination_packet = IsTerminationPacket(*packet);
1611 if (writer_->IsWriteBlocked() && !is_termination_packet) { 1609 if (writer_->IsWriteBlocked() && !is_termination_packet) {
1612 return false; 1610 return false;
1613 } 1611 }
1614 1612
1615 QuicPacketNumber packet_number = packet->packet_number; 1613 QuicPacketNumber packet_number = packet->packet_number;
1616 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number); 1614 DCHECK_LE(packet_number_of_last_sent_packet_, packet_number);
1617 packet_number_of_last_sent_packet_ = packet_number; 1615 packet_number_of_last_sent_packet_ = packet_number;
1618 1616
1619 QuicEncryptedPacket* encrypted = packet->packet; 1617 QuicPacketLength encrypted_length = packet->encrypted_length;
1620 // Termination packets are eventually owned by TimeWaitListManager. 1618 // Termination packets are eventually owned by TimeWaitListManager.
1621 // Others are deleted at the end of this call. 1619 // Others are deleted at the end of this call.
1622 if (is_termination_packet) { 1620 if (is_termination_packet) {
1623 if (termination_packets_.get() == nullptr) { 1621 if (termination_packets_.get() == nullptr) {
1624 termination_packets_.reset(new std::vector<QuicEncryptedPacket*>); 1622 termination_packets_.reset(new std::vector<QuicEncryptedPacket*>);
1625 } 1623 }
1626 // Clone the packet so it's owned in the future. 1624 // Copy the buffer so it's owned in the future.
1627 termination_packets_->push_back(encrypted->Clone()); 1625 char* buffer_copy = QuicUtils::CopyBuffer(*packet);
1626 termination_packets_->push_back(
1627 new QuicEncryptedPacket(buffer_copy, encrypted_length, true));
1628 // This assures we won't try to write *forced* packets when blocked. 1628 // This assures we won't try to write *forced* packets when blocked.
1629 // Return true to stop processing. 1629 // Return true to stop processing.
1630 if (writer_->IsWriteBlocked()) { 1630 if (writer_->IsWriteBlocked()) {
1631 visitor_->OnWriteBlocked(); 1631 visitor_->OnWriteBlocked();
1632 return true; 1632 return true;
1633 } 1633 }
1634 } 1634 }
1635 1635
1636 DCHECK_LE(encrypted->length(), kMaxPacketSize); 1636 DCHECK_LE(encrypted_length, kMaxPacketSize);
1637 DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength()); 1637 DCHECK_LE(encrypted_length, packet_generator_.GetMaxPacketLength());
1638 DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : " 1638 DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : "
1639 << (packet->is_fec_packet 1639 << (packet->is_fec_packet
1640 ? "FEC " 1640 ? "FEC "
1641 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA 1641 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA
1642 ? "data bearing " 1642 ? "data bearing "
1643 : " ack only ")) 1643 : " ack only "))
1644 << ", encryption level: " 1644 << ", encryption level: "
1645 << QuicUtils::EncryptionLevelToString(packet->encryption_level) 1645 << QuicUtils::EncryptionLevelToString(packet->encryption_level)
1646 << ", encrypted length:" << encrypted->length(); 1646 << ", encrypted length:" << encrypted_length;
1647 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl 1647 DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl
1648 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); 1648 << QuicUtils::StringToHexASCIIDump(
1649 StringPiece(packet->encrypted_buffer, encrypted_length));
1649 1650
1650 // Measure the RTT from before the write begins to avoid underestimating the 1651 // Measure the RTT from before the write begins to avoid underestimating the
1651 // min_rtt_, especially in cases where the thread blocks or gets swapped out 1652 // min_rtt_, especially in cases where the thread blocks or gets swapped out
1652 // during the WritePacket below. 1653 // during the WritePacket below.
1653 QuicTime packet_send_time = clock_->Now(); 1654 QuicTime packet_send_time = clock_->Now();
1654 WriteResult result = writer_->WritePacket( 1655 WriteResult result = writer_->WritePacket(
1655 encrypted->data(), encrypted->length(), self_address().address().bytes(), 1656 packet->encrypted_buffer, encrypted_length,
1656 peer_address(), per_packet_options_); 1657 self_address().address().bytes(), peer_address(), per_packet_options_);
1657 if (result.error_code == ERR_IO_PENDING) { 1658 if (result.error_code == ERR_IO_PENDING) {
1658 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); 1659 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status);
1659 } 1660 }
1660 1661
1661 if (result.status == WRITE_STATUS_BLOCKED) { 1662 if (result.status == WRITE_STATUS_BLOCKED) {
1662 visitor_->OnWriteBlocked(); 1663 visitor_->OnWriteBlocked();
1663 // If the socket buffers the the data, then the packet should not 1664 // If the socket buffers the the data, then the packet should not
1664 // be queued and sent again, which would result in an unnecessary 1665 // be queued and sent again, which would result in an unnecessary
1665 // duplicate packet being sent. The helper must call OnCanWrite 1666 // duplicate packet being sent. The helper must call OnCanWrite
1666 // when the write completes, and OnWriteError if an error occurs. 1667 // when the write completes, and OnWriteError if an error occurs.
1667 if (!writer_->IsWriteBlockedDataBuffered()) { 1668 if (!writer_->IsWriteBlockedDataBuffered()) {
1668 return false; 1669 return false;
1669 } 1670 }
1670 } 1671 }
1671 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { 1672 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) {
1672 // Pass the write result to the visitor. 1673 // Pass the write result to the visitor.
1673 debug_visitor_->OnPacketSent(*packet, packet->original_packet_number, 1674 debug_visitor_->OnPacketSent(*packet, packet->original_packet_number,
1674 packet->transmission_type, encrypted->length(), 1675 packet->transmission_type, encrypted_length,
1675 packet_send_time); 1676 packet_send_time);
1676 } 1677 }
1677 if (packet->transmission_type == NOT_RETRANSMISSION) { 1678 if (packet->transmission_type == NOT_RETRANSMISSION) {
1678 time_of_last_sent_new_packet_ = packet_send_time; 1679 time_of_last_sent_new_packet_ = packet_send_time;
1679 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && 1680 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA &&
1680 last_send_for_timeout_ <= time_of_last_received_packet_) { 1681 last_send_for_timeout_ <= time_of_last_received_packet_) {
1681 last_send_for_timeout_ = packet_send_time; 1682 last_send_for_timeout_ = packet_send_time;
1682 } 1683 }
1683 } 1684 }
1684 SetPingAlarm(); 1685 SetPingAlarm();
1685 MaybeSetFecAlarm(packet_number); 1686 MaybeSetFecAlarm(packet_number);
1686 MaybeSetMtuAlarm(); 1687 MaybeSetMtuAlarm();
1687 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " 1688 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: "
1688 << packet_send_time.ToDebuggingValue(); 1689 << packet_send_time.ToDebuggingValue();
1689 1690
1690 // TODO(ianswett): Change the packet number length and other packet creator 1691 // TODO(ianswett): Change the packet number length and other packet creator
1691 // options by a more explicit API than setting a struct value directly, 1692 // options by a more explicit API than setting a struct value directly,
1692 // perhaps via the NetworkChangeVisitor. 1693 // perhaps via the NetworkChangeVisitor.
1693 packet_generator_.UpdateSequenceNumberLength( 1694 packet_generator_.UpdateSequenceNumberLength(
1694 sent_packet_manager_.least_packet_awaited_by_peer(), 1695 sent_packet_manager_.least_packet_awaited_by_peer(),
1695 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1696 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1696 1697
1697 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1698 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
1698 packet, packet->original_packet_number, packet_send_time, 1699 packet, packet->original_packet_number, packet_send_time,
1699 encrypted->length(), packet->transmission_type, 1700 encrypted_length, packet->transmission_type, IsRetransmittable(*packet));
1700 IsRetransmittable(*packet));
1701 1701
1702 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1702 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1703 SetRetransmissionAlarm(); 1703 SetRetransmissionAlarm();
1704 } 1704 }
1705 1705
1706 stats_.bytes_sent += result.bytes_written; 1706 stats_.bytes_sent += result.bytes_written;
1707 ++stats_.packets_sent; 1707 ++stats_.packets_sent;
1708 if (packet->transmission_type != NOT_RETRANSMISSION) { 1708 if (packet->transmission_type != NOT_RETRANSMISSION) {
1709 stats_.bytes_retransmitted += result.bytes_written; 1709 stats_.bytes_retransmitted += result.bytes_written;
1710 ++stats_.packets_retransmitted; 1710 ++stats_.packets_retransmitted;
1711 } 1711 }
1712 1712
1713 if (result.status == WRITE_STATUS_ERROR) { 1713 if (result.status == WRITE_STATUS_ERROR) {
1714 OnWriteError(result.error_code); 1714 OnWriteError(result.error_code);
1715 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() 1715 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length
1716 << " bytes " 1716 << " bytes "
1717 << " from host " << (self_address().address().empty() 1717 << " from host " << (self_address().address().empty()
1718 ? " empty address " 1718 ? " empty address "
1719 : self_address().ToStringWithoutPort()) 1719 : self_address().ToStringWithoutPort())
1720 << " to address " << peer_address().ToString(); 1720 << " to address " << peer_address().ToString();
1721 return false; 1721 return false;
1722 } 1722 }
1723 1723
1724 return true; 1724 return true;
1725 } 1725 }
(...skipping 30 matching lines...) Expand all
1756 1756
1757 void QuicConnection::OnWriteError(int error_code) { 1757 void QuicConnection::OnWriteError(int error_code) {
1758 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code << " (" 1758 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code << " ("
1759 << ErrorToString(error_code) << ")"; 1759 << ErrorToString(error_code) << ")";
1760 // We can't send an error as the socket is presumably borked. 1760 // We can't send an error as the socket is presumably borked.
1761 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); 1761 CloseConnection(QUIC_PACKET_WRITE_ERROR, false);
1762 } 1762 }
1763 1763
1764 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) { 1764 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) {
1765 DCHECK_NE(kInvalidPathId, serialized_packet->path_id); 1765 DCHECK_NE(kInvalidPathId, serialized_packet->path_id);
1766 if (serialized_packet->packet == nullptr) { 1766 if (serialized_packet->encrypted_buffer == nullptr) {
1767 // We failed to serialize the packet, so close the connection. 1767 // We failed to serialize the packet, so close the connection.
1768 // CloseConnection does not send close packet, so no infinite loop here. 1768 // CloseConnection does not send close packet, so no infinite loop here.
1769 // TODO(ianswett): This is actually an internal error, not an encryption 1769 // TODO(ianswett): This is actually an internal error, not an encryption
1770 // failure. 1770 // failure.
1771 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); 1771 CloseConnection(QUIC_ENCRYPTION_FAILURE, false);
1772 return; 1772 return;
1773 } 1773 }
1774 if (serialized_packet->is_fec_packet && fec_alarm_->IsSet()) { 1774 if (serialized_packet->is_fec_packet && fec_alarm_->IsSet()) {
1775 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. 1775 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm.
1776 fec_alarm_->Cancel(); 1776 fec_alarm_->Cancel();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 // complete with the server. 1810 // complete with the server.
1811 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ && 1811 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ &&
1812 ack_frame_updated()) { 1812 ack_frame_updated()) {
1813 ack_alarm_->Cancel(); 1813 ack_alarm_->Cancel();
1814 ack_alarm_->Set(clock_->ApproximateNow()); 1814 ack_alarm_->Set(clock_->ApproximateNow());
1815 } 1815 }
1816 } 1816 }
1817 1817
1818 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) { 1818 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) {
1819 // The caller of this function is responsible for checking CanWrite(). 1819 // The caller of this function is responsible for checking CanWrite().
1820 if (packet->packet == nullptr) { 1820 if (packet->encrypted_buffer == nullptr) {
1821 QUIC_BUG << "packet.packet == nullptr in to SendOrQueuePacket"; 1821 QUIC_BUG << "packet.encrypted_buffer == nullptr in to SendOrQueuePacket";
1822 return; 1822 return;
1823 } 1823 }
1824 1824
1825 sent_entropy_manager_.RecordPacketEntropyHash(packet->packet_number, 1825 sent_entropy_manager_.RecordPacketEntropyHash(packet->packet_number,
1826 packet->entropy_hash); 1826 packet->entropy_hash);
1827 // If there are already queued packets, queue this one immediately to ensure 1827 // If there are already queued packets, queue this one immediately to ensure
1828 // it's written in sequence number order. 1828 // it's written in sequence number order.
1829 if (!queued_packets_.empty() || !WritePacket(packet)) { 1829 if (!queued_packets_.empty() || !WritePacket(packet)) {
1830 // Take ownership of the underlying encrypted packet. 1830 // Take ownership of the underlying encrypted packet.
1831 if (!packet->packet->owns_buffer()) { 1831 packet->encrypted_buffer = QuicUtils::CopyBuffer(*packet);
1832 scoped_ptr<QuicEncryptedPacket> encrypted_deleter(packet->packet);
1833 packet->packet = packet->packet->Clone();
1834 }
1835 queued_packets_.push_back(*packet); 1832 queued_packets_.push_back(*packet);
1836 packet->retransmittable_frames.clear(); 1833 packet->retransmittable_frames.clear();
1837 } 1834 }
1838 1835
1836 QuicUtils::ClearSerializedPacket(packet);
1839 // If a forward-secure encrypter is available but is not being used and the 1837 // If a forward-secure encrypter is available but is not being used and the
1840 // next packet number is the first packet which requires 1838 // next packet number is the first packet which requires
1841 // forward security, start using the forward-secure encrypter. 1839 // forward security, start using the forward-secure encrypter.
1842 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && 1840 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE &&
1843 has_forward_secure_encrypter_ && 1841 has_forward_secure_encrypter_ &&
1844 packet->packet_number >= first_required_forward_secure_packet_ - 1) { 1842 packet->packet_number >= first_required_forward_secure_packet_ - 1) {
1845 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 1843 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
1846 } 1844 }
1847 } 1845 }
1848 1846
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 void QuicConnection::OnPathClosed(QuicPathId path_id) { 2531 void QuicConnection::OnPathClosed(QuicPathId path_id) {
2534 // Stop receiving packets on this path. 2532 // Stop receiving packets on this path.
2535 framer_.OnPathClosed(path_id); 2533 framer_.OnPathClosed(path_id);
2536 } 2534 }
2537 2535
2538 bool QuicConnection::ack_frame_updated() const { 2536 bool QuicConnection::ack_frame_updated() const {
2539 return received_packet_manager_.ack_frame_updated(); 2537 return received_packet_manager_.ack_frame_updated();
2540 } 2538 }
2541 2539
2542 } // namespace net 2540 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698