| Index: net/quic/quic_connection.cc
|
| diff --git a/net/quic/quic_connection.cc b/net/quic/quic_connection.cc
|
| index 0a0a51f9baa16641937404adf6387e4002e19478..74c785c7f9c7ab9985670c972492ce9786633079 100644
|
| --- a/net/quic/quic_connection.cc
|
| +++ b/net/quic/quic_connection.cc
|
| @@ -362,6 +362,9 @@ QuicConnection::~QuicConnection() {
|
| void QuicConnection::ClearQueuedPackets() {
|
| for (QueuedPacketList::iterator it = queued_packets_.begin();
|
| it != queued_packets_.end(); ++it) {
|
| + // Delete the buffer before calling ClearSerializedPacket, which sets
|
| + // encrypted_buffer to nullptr.
|
| + delete[] it->encrypted_buffer;
|
| QuicUtils::ClearSerializedPacket(&(*it));
|
| }
|
| queued_packets_.clear();
|
| @@ -1207,6 +1210,7 @@ void QuicConnection::SendRstStream(QuicStreamId id,
|
| ++packet_iterator;
|
| continue;
|
| }
|
| + delete[] packet_iterator->encrypted_buffer;
|
| QuicUtils::ClearSerializedPacket(&(*packet_iterator));
|
| packet_iterator = queued_packets_.erase(packet_iterator);
|
| }
|
| @@ -1471,6 +1475,8 @@ void QuicConnection::WriteQueuedPackets() {
|
| QueuedPacketList::iterator packet_iterator = queued_packets_.begin();
|
| while (packet_iterator != queued_packets_.end() &&
|
| WritePacket(&(*packet_iterator))) {
|
| + delete[] packet_iterator->encrypted_buffer;
|
| + QuicUtils::ClearSerializedPacket(&(*packet_iterator));
|
| packet_iterator = queued_packets_.erase(packet_iterator);
|
| }
|
| }
|
| @@ -1497,10 +1503,10 @@ void QuicConnection::WritePendingRetransmissions() {
|
| SerializedPacket serialized_packet =
|
| packet_generator_.ReserializeAllFrames(pending, buffer, kMaxPacketSize);
|
| if (FLAGS_quic_retransmit_via_onserializedpacket) {
|
| - DCHECK(serialized_packet.packet == nullptr);
|
| + DCHECK(serialized_packet.encrypted_buffer == nullptr);
|
| continue;
|
| }
|
| - if (serialized_packet.packet == nullptr) {
|
| + if (serialized_packet.encrypted_buffer == nullptr) {
|
| // We failed to serialize the packet, so close the connection.
|
| // CloseConnection does not send close packet, so no infinite loop here.
|
| // TODO(ianswett): This is actually an internal error, not an encryption
|
| @@ -1587,14 +1593,6 @@ bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) {
|
| }
|
|
|
| bool QuicConnection::WritePacket(SerializedPacket* packet) {
|
| - if (!WritePacketInner(packet)) {
|
| - return false;
|
| - }
|
| - QuicUtils::ClearSerializedPacket(packet);
|
| - return true;
|
| -}
|
| -
|
| -bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
| if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) {
|
| QUIC_BUG << "Attempt to write packet:" << packet->packet_number
|
| << " after:" << sent_packet_manager_.largest_sent_packet();
|
| @@ -1616,15 +1614,17 @@ bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
| DCHECK_LE(packet_number_of_last_sent_packet_, packet_number);
|
| packet_number_of_last_sent_packet_ = packet_number;
|
|
|
| - QuicEncryptedPacket* encrypted = packet->packet;
|
| + QuicPacketLength encrypted_length = packet->encrypted_length;
|
| // Termination packets are eventually owned by TimeWaitListManager.
|
| // Others are deleted at the end of this call.
|
| if (is_termination_packet) {
|
| if (termination_packets_.get() == nullptr) {
|
| termination_packets_.reset(new std::vector<QuicEncryptedPacket*>);
|
| }
|
| - // Clone the packet so it's owned in the future.
|
| - termination_packets_->push_back(encrypted->Clone());
|
| + // Copy the buffer so it's owned in the future.
|
| + char* buffer_copy = QuicUtils::CopyBuffer(*packet);
|
| + termination_packets_->push_back(
|
| + new QuicEncryptedPacket(buffer_copy, encrypted_length, true));
|
| // This assures we won't try to write *forced* packets when blocked.
|
| // Return true to stop processing.
|
| if (writer_->IsWriteBlocked()) {
|
| @@ -1633,8 +1633,8 @@ bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
| }
|
| }
|
|
|
| - DCHECK_LE(encrypted->length(), kMaxPacketSize);
|
| - DCHECK_LE(encrypted->length(), packet_generator_.GetMaxPacketLength());
|
| + DCHECK_LE(encrypted_length, kMaxPacketSize);
|
| + DCHECK_LE(encrypted_length, packet_generator_.GetMaxPacketLength());
|
| DVLOG(1) << ENDPOINT << "Sending packet " << packet_number << " : "
|
| << (packet->is_fec_packet
|
| ? "FEC "
|
| @@ -1643,17 +1643,18 @@ bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
| : " ack only "))
|
| << ", encryption level: "
|
| << QuicUtils::EncryptionLevelToString(packet->encryption_level)
|
| - << ", encrypted length:" << encrypted->length();
|
| + << ", encrypted length:" << encrypted_length;
|
| DVLOG(2) << ENDPOINT << "packet(" << packet_number << "): " << std::endl
|
| - << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece());
|
| + << QuicUtils::StringToHexASCIIDump(
|
| + StringPiece(packet->encrypted_buffer, encrypted_length));
|
|
|
| // Measure the RTT from before the write begins to avoid underestimating the
|
| // min_rtt_, especially in cases where the thread blocks or gets swapped out
|
| // during the WritePacket below.
|
| QuicTime packet_send_time = clock_->Now();
|
| WriteResult result = writer_->WritePacket(
|
| - encrypted->data(), encrypted->length(), self_address().address().bytes(),
|
| - peer_address(), per_packet_options_);
|
| + packet->encrypted_buffer, encrypted_length,
|
| + self_address().address().bytes(), peer_address(), per_packet_options_);
|
| if (result.error_code == ERR_IO_PENDING) {
|
| DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status);
|
| }
|
| @@ -1671,7 +1672,7 @@ bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
| if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) {
|
| // Pass the write result to the visitor.
|
| debug_visitor_->OnPacketSent(*packet, packet->original_packet_number,
|
| - packet->transmission_type, encrypted->length(),
|
| + packet->transmission_type, encrypted_length,
|
| packet_send_time);
|
| }
|
| if (packet->transmission_type == NOT_RETRANSMISSION) {
|
| @@ -1696,8 +1697,7 @@ bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
|
|
| bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
|
| packet, packet->original_packet_number, packet_send_time,
|
| - encrypted->length(), packet->transmission_type,
|
| - IsRetransmittable(*packet));
|
| + encrypted_length, packet->transmission_type, IsRetransmittable(*packet));
|
|
|
| if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
|
| SetRetransmissionAlarm();
|
| @@ -1712,7 +1712,7 @@ bool QuicConnection::WritePacketInner(SerializedPacket* packet) {
|
|
|
| if (result.status == WRITE_STATUS_ERROR) {
|
| OnWriteError(result.error_code);
|
| - DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length()
|
| + DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length
|
| << " bytes "
|
| << " from host " << (self_address().address().empty()
|
| ? " empty address "
|
| @@ -1763,7 +1763,7 @@ void QuicConnection::OnWriteError(int error_code) {
|
|
|
| void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) {
|
| DCHECK_NE(kInvalidPathId, serialized_packet->path_id);
|
| - if (serialized_packet->packet == nullptr) {
|
| + if (serialized_packet->encrypted_buffer == nullptr) {
|
| // We failed to serialize the packet, so close the connection.
|
| // CloseConnection does not send close packet, so no infinite loop here.
|
| // TODO(ianswett): This is actually an internal error, not an encryption
|
| @@ -1817,8 +1817,8 @@ void QuicConnection::OnHandshakeComplete() {
|
|
|
| void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) {
|
| // The caller of this function is responsible for checking CanWrite().
|
| - if (packet->packet == nullptr) {
|
| - QUIC_BUG << "packet.packet == nullptr in to SendOrQueuePacket";
|
| + if (packet->encrypted_buffer == nullptr) {
|
| + QUIC_BUG << "packet.encrypted_buffer == nullptr in to SendOrQueuePacket";
|
| return;
|
| }
|
|
|
| @@ -1828,14 +1828,12 @@ void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) {
|
| // it's written in sequence number order.
|
| if (!queued_packets_.empty() || !WritePacket(packet)) {
|
| // Take ownership of the underlying encrypted packet.
|
| - if (!packet->packet->owns_buffer()) {
|
| - scoped_ptr<QuicEncryptedPacket> encrypted_deleter(packet->packet);
|
| - packet->packet = packet->packet->Clone();
|
| - }
|
| + packet->encrypted_buffer = QuicUtils::CopyBuffer(*packet);
|
| queued_packets_.push_back(*packet);
|
| packet->retransmittable_frames.clear();
|
| }
|
|
|
| + QuicUtils::ClearSerializedPacket(packet);
|
| // If a forward-secure encrypter is available but is not being used and the
|
| // next packet number is the first packet which requires
|
| // forward security, start using the forward-secure encrypter.
|
|
|