| 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_packet_creator.h" | 5 #include "net/quic/quic_packet_creator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 buffer += copy_len; | 397 buffer += copy_len; |
| 398 if (length == 0 || ++iovnum >= iov.iov_count) { | 398 if (length == 0 || ++iovnum >= iov.iov_count) { |
| 399 break; | 399 break; |
| 400 } | 400 } |
| 401 src = static_cast<char*>(iov.iov[iovnum].iov_base); | 401 src = static_cast<char*>(iov.iov[iovnum].iov_base); |
| 402 copy_len = min(length, iov.iov[iovnum].iov_len); | 402 copy_len = min(length, iov.iov[iovnum].iov_len); |
| 403 } | 403 } |
| 404 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer."; | 404 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer."; |
| 405 } | 405 } |
| 406 | 406 |
| 407 SerializedPacket QuicPacketCreator::ReserializeAllFrames( | 407 void QuicPacketCreator::ReserializeAllFrames( |
| 408 const PendingRetransmission& retransmission, | 408 const PendingRetransmission& retransmission, |
| 409 char* buffer, | 409 char* buffer, |
| 410 size_t buffer_len) { | 410 size_t buffer_len) { |
| 411 DCHECK(queued_frames_.empty()); | 411 DCHECK(queued_frames_.empty()); |
| 412 DCHECK(fec_group_.get() == nullptr); | 412 DCHECK(fec_group_.get() == nullptr); |
| 413 DCHECK(!packet_.needs_padding); | 413 DCHECK(!packet_.needs_padding); |
| 414 QUIC_BUG_IF(retransmission.retransmittable_frames.empty()) | 414 QUIC_BUG_IF(retransmission.retransmittable_frames.empty()) |
| 415 << "Attempt to serialize empty packet"; | 415 << "Attempt to serialize empty packet"; |
| 416 const QuicPacketNumberLength saved_length = packet_.packet_number_length; | 416 const QuicPacketNumberLength saved_length = packet_.packet_number_length; |
| 417 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; | 417 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; |
| 418 const bool saved_should_fec_protect = fec_protect_; | 418 const bool saved_should_fec_protect = fec_protect_; |
| 419 const bool saved_needs_padding = packet_.needs_padding; | |
| 420 const EncryptionLevel default_encryption_level = packet_.encryption_level; | 419 const EncryptionLevel default_encryption_level = packet_.encryption_level; |
| 421 | 420 |
| 422 // Temporarily set the packet number length, stop FEC protection, | 421 // Temporarily set the packet number length, stop FEC protection, |
| 423 // and change the encryption level. | 422 // and change the encryption level. |
| 424 packet_.packet_number_length = retransmission.packet_number_length; | 423 packet_.packet_number_length = retransmission.packet_number_length; |
| 425 next_packet_number_length_ = retransmission.packet_number_length; | 424 next_packet_number_length_ = retransmission.packet_number_length; |
| 426 fec_protect_ = false; | 425 fec_protect_ = false; |
| 427 packet_.needs_padding = retransmission.needs_padding; | 426 packet_.needs_padding = retransmission.needs_padding; |
| 428 // Only preserve the original encryption level if it's a handshake packet or | 427 // Only preserve the original encryption level if it's a handshake packet or |
| 429 // if we haven't gone forward secure. | 428 // if we haven't gone forward secure. |
| 430 if (retransmission.has_crypto_handshake || | 429 if (retransmission.has_crypto_handshake || |
| 431 packet_.encryption_level != ENCRYPTION_FORWARD_SECURE) { | 430 packet_.encryption_level != ENCRYPTION_FORWARD_SECURE) { |
| 432 packet_.encryption_level = retransmission.encryption_level; | 431 packet_.encryption_level = retransmission.encryption_level; |
| 433 } | 432 } |
| 434 | 433 |
| 435 // Serialize the packet and restore the FEC and packet number length state. | 434 // Serialize the packet and restore the FEC and packet number length state. |
| 436 for (const QuicFrame& frame : retransmission.retransmittable_frames) { | 435 for (const QuicFrame& frame : retransmission.retransmittable_frames) { |
| 437 bool success = AddFrame(frame, false); | 436 bool success = AddFrame(frame, false); |
| 438 DCHECK(success); | 437 DCHECK(success); |
| 439 } | 438 } |
| 440 SerializePacket(buffer, buffer_len); | 439 SerializePacket(buffer, buffer_len); |
| 441 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 440 packet_.original_packet_number = retransmission.packet_number; |
| 442 packet_.original_packet_number = retransmission.packet_number; | 441 packet_.transmission_type = retransmission.transmission_type; |
| 443 packet_.transmission_type = retransmission.transmission_type; | 442 OnSerializedPacket(); |
| 444 OnSerializedPacket(); | 443 // Restore old values. |
| 445 // Restore old values. | 444 packet_.packet_number_length = saved_length; |
| 446 packet_.packet_number_length = saved_length; | 445 next_packet_number_length_ = saved_next_length; |
| 447 next_packet_number_length_ = saved_next_length; | 446 fec_protect_ = saved_should_fec_protect; |
| 448 fec_protect_ = saved_should_fec_protect; | 447 packet_.encryption_level = default_encryption_level; |
| 449 packet_.encryption_level = default_encryption_level; | |
| 450 return NoPacket(); | |
| 451 } else { | |
| 452 SerializedPacket packet_copy = packet_; | |
| 453 ClearPacket(); | |
| 454 // Restore old values. | |
| 455 packet_.needs_padding = saved_needs_padding; | |
| 456 packet_.packet_number_length = saved_length; | |
| 457 next_packet_number_length_ = saved_next_length; | |
| 458 fec_protect_ = saved_should_fec_protect; | |
| 459 packet_.encryption_level = default_encryption_level; | |
| 460 return packet_copy; | |
| 461 } | |
| 462 } | 448 } |
| 463 | 449 |
| 464 void QuicPacketCreator::Flush() { | 450 void QuicPacketCreator::Flush() { |
| 465 if (!HasPendingFrames()) { | 451 if (!HasPendingFrames()) { |
| 466 return; | 452 return; |
| 467 } | 453 } |
| 468 | 454 |
| 469 // TODO(rtenneti): Change the default 64 alignas value (used the default | 455 // TODO(rtenneti): Change the default 64 alignas value (used the default |
| 470 // value from CACHELINE_SIZE). | 456 // value from CACHELINE_SIZE). |
| 471 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize]; | 457 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize]; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; | 844 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; |
| 859 packet_.path_id = path_id; | 845 packet_.path_id = path_id; |
| 860 DCHECK(packet_.path_id != kInvalidPathId); | 846 DCHECK(packet_.path_id != kInvalidPathId); |
| 861 // Send path in packet if current path is not the default path. | 847 // Send path in packet if current path is not the default path. |
| 862 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; | 848 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; |
| 863 // Switching path needs to update packet number length. | 849 // Switching path needs to update packet number length. |
| 864 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); | 850 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); |
| 865 } | 851 } |
| 866 | 852 |
| 867 } // namespace net | 853 } // namespace net |
| OLD | NEW |