| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), | 95 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), |
| 96 max_packet_length_(0), | 96 max_packet_length_(0), |
| 97 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), | 97 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), |
| 98 packet_size_(0), | 98 packet_size_(0), |
| 99 connection_id_(connection_id), | 99 connection_id_(connection_id), |
| 100 packet_(kDefaultPathId, | 100 packet_(kDefaultPathId, |
| 101 0, | 101 0, |
| 102 next_packet_number_length_, | 102 next_packet_number_length_, |
| 103 nullptr, | 103 nullptr, |
| 104 0, | 104 0, |
| 105 nullptr, | |
| 106 false, | 105 false, |
| 107 false), | 106 false), |
| 108 should_fec_protect_next_packet_(false), | 107 should_fec_protect_next_packet_(false), |
| 109 fec_protect_(false), | 108 fec_protect_(false), |
| 110 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), | 109 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), |
| 111 fec_send_policy_(FEC_ANY_TRIGGER), | 110 fec_send_policy_(FEC_ANY_TRIGGER), |
| 112 fec_timeout_(QuicTime::Delta::Zero()), | 111 fec_timeout_(QuicTime::Delta::Zero()), |
| 113 rtt_multiplier_for_fec_timeout_(kRttMultiplierForFecTimeout) { | 112 rtt_multiplier_for_fec_timeout_(kRttMultiplierForFecTimeout) { |
| 114 SetMaxPacketLength(kDefaultMaxPacketSize); | 113 SetMaxPacketLength(kDefaultMaxPacketSize); |
| 115 } | 114 } |
| 116 | 115 |
| 117 QuicPacketCreator::~QuicPacketCreator() { | 116 QuicPacketCreator::~QuicPacketCreator() { |
| 118 if (packet_.retransmittable_frames != nullptr) { | 117 QuicUtils::DeleteFrames(&packet_.retransmittable_frames); |
| 119 QuicUtils::DeleteFrames(packet_.retransmittable_frames); | |
| 120 delete packet_.retransmittable_frames; | |
| 121 } | |
| 122 if (packet_.packet != nullptr) { | 118 if (packet_.packet != nullptr) { |
| 123 delete packet_.packet; | 119 delete packet_.packet; |
| 124 } | 120 } |
| 125 } | 121 } |
| 126 | 122 |
| 127 void QuicPacketCreator::OnBuiltFecProtectedPayload( | 123 void QuicPacketCreator::OnBuiltFecProtectedPayload( |
| 128 const QuicPacketHeader& header, | 124 const QuicPacketHeader& header, |
| 129 StringPiece payload) { | 125 StringPiece payload) { |
| 130 if (fec_group_.get() != nullptr) { | 126 if (fec_group_.get() != nullptr) { |
| 131 DCHECK_NE(0u, header.fec_group); | 127 DCHECK_NE(0u, header.fec_group); |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 496 |
| 501 void QuicPacketCreator::ClearPacket() { | 497 void QuicPacketCreator::ClearPacket() { |
| 502 packet_.has_ack = false; | 498 packet_.has_ack = false; |
| 503 packet_.has_stop_waiting = false; | 499 packet_.has_stop_waiting = false; |
| 504 packet_.has_crypto_handshake = NOT_HANDSHAKE; | 500 packet_.has_crypto_handshake = NOT_HANDSHAKE; |
| 505 packet_.needs_padding = false; | 501 packet_.needs_padding = false; |
| 506 packet_.is_fec_packet = false; | 502 packet_.is_fec_packet = false; |
| 507 packet_.original_packet_number = 0; | 503 packet_.original_packet_number = 0; |
| 508 packet_.transmission_type = NOT_RETRANSMISSION; | 504 packet_.transmission_type = NOT_RETRANSMISSION; |
| 509 packet_.packet = nullptr; | 505 packet_.packet = nullptr; |
| 510 packet_.retransmittable_frames = nullptr; | 506 DCHECK(packet_.retransmittable_frames.empty()); |
| 511 packet_.listeners.clear(); | 507 packet_.listeners.clear(); |
| 512 } | 508 } |
| 513 | 509 |
| 514 bool QuicPacketCreator::HasPendingFrames() const { | 510 bool QuicPacketCreator::HasPendingFrames() const { |
| 515 return !queued_frames_.empty(); | 511 return !queued_frames_.empty(); |
| 516 } | 512 } |
| 517 | 513 |
| 518 bool QuicPacketCreator::HasPendingRetransmittableFrames() const { | 514 bool QuicPacketCreator::HasPendingRetransmittableFrames() const { |
| 519 return packet_.retransmittable_frames != nullptr && | 515 return !packet_.retransmittable_frames.empty(); |
| 520 !packet_.retransmittable_frames->empty(); | |
| 521 } | 516 } |
| 522 | 517 |
| 523 size_t QuicPacketCreator::ExpansionOnNewFrame() const { | 518 size_t QuicPacketCreator::ExpansionOnNewFrame() const { |
| 524 // If packet is FEC protected, there's no expansion. | 519 // If packet is FEC protected, there's no expansion. |
| 525 if (fec_protect_) { | 520 if (fec_protect_) { |
| 526 return 0; | 521 return 0; |
| 527 } | 522 } |
| 528 // If the last frame in the packet is a stream frame, then it will expand to | 523 // If the last frame in the packet is a stream frame, then it will expand to |
| 529 // include the stream_length field when a new frame is added. | 524 // include the stream_length field when a new frame is added. |
| 530 bool has_trailing_stream_frame = | 525 bool has_trailing_stream_frame = |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 QuicEncryptedPacket* encrypted = QuicFramer::BuildVersionNegotiationPacket( | 670 QuicEncryptedPacket* encrypted = QuicFramer::BuildVersionNegotiationPacket( |
| 676 connection_id_, supported_versions); | 671 connection_id_, supported_versions); |
| 677 DCHECK(encrypted); | 672 DCHECK(encrypted); |
| 678 DCHECK_GE(max_packet_length_, encrypted->length()); | 673 DCHECK_GE(max_packet_length_, encrypted->length()); |
| 679 return encrypted; | 674 return encrypted; |
| 680 } | 675 } |
| 681 | 676 |
| 682 // TODO(jri): Make this a public method of framer? | 677 // TODO(jri): Make this a public method of framer? |
| 683 SerializedPacket QuicPacketCreator::NoPacket() { | 678 SerializedPacket QuicPacketCreator::NoPacket() { |
| 684 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER, | 679 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER, |
| 685 nullptr, 0, nullptr, false, false); | 680 nullptr, 0, false, false); |
| 686 } | 681 } |
| 687 | 682 |
| 688 void QuicPacketCreator::FillPacketHeader(QuicFecGroupNumber fec_group, | 683 void QuicPacketCreator::FillPacketHeader(QuicFecGroupNumber fec_group, |
| 689 bool fec_flag, | 684 bool fec_flag, |
| 690 QuicPacketHeader* header) { | 685 QuicPacketHeader* header) { |
| 691 header->public_header.connection_id = connection_id_; | 686 header->public_header.connection_id = connection_id_; |
| 692 header->public_header.connection_id_length = connection_id_length_; | 687 header->public_header.connection_id_length = connection_id_length_; |
| 693 header->public_header.multipath_flag = send_path_id_in_packet_; | 688 header->public_header.multipath_flag = send_path_id_in_packet_; |
| 694 header->public_header.reset_flag = false; | 689 header->public_header.reset_flag = false; |
| 695 header->public_header.version_flag = send_version_in_packet_; | 690 header->public_header.version_flag = send_version_in_packet_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 packet_.packet_number_length); | 726 packet_.packet_number_length); |
| 732 if (frame_len == 0) { | 727 if (frame_len == 0) { |
| 733 // Current open packet is full. | 728 // Current open packet is full. |
| 734 Flush(); | 729 Flush(); |
| 735 return false; | 730 return false; |
| 736 } | 731 } |
| 737 DCHECK_LT(0u, packet_size_); | 732 DCHECK_LT(0u, packet_size_); |
| 738 packet_size_ += ExpansionOnNewFrame() + frame_len; | 733 packet_size_ += ExpansionOnNewFrame() + frame_len; |
| 739 | 734 |
| 740 if (save_retransmittable_frames && ShouldRetransmit(frame)) { | 735 if (save_retransmittable_frames && ShouldRetransmit(frame)) { |
| 741 if (packet_.retransmittable_frames == nullptr) { | 736 if (packet_.retransmittable_frames.empty()) { |
| 742 packet_.retransmittable_frames = new QuicFrames(); | 737 packet_.retransmittable_frames.reserve(2); |
| 743 packet_.retransmittable_frames->reserve(2); | |
| 744 } | 738 } |
| 745 packet_.retransmittable_frames->push_back(frame); | 739 packet_.retransmittable_frames.push_back(frame); |
| 746 queued_frames_.push_back(frame); | 740 queued_frames_.push_back(frame); |
| 747 if (frame.type == STREAM_FRAME && | 741 if (frame.type == STREAM_FRAME && |
| 748 frame.stream_frame->stream_id == kCryptoStreamId) { | 742 frame.stream_frame->stream_id == kCryptoStreamId) { |
| 749 packet_.has_crypto_handshake = IS_HANDSHAKE; | 743 packet_.has_crypto_handshake = IS_HANDSHAKE; |
| 750 } | 744 } |
| 751 } else { | 745 } else { |
| 752 queued_frames_.push_back(frame); | 746 queued_frames_.push_back(frame); |
| 753 } | 747 } |
| 754 | 748 |
| 755 if (frame.type == ACK_FRAME) { | 749 if (frame.type == ACK_FRAME) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; | 855 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; |
| 862 packet_.path_id = path_id; | 856 packet_.path_id = path_id; |
| 863 DCHECK(packet_.path_id != kInvalidPathId); | 857 DCHECK(packet_.path_id != kInvalidPathId); |
| 864 // Send path in packet if current path is not the default path. | 858 // Send path in packet if current path is not the default path. |
| 865 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; | 859 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; |
| 866 // Switching path needs to update packet number length. | 860 // Switching path needs to update packet number length. |
| 867 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); | 861 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); |
| 868 } | 862 } |
| 869 | 863 |
| 870 } // namespace net | 864 } // namespace net |
| OLD | NEW |