Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: net/quic/quic_packet_creator.cc

Issue 399153003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added NET_EXPORT_PRIVATE Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_packet_creator.h ('k') | net/quic/quic_packet_creator_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "net/quic/quic_fec_group.h" 11 #include "net/quic/quic_fec_group.h"
12 #include "net/quic/quic_utils.h" 12 #include "net/quic/quic_utils.h"
13 13
14 using base::StringPiece; 14 using base::StringPiece;
15 using std::make_pair; 15 using std::make_pair;
16 using std::max; 16 using std::max;
17 using std::min; 17 using std::min;
18 using std::pair; 18 using std::pair;
19 using std::vector; 19 using std::vector;
20 20
21 namespace net { 21 namespace net {
22 22
23 namespace {
24
25 // Default max packets in an FEC group.
26 static const size_t kDefaultMaxPacketsPerFecGroup = 10;
27 // Lowest max packets in an FEC group.
28 static const size_t kLowestMaxPacketsPerFecGroup = 2;
29
30 } // namespace
31
23 // A QuicRandom wrapper that gets a bucket of entropy and distributes it 32 // A QuicRandom wrapper that gets a bucket of entropy and distributes it
24 // bit-by-bit. Replenishes the bucket as needed. Not thread-safe. Expose this 33 // bit-by-bit. Replenishes the bucket as needed. Not thread-safe. Expose this
25 // class if single bit randomness is needed elsewhere. 34 // class if single bit randomness is needed elsewhere.
26 class QuicRandomBoolSource { 35 class QuicRandomBoolSource {
27 public: 36 public:
28 // random: Source of entropy. Not owned. 37 // random: Source of entropy. Not owned.
29 explicit QuicRandomBoolSource(QuicRandom* random) 38 explicit QuicRandomBoolSource(QuicRandom* random)
30 : random_(random), 39 : random_(random),
31 bit_bucket_(0), 40 bit_bucket_(0),
32 bit_mask_(0) {} 41 bit_mask_(0) {}
(...skipping 27 matching lines...) Expand all
60 QuicRandom* random_generator) 69 QuicRandom* random_generator)
61 : connection_id_(connection_id), 70 : connection_id_(connection_id),
62 encryption_level_(ENCRYPTION_NONE), 71 encryption_level_(ENCRYPTION_NONE),
63 framer_(framer), 72 framer_(framer),
64 random_bool_source_(new QuicRandomBoolSource(random_generator)), 73 random_bool_source_(new QuicRandomBoolSource(random_generator)),
65 sequence_number_(0), 74 sequence_number_(0),
66 should_fec_protect_(false), 75 should_fec_protect_(false),
67 fec_group_number_(0), 76 fec_group_number_(0),
68 send_version_in_packet_(!framer->is_server()), 77 send_version_in_packet_(!framer->is_server()),
69 max_packet_length_(kDefaultMaxPacketSize), 78 max_packet_length_(kDefaultMaxPacketSize),
70 max_packets_per_fec_group_(kMaxPacketsPerFecGroup), 79 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup),
71 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), 80 connection_id_length_(PACKET_8BYTE_CONNECTION_ID),
72 next_sequence_number_length_(PACKET_1BYTE_SEQUENCE_NUMBER), 81 next_sequence_number_length_(PACKET_1BYTE_SEQUENCE_NUMBER),
73 sequence_number_length_(next_sequence_number_length_), 82 sequence_number_length_(next_sequence_number_length_),
74 packet_size_(0) { 83 packet_size_(0) {
75 framer_->set_fec_builder(this); 84 framer_->set_fec_builder(this);
76 } 85 }
77 86
78 QuicPacketCreator::~QuicPacketCreator() { 87 QuicPacketCreator::~QuicPacketCreator() {
79 } 88 }
80 89
81 void QuicPacketCreator::OnBuiltFecProtectedPayload( 90 void QuicPacketCreator::OnBuiltFecProtectedPayload(
82 const QuicPacketHeader& header, StringPiece payload) { 91 const QuicPacketHeader& header, StringPiece payload) {
83 if (fec_group_.get()) { 92 if (fec_group_.get()) {
84 DCHECK_NE(0u, header.fec_group); 93 DCHECK_NE(0u, header.fec_group);
85 fec_group_->Update(encryption_level_, header, payload); 94 fec_group_->Update(encryption_level_, header, payload);
86 } 95 }
87 } 96 }
88 97
98 void QuicPacketCreator::set_max_packets_per_fec_group(
99 size_t max_packets_per_fec_group) {
100 max_packets_per_fec_group_ = max(kLowestMaxPacketsPerFecGroup,
101 max_packets_per_fec_group);
102 DCHECK_LT(0u, max_packets_per_fec_group_);
103 }
104
89 bool QuicPacketCreator::ShouldSendFec(bool force_close) const { 105 bool QuicPacketCreator::ShouldSendFec(bool force_close) const {
90 DCHECK(!HasPendingFrames()); 106 DCHECK(!HasPendingFrames());
91 return fec_group_.get() != NULL && fec_group_->NumReceivedPackets() > 0 && 107 return fec_group_.get() != NULL && fec_group_->NumReceivedPackets() > 0 &&
92 (force_close || fec_group_->NumReceivedPackets() >= 108 (force_close || fec_group_->NumReceivedPackets() >=
93 max_packets_per_fec_group_); 109 max_packets_per_fec_group_);
94 } 110 }
95 111
96 bool QuicPacketCreator::IsFecGroupOpen() const { 112 bool QuicPacketCreator::IsFecGroupOpen() const {
97 return ShouldSendFec(true); 113 return fec_group_.get() != NULL;
98 } 114 }
99 115
100 void QuicPacketCreator::StartFecProtectingPackets() { 116 void QuicPacketCreator::StartFecProtectingPackets() {
101 if (!IsFecEnabled()) { 117 if (!IsFecEnabled()) {
102 LOG(DFATAL) << "Cannot start FEC protection when FEC is not enabled."; 118 LOG(DFATAL) << "Cannot start FEC protection when FEC is not enabled.";
103 return; 119 return;
104 } 120 }
105 // TODO(jri): This currently requires that the generator flush out any 121 // TODO(jri): This currently requires that the generator flush out any
106 // pending frames when FEC protection is turned on. If current packet can be 122 // pending frames when FEC protection is turned on. If current packet can be
107 // converted to an FEC protected packet, do it. This will require the 123 // converted to an FEC protected packet, do it. This will require the
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if (!is_handshake) { 524 if (!is_handshake) {
509 return; 525 return;
510 } 526 }
511 527
512 QuicPaddingFrame padding; 528 QuicPaddingFrame padding;
513 bool success = AddFrame(QuicFrame(&padding), false); 529 bool success = AddFrame(QuicFrame(&padding), false);
514 DCHECK(success); 530 DCHECK(success);
515 } 531 }
516 532
517 } // namespace net 533 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.h ('k') | net/quic/quic_packet_creator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698