| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/quic/crypto/quic_random.h" | 8 #include "net/quic/crypto/quic_random.h" |
| 9 #include "net/quic/quic_ack_notifier.h" | 9 #include "net/quic/quic_ack_notifier.h" |
| 10 #include "net/quic/quic_fec_group.h" | 10 #include "net/quic/quic_fec_group.h" |
| 11 #include "net/quic/quic_utils.h" | 11 #include "net/quic/quic_utils.h" |
| 12 | 12 |
| 13 using base::StringPiece; | 13 using base::StringPiece; |
| 14 using std::make_pair; | 14 using std::make_pair; |
| 15 using std::max; | 15 using std::max; |
| 16 using std::min; | 16 using std::min; |
| 17 using std::pair; | 17 using std::pair; |
| 18 using std::vector; | 18 using std::vector; |
| 19 | 19 |
| 20 // If true, then QUIC handshake packets will be padded to the maximium packet | |
| 21 // size. | |
| 22 bool FLAGS_pad_quic_handshake_packets = true; | |
| 23 | |
| 24 namespace net { | 20 namespace net { |
| 25 | 21 |
| 26 // A QuicRandom wrapper that gets a bucket of entropy and distributes it | 22 // A QuicRandom wrapper that gets a bucket of entropy and distributes it |
| 27 // bit-by-bit. Replenishes the bucket as needed. Not thread-safe. Expose this | 23 // bit-by-bit. Replenishes the bucket as needed. Not thread-safe. Expose this |
| 28 // class if single bit randomness is needed elsewhere. | 24 // class if single bit randomness is needed elsewhere. |
| 29 class QuicRandomBoolSource { | 25 class QuicRandomBoolSource { |
| 30 public: | 26 public: |
| 31 // random: Source of entropy. Not owned. | 27 // random: Source of entropy. Not owned. |
| 32 explicit QuicRandomBoolSource(QuicRandom* random) | 28 explicit QuicRandomBoolSource(QuicRandom* random) |
| 33 : random_(random), | 29 : random_(random), |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 return AddFrame(frame, true); | 309 return AddFrame(frame, true); |
| 314 } | 310 } |
| 315 | 311 |
| 316 SerializedPacket QuicPacketCreator::SerializePacket() { | 312 SerializedPacket QuicPacketCreator::SerializePacket() { |
| 317 if (queued_frames_.empty()) { | 313 if (queued_frames_.empty()) { |
| 318 LOG(DFATAL) << "Attempt to serialize empty packet"; | 314 LOG(DFATAL) << "Attempt to serialize empty packet"; |
| 319 } | 315 } |
| 320 QuicPacketHeader header; | 316 QuicPacketHeader header; |
| 321 FillPacketHeader(fec_group_number_, false, false, &header); | 317 FillPacketHeader(fec_group_number_, false, false, &header); |
| 322 | 318 |
| 323 if (FLAGS_pad_quic_handshake_packets) { | 319 MaybeAddPadding(); |
| 324 MaybeAddPadding(); | |
| 325 } | |
| 326 | 320 |
| 327 size_t max_plaintext_size = | 321 size_t max_plaintext_size = |
| 328 framer_->GetMaxPlaintextSize(options_.max_packet_length); | 322 framer_->GetMaxPlaintextSize(options_.max_packet_length); |
| 329 DCHECK_GE(max_plaintext_size, packet_size_); | 323 DCHECK_GE(max_plaintext_size, packet_size_); |
| 330 // ACK and CONNECTION_CLOSE Frames will be truncated only if they're | 324 // ACK and CONNECTION_CLOSE Frames will be truncated only if they're |
| 331 // the first frame in the packet. If truncation is to occur, then | 325 // the first frame in the packet. If truncation is to occur, then |
| 332 // GetSerializedFrameLength will have returned all bytes free. | 326 // GetSerializedFrameLength will have returned all bytes free. |
| 333 bool possibly_truncated = | 327 bool possibly_truncated = |
| 334 packet_size_ != max_plaintext_size || | 328 packet_size_ != max_plaintext_size || |
| 335 queued_frames_.size() != 1 || | 329 queued_frames_.size() != 1 || |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 if (!is_handshake) { | 470 if (!is_handshake) { |
| 477 return; | 471 return; |
| 478 } | 472 } |
| 479 | 473 |
| 480 QuicPaddingFrame padding; | 474 QuicPaddingFrame padding; |
| 481 bool success = AddFrame(QuicFrame(&padding), false); | 475 bool success = AddFrame(QuicFrame(&padding), false); |
| 482 DCHECK(success); | 476 DCHECK(success); |
| 483 } | 477 } |
| 484 | 478 |
| 485 } // namespace net | 479 } // namespace net |
| OLD | NEW |