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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "net/quic/crypto/quic_random.h" | 9 #include "net/quic/crypto/quic_random.h" |
10 #include "net/quic/quic_ack_notifier.h" | 10 #include "net/quic/quic_ack_notifier.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 void QuicPacketCreator::OnBuiltFecProtectedPayload( | 83 void QuicPacketCreator::OnBuiltFecProtectedPayload( |
84 const QuicPacketHeader& header, StringPiece payload) { | 84 const QuicPacketHeader& header, StringPiece payload) { |
85 if (fec_group_.get()) { | 85 if (fec_group_.get()) { |
86 DCHECK_NE(0u, header.fec_group); | 86 DCHECK_NE(0u, header.fec_group); |
87 fec_group_->Update(encryption_level_, header, payload); | 87 fec_group_->Update(encryption_level_, header, payload); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 bool QuicPacketCreator::ShouldSendFec(bool force_close) const { | 91 bool QuicPacketCreator::ShouldSendFec(bool force_close) const { |
| 92 DCHECK(!HasPendingFrames()); |
92 return fec_group_.get() != NULL && fec_group_->NumReceivedPackets() > 0 && | 93 return fec_group_.get() != NULL && fec_group_->NumReceivedPackets() > 0 && |
93 (force_close || fec_group_->NumReceivedPackets() >= | 94 (force_close || fec_group_->NumReceivedPackets() >= |
94 max_packets_per_fec_group_); | 95 max_packets_per_fec_group_); |
95 } | 96 } |
96 | 97 |
| 98 bool QuicPacketCreator::IsFecGroupOpen() const { |
| 99 return ShouldSendFec(true); |
| 100 } |
| 101 |
97 void QuicPacketCreator::StartFecProtectingPackets() { | 102 void QuicPacketCreator::StartFecProtectingPackets() { |
98 if (!IsFecEnabled()) { | 103 if (!IsFecEnabled()) { |
99 LOG(DFATAL) << "Cannot start FEC protection when FEC is not enabled."; | 104 LOG(DFATAL) << "Cannot start FEC protection when FEC is not enabled."; |
100 return; | 105 return; |
101 } | 106 } |
102 // TODO(jri): This currently requires that the generator flush out any | 107 // TODO(jri): This currently requires that the generator flush out any |
103 // pending frames when FEC protection is turned on. If current packet can be | 108 // pending frames when FEC protection is turned on. If current packet can be |
104 // converted to an FEC protected packet, do it. This will require the | 109 // converted to an FEC protected packet, do it. This will require the |
105 // generator to check if the resulting expansion still allows the incoming | 110 // generator to check if the resulting expansion still allows the incoming |
106 // frame to be added to the packet. | 111 // frame to be added to the packet. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 << "Attempt to serialize empty packet"; | 303 << "Attempt to serialize empty packet"; |
299 for (size_t i = 0; i < frames.size(); ++i) { | 304 for (size_t i = 0; i < frames.size(); ++i) { |
300 bool success = AddFrame(frames[i], false); | 305 bool success = AddFrame(frames[i], false); |
301 DCHECK(success); | 306 DCHECK(success); |
302 } | 307 } |
303 SerializedPacket packet = SerializePacket(); | 308 SerializedPacket packet = SerializePacket(); |
304 DCHECK(packet.retransmittable_frames == NULL); | 309 DCHECK(packet.retransmittable_frames == NULL); |
305 return packet; | 310 return packet; |
306 } | 311 } |
307 | 312 |
308 bool QuicPacketCreator::HasPendingFrames() { | 313 bool QuicPacketCreator::HasPendingFrames() const { |
309 return !queued_frames_.empty(); | 314 return !queued_frames_.empty(); |
310 } | 315 } |
311 | 316 |
312 size_t QuicPacketCreator::ExpansionOnNewFrame() const { | 317 size_t QuicPacketCreator::ExpansionOnNewFrame() const { |
313 // If packet is FEC protected, there's no expansion. | 318 // If packet is FEC protected, there's no expansion. |
314 if (should_fec_protect_) { | 319 if (should_fec_protect_) { |
315 return 0; | 320 return 0; |
316 } | 321 } |
317 // If the last frame in the packet is a stream frame, then it will expand to | 322 // If the last frame in the packet is a stream frame, then it will expand to |
318 // include the stream_length field when a new frame is added. | 323 // include the stream_length field when a new frame is added. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 if (!is_handshake) { | 505 if (!is_handshake) { |
501 return; | 506 return; |
502 } | 507 } |
503 | 508 |
504 QuicPaddingFrame padding; | 509 QuicPaddingFrame padding; |
505 bool success = AddFrame(QuicFrame(&padding), false); | 510 bool success = AddFrame(QuicFrame(&padding), false); |
506 DCHECK(success); | 511 DCHECK(success); |
507 } | 512 } |
508 | 513 |
509 } // namespace net | 514 } // namespace net |
OLD | NEW |