| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id, | 84 QuicPacketCreator::QuicPacketCreator(QuicConnectionId connection_id, |
| 85 QuicFramer* framer, | 85 QuicFramer* framer, |
| 86 QuicRandom* random_generator, | 86 QuicRandom* random_generator, |
| 87 DelegateInterface* delegate) | 87 DelegateInterface* delegate) |
| 88 : delegate_(delegate), | 88 : delegate_(delegate), |
| 89 connection_id_(connection_id), | 89 connection_id_(connection_id), |
| 90 encryption_level_(ENCRYPTION_NONE), | 90 encryption_level_(ENCRYPTION_NONE), |
| 91 framer_(framer), | 91 framer_(framer), |
| 92 random_bool_source_(new QuicRandomBoolSource(random_generator)), | 92 random_bool_source_(new QuicRandomBoolSource(random_generator)), |
| 93 packet_number_(0), | 93 packet_number_(0), |
| 94 should_fec_protect_(false), | 94 should_fec_protect_next_packet_(false), |
| 95 fec_protect_(false), | 95 fec_protect_(false), |
| 96 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT), | 96 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT), |
| 97 max_packet_length_(0), | 97 max_packet_length_(0), |
| 98 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), | 98 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), |
| 99 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), | 99 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), |
| 100 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), | 100 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), |
| 101 packet_number_length_(next_packet_number_length_), | 101 packet_number_length_(next_packet_number_length_), |
| 102 packet_size_(0), | 102 packet_size_(0), |
| 103 needs_padding_(false), | 103 needs_padding_(false), |
| 104 fec_send_policy_(FEC_ANY_TRIGGER), | 104 fec_send_policy_(FEC_ANY_TRIGGER), |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 next_packet_number_length_ = | 244 next_packet_number_length_ = |
| 245 QuicFramer::GetMinSequenceNumberLength(delta * 4); | 245 QuicFramer::GetMinSequenceNumberLength(delta * 4); |
| 246 } | 246 } |
| 247 | 247 |
| 248 bool QuicPacketCreator::ConsumeData(QuicStreamId id, | 248 bool QuicPacketCreator::ConsumeData(QuicStreamId id, |
| 249 QuicIOVector iov, | 249 QuicIOVector iov, |
| 250 size_t iov_offset, | 250 size_t iov_offset, |
| 251 QuicStreamOffset offset, | 251 QuicStreamOffset offset, |
| 252 bool fin, | 252 bool fin, |
| 253 bool needs_padding, | 253 bool needs_padding, |
| 254 QuicFrame* frame) { | 254 QuicFrame* frame, |
| 255 FecProtection fec_protection) { |
| 255 if (!HasRoomForStreamFrame(id, offset)) { | 256 if (!HasRoomForStreamFrame(id, offset)) { |
| 256 Flush(); | 257 Flush(); |
| 257 return false; | 258 return false; |
| 258 } | 259 } |
| 259 | 260 |
| 260 UniqueStreamBuffer buffer; | 261 UniqueStreamBuffer buffer; |
| 262 if (fec_protection == MUST_FEC_PROTECT) { |
| 263 should_fec_protect_next_packet_ = true; |
| 264 MaybeStartFecProtection(); |
| 265 } |
| 261 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); | 266 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); |
| 262 | |
| 263 bool success = AddFrame(*frame, | 267 bool success = AddFrame(*frame, |
| 264 /*save_retransmittable_frames=*/true, needs_padding, | 268 /*save_retransmittable_frames=*/true, needs_padding, |
| 265 std::move(buffer)); | 269 std::move(buffer)); |
| 266 DCHECK(success); | 270 DCHECK(success); |
| 267 return true; | 271 return true; |
| 268 } | 272 } |
| 269 | 273 |
| 270 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, | 274 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, |
| 271 QuicStreamOffset offset) const { | 275 QuicStreamOffset offset) const { |
| 272 // TODO(jri): This is a simple safe decision for now, but make | 276 // TODO(jri): This is a simple safe decision for now, but make |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } else { | 759 } else { |
| 756 // TODO(zhongyi): Change the default 64 alignas value (used the default | 760 // TODO(zhongyi): Change the default 64 alignas value (used the default |
| 757 // value from CACHELINE_SIZE). | 761 // value from CACHELINE_SIZE). |
| 758 ALIGNAS(64) char seralized_fec_buffer[kMaxPacketSize]; | 762 ALIGNAS(64) char seralized_fec_buffer[kMaxPacketSize]; |
| 759 SerializedPacket serialized_fec = | 763 SerializedPacket serialized_fec = |
| 760 SerializeFec(seralized_fec_buffer, kMaxPacketSize); | 764 SerializeFec(seralized_fec_buffer, kMaxPacketSize); |
| 761 delegate_->OnSerializedPacket(&serialized_fec); | 765 delegate_->OnSerializedPacket(&serialized_fec); |
| 762 } | 766 } |
| 763 } | 767 } |
| 764 | 768 |
| 765 if (!should_fec_protect_ && fec_protect_ && !IsFecGroupOpen()) { | 769 if (!should_fec_protect_next_packet_ && fec_protect_ && !IsFecGroupOpen()) { |
| 766 StopFecProtectingPackets(); | 770 StopFecProtectingPackets(); |
| 767 } | 771 } |
| 768 } | 772 } |
| 769 | 773 |
| 770 QuicTime::Delta QuicPacketCreator::GetFecTimeout( | 774 QuicTime::Delta QuicPacketCreator::GetFecTimeout( |
| 771 QuicPacketNumber packet_number) { | 775 QuicPacketNumber packet_number) { |
| 772 // Do not set up FEC alarm for |packet_number| it is not the first packet in | 776 // Do not set up FEC alarm for |packet_number| it is not the first packet in |
| 773 // the current group. | 777 // the current group. |
| 774 if (fec_group_.get() != nullptr && | 778 if (fec_group_.get() != nullptr && |
| 775 (packet_number == fec_group_->FecGroupNumber())) { | 779 (packet_number == fec_group_->FecGroupNumber())) { |
| 776 return QuicTime::Delta::Max( | 780 return QuicTime::Delta::Max( |
| 777 fec_timeout_, QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs)); | 781 fec_timeout_, QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs)); |
| 778 } | 782 } |
| 779 return QuicTime::Delta::Infinite(); | 783 return QuicTime::Delta::Infinite(); |
| 780 } | 784 } |
| 781 | 785 |
| 782 void QuicPacketCreator::OnCongestionWindowChange( | 786 void QuicPacketCreator::OnCongestionWindowChange( |
| 783 QuicPacketCount max_packets_in_flight) { | 787 QuicPacketCount max_packets_in_flight) { |
| 784 set_max_packets_per_fec_group(static_cast<size_t>( | 788 set_max_packets_per_fec_group(static_cast<size_t>( |
| 785 kMaxPacketsInFlightMultiplierForFecGroupSize * max_packets_in_flight)); | 789 kMaxPacketsInFlightMultiplierForFecGroupSize * max_packets_in_flight)); |
| 786 } | 790 } |
| 787 | 791 |
| 788 void QuicPacketCreator::OnRttChange(QuicTime::Delta rtt) { | 792 void QuicPacketCreator::OnRttChange(QuicTime::Delta rtt) { |
| 789 fec_timeout_ = rtt.Multiply(rtt_multiplier_for_fec_timeout_); | 793 fec_timeout_ = rtt.Multiply(rtt_multiplier_for_fec_timeout_); |
| 790 } | 794 } |
| 791 | 795 |
| 792 } // namespace net | 796 } // namespace net |
| OLD | NEW |