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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 DCHECK(send_version_in_packet_); | 180 DCHECK(send_version_in_packet_); |
181 send_version_in_packet_ = false; | 181 send_version_in_packet_ = false; |
182 if (packet_size_ > 0) { | 182 if (packet_size_ > 0) { |
183 DCHECK_LT(kQuicVersionSize, packet_size_); | 183 DCHECK_LT(kQuicVersionSize, packet_size_); |
184 packet_size_ -= kQuicVersionSize; | 184 packet_size_ -= kQuicVersionSize; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 void QuicPacketCreator::UpdateSequenceNumberLength( | 188 void QuicPacketCreator::UpdateSequenceNumberLength( |
189 QuicPacketSequenceNumber least_packet_awaited_by_peer, | 189 QuicPacketSequenceNumber least_packet_awaited_by_peer, |
190 QuicByteCount congestion_window) { | 190 QuicPacketCount max_packets_in_flight) { |
191 DCHECK_LE(least_packet_awaited_by_peer, sequence_number_ + 1); | 191 DCHECK_LE(least_packet_awaited_by_peer, sequence_number_ + 1); |
192 // Since the packet creator will not change sequence number length mid FEC | 192 // Since the packet creator will not change sequence number length mid FEC |
193 // group, include the size of an FEC group to be safe. | 193 // group, include the size of an FEC group to be safe. |
194 const QuicPacketSequenceNumber current_delta = | 194 const QuicPacketSequenceNumber current_delta = |
195 max_packets_per_fec_group_ + sequence_number_ + 1 | 195 max_packets_per_fec_group_ + sequence_number_ + 1 |
196 - least_packet_awaited_by_peer; | 196 - least_packet_awaited_by_peer; |
197 const uint64 congestion_window_packets = | 197 const uint64 delta = max(current_delta, max_packets_in_flight); |
198 congestion_window / max_packet_length_; | |
199 const uint64 delta = max(current_delta, congestion_window_packets); | |
200 next_sequence_number_length_ = | 198 next_sequence_number_length_ = |
201 QuicFramer::GetMinSequenceNumberLength(delta * 4); | 199 QuicFramer::GetMinSequenceNumberLength(delta * 4); |
202 } | 200 } |
203 | 201 |
204 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, | 202 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, |
205 QuicStreamOffset offset) const { | 203 QuicStreamOffset offset) const { |
206 // TODO(jri): This is a simple safe decision for now, but make | 204 // TODO(jri): This is a simple safe decision for now, but make |
207 // is_in_fec_group a parameter. Same as with all public methods in | 205 // is_in_fec_group a parameter. Same as with all public methods in |
208 // QuicPacketCreator. | 206 // QuicPacketCreator. |
209 return BytesFree() > | 207 return BytesFree() > |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 queued_frames_.push_back( | 496 queued_frames_.push_back( |
499 queued_retransmittable_frames_->AddNonStreamFrame(frame)); | 497 queued_retransmittable_frames_->AddNonStreamFrame(frame)); |
500 } | 498 } |
501 } else { | 499 } else { |
502 queued_frames_.push_back(frame); | 500 queued_frames_.push_back(frame); |
503 } | 501 } |
504 return true; | 502 return true; |
505 } | 503 } |
506 | 504 |
507 void QuicPacketCreator::MaybeAddPadding() { | 505 void QuicPacketCreator::MaybeAddPadding() { |
508 if (queued_retransmittable_frames_.get() == nullptr) { | |
509 return; | |
510 } | |
511 if (!queued_retransmittable_frames_->HasCryptoHandshake()) { | |
512 return; | |
513 } | |
514 if (BytesFree() == 0) { | 506 if (BytesFree() == 0) { |
515 // Don't pad full packets. | 507 // Don't pad full packets. |
516 return; | 508 return; |
517 } | 509 } |
| 510 |
| 511 // Since ReserializeAllFrames does not populate queued_retransmittable_frames_ |
| 512 // it's not sufficient to simply call |
| 513 // queued_retransmittable_frames_->HasCryptoHandshake(). |
| 514 // TODO(rch): we should really make ReserializeAllFrames not be a special |
| 515 // case! |
| 516 |
| 517 // If any of the frames in the current packet are on the crypto stream |
| 518 // then they contain handshake messagses, and we should pad them. |
| 519 bool is_handshake = false; |
| 520 for (const QuicFrame& frame : queued_frames_) { |
| 521 if (frame.type == STREAM_FRAME && |
| 522 frame.stream_frame->stream_id == kCryptoStreamId) { |
| 523 is_handshake = true; |
| 524 break; |
| 525 } |
| 526 } |
| 527 if (!is_handshake) { |
| 528 return; |
| 529 } |
| 530 |
518 QuicPaddingFrame padding; | 531 QuicPaddingFrame padding; |
519 bool success = AddFrame(QuicFrame(&padding), false); | 532 bool success = AddFrame(QuicFrame(&padding), false); |
520 DCHECK(success); | 533 DCHECK(success); |
521 } | 534 } |
522 | 535 |
523 } // namespace net | 536 } // namespace net |
OLD | NEW |