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

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

Issue 312553003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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_framer_test.cc ('k') | net/quic/quic_packet_creator.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 // Accumulates frames for the next packet until more frames no longer fit or 5 // Accumulates frames for the next packet until more frames no longer fit or
6 // it's time to create a packet from them. Also provides packet creation of 6 // it's time to create a packet from them. Also provides packet creation of
7 // FEC packets based on previously created packets. 7 // FEC packets based on previously created packets.
8 8
9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_ 9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_
10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_ 10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_
(...skipping 11 matching lines...) Expand all
22 namespace test { 22 namespace test {
23 class QuicPacketCreatorPeer; 23 class QuicPacketCreatorPeer;
24 } 24 }
25 25
26 class QuicAckNotifier; 26 class QuicAckNotifier;
27 class QuicRandom; 27 class QuicRandom;
28 class QuicRandomBoolSource; 28 class QuicRandomBoolSource;
29 29
30 class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface { 30 class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface {
31 public: 31 public:
32 // Options for controlling how packets are created.
33 struct Options {
34 Options()
35 : max_packet_length(kDefaultMaxPacketSize),
36 max_packets_per_fec_group(0),
37 send_connection_id_length(PACKET_8BYTE_CONNECTION_ID),
38 send_sequence_number_length(PACKET_1BYTE_SEQUENCE_NUMBER) {}
39
40 size_t max_packet_length;
41 // 0 indicates fec is disabled.
42 size_t max_packets_per_fec_group;
43 // Length of connection_id to send over the wire.
44 QuicConnectionIdLength send_connection_id_length;
45 QuicSequenceNumberLength send_sequence_number_length;
46 };
47
48 // QuicRandom* required for packet entropy. 32 // QuicRandom* required for packet entropy.
49 QuicPacketCreator(QuicConnectionId connection_id, 33 QuicPacketCreator(QuicConnectionId connection_id,
50 QuicFramer* framer, 34 QuicFramer* framer,
51 QuicRandom* random_generator, 35 QuicRandom* random_generator,
52 bool is_server); 36 bool is_server);
53 37
54 virtual ~QuicPacketCreator(); 38 virtual ~QuicPacketCreator();
55 39
56 // QuicFecBuilderInterface 40 // QuicFecBuilderInterface
57 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, 41 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header,
58 base::StringPiece payload) OVERRIDE; 42 base::StringPiece payload) OVERRIDE;
59 43
60 // Turn on FEC protection for subsequently created packets. FEC should be 44 // Turn on FEC protection for subsequently created packets. FEC should be
61 // enabled first (max_packets_per_fec_group should be non-zero) for FEC 45 // enabled first (max_packets_per_fec_group should be non-zero) for FEC
62 // protection to start. 46 // protection to start.
63 void StartFecProtectingPackets(); 47 void StartFecProtectingPackets();
64 48
65 // Turn off FEC protection for subsequently created packets. If the creator 49 // Turn off FEC protection for subsequently created packets. If the creator
66 // has any open fec group, call will fail. It is the caller's responsibility 50 // has any open FEC group, call will fail. It is the caller's responsibility
67 // to flush out FEC packets in generation, and to verify with ShouldSendFec() 51 // to flush out FEC packets in generation, and to verify with ShouldSendFec()
68 // that there is no open FEC group. 52 // that there is no open FEC group.
69 void StopFecProtectingPackets(); 53 void StopFecProtectingPackets();
70 54
71 // Checks if it's time to send an FEC packet. |force_close| forces this to 55 // Checks if it's time to send an FEC packet. |force_close| forces this to
72 // return true if an fec group is open. 56 // return true if an FEC group is open.
73 bool ShouldSendFec(bool force_close) const; 57 bool ShouldSendFec(bool force_close) const;
74 58
75 // Returns current max number of packets covered by an FEC group.
76 size_t max_packets_per_fec_group() const;
77
78 // Sets creator's max number of packets covered by an FEC group.
79 void set_max_packets_per_fec_group(size_t max_packets_per_fec_group);
80
81 // Makes the framer not serialize the protocol version in sent packets. 59 // Makes the framer not serialize the protocol version in sent packets.
82 void StopSendingVersion(); 60 void StopSendingVersion();
83 61
84 // Update the sequence number length to use in future packets as soon as it 62 // Update the sequence number length to use in future packets as soon as it
85 // can be safely changed. 63 // can be safely changed.
86 void UpdateSequenceNumberLength( 64 void UpdateSequenceNumberLength(
87 QuicPacketSequenceNumber least_packet_awaited_by_peer, 65 QuicPacketSequenceNumber least_packet_awaited_by_peer,
88 QuicByteCount congestion_window); 66 QuicByteCount congestion_window);
89 67
90 // The overhead the framing will add for a packet with one frame. 68 // The overhead the framing will add for a packet with one frame.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // Sequence number of the last created packet, or 0 if no packets have been 184 // Sequence number of the last created packet, or 0 if no packets have been
207 // created. 185 // created.
208 QuicPacketSequenceNumber sequence_number() const { 186 QuicPacketSequenceNumber sequence_number() const {
209 return sequence_number_; 187 return sequence_number_;
210 } 188 }
211 189
212 void set_sequence_number(QuicPacketSequenceNumber s) { 190 void set_sequence_number(QuicPacketSequenceNumber s) {
213 sequence_number_ = s; 191 sequence_number_ = s;
214 } 192 }
215 193
216 Options* options() { 194 QuicConnectionIdLength connection_id_length() const {
217 return &options_; 195 return connection_id_length_;
196 }
197
198 QuicSequenceNumberLength next_sequence_number_length() const {
199 return next_sequence_number_length_;
200 }
201
202 void set_next_sequence_number_length(QuicSequenceNumberLength length) {
203 next_sequence_number_length_ = length;
204 }
205
206 size_t max_packet_length() const {
207 return max_packet_length_;
208 }
209
210 void set_max_packet_length(size_t length) {
211 // |max_packet_length_| should not be changed mid-packet or mid-FEC group.
212 DCHECK(fec_group_.get() == NULL && queued_frames_.empty());
213 max_packet_length_ = length;
214 }
215
216 // Returns current max number of packets covered by an FEC group.
217 size_t max_packets_per_fec_group() const {
218 return max_packets_per_fec_group_;
219 }
220
221 // Sets creator's max number of packets covered by an FEC group.
222 void set_max_packets_per_fec_group(
223 size_t max_packets_per_fec_group) {
224 // To turn off FEC protection, use StopFecProtectingPackets().
225 DCHECK_NE(0u, max_packets_per_fec_group);
226 max_packets_per_fec_group_ = max_packets_per_fec_group;
218 } 227 }
219 228
220 private: 229 private:
221 friend class test::QuicPacketCreatorPeer; 230 friend class test::QuicPacketCreatorPeer;
222 231
223 static bool ShouldRetransmit(const QuicFrame& frame); 232 static bool ShouldRetransmit(const QuicFrame& frame);
224 233
225 // Updates sequence number length on a packet or FEC group boundary. 234 // Updates sequence number and max packet lengths on a packet or FEC group
226 // Also starts an FEC group if FEC protection is on and there is not already 235 // boundary.
227 // an FEC group open. 236 void MaybeUpdateLengths();
237
238 // Updates lengths and also starts an FEC group if FEC protection is on and
239 // there is not already an FEC group open.
228 InFecGroup MaybeUpdateLengthsAndStartFec(); 240 InFecGroup MaybeUpdateLengthsAndStartFec();
229 241
230 void FillPacketHeader(QuicFecGroupNumber fec_group, 242 void FillPacketHeader(QuicFecGroupNumber fec_group,
231 bool fec_flag, 243 bool fec_flag,
232 QuicPacketHeader* header); 244 QuicPacketHeader* header);
233 245
234 // Allows a frame to be added without creating retransmittable frames. 246 // Allows a frame to be added without creating retransmittable frames.
235 // Particularly useful for retransmits using SerializeAllFrames(). 247 // Particularly useful for retransmits using SerializeAllFrames().
236 bool AddFrame(const QuicFrame& frame, bool save_retransmittable_frames); 248 bool AddFrame(const QuicFrame& frame, bool save_retransmittable_frames);
237 249
238 // Adds a padding frame to the current packet only if the current packet 250 // Adds a padding frame to the current packet only if the current packet
239 // contains a handshake message, and there is sufficient room to fit a 251 // contains a handshake message, and there is sufficient room to fit a
240 // padding frame. 252 // padding frame.
241 void MaybeAddPadding(); 253 void MaybeAddPadding();
242 254
243 Options options_;
244 QuicConnectionId connection_id_; 255 QuicConnectionId connection_id_;
245 EncryptionLevel encryption_level_; 256 EncryptionLevel encryption_level_;
246 QuicFramer* framer_; 257 QuicFramer* framer_;
247 scoped_ptr<QuicRandomBoolSource> random_bool_source_; 258 scoped_ptr<QuicRandomBoolSource> random_bool_source_;
248 QuicPacketSequenceNumber sequence_number_; 259 QuicPacketSequenceNumber sequence_number_;
249 // If true, any created packets will be FEC protected. 260 // If true, any created packets will be FEC protected.
250 bool should_fec_protect_; 261 bool should_fec_protect_;
251 QuicFecGroupNumber fec_group_number_; 262 QuicFecGroupNumber fec_group_number_;
252 scoped_ptr<QuicFecGroup> fec_group_; 263 scoped_ptr<QuicFecGroup> fec_group_;
253 // bool to keep track if this packet creator is being used the server. 264 // bool to keep track if this packet creator is being used the server.
254 bool is_server_; 265 bool is_server_;
255 // Controls whether protocol version should be included while serializing the 266 // Controls whether protocol version should be included while serializing the
256 // packet. 267 // packet.
257 bool send_version_in_packet_; 268 bool send_version_in_packet_;
258 // The sequence number length for the current packet and the current FEC group 269 // Maximum length including headers and encryption (UDP payload length.)
259 // if FEC is enabled. 270 size_t max_packet_length_;
260 // Mutable so PacketSize() can adjust it when the packet is empty. 271 // 0 indicates FEC is disabled.
272 size_t max_packets_per_fec_group_;
273 // Length of connection_id to send over the wire.
274 QuicConnectionIdLength connection_id_length_;
275 // Staging variable to hold next packet sequence number length. When sequence
276 // number length is to be changed, this variable holds the new length until
277 // a packet or FEC group boundary, when the creator's sequence_number_length_
278 // can be changed to this new value.
279 QuicSequenceNumberLength next_sequence_number_length_;
280 // Sequence number length for the current packet and for the current FEC group
281 // when FEC is enabled. Mutable so PacketSize() can adjust it when the packet
282 // is empty.
261 mutable QuicSequenceNumberLength sequence_number_length_; 283 mutable QuicSequenceNumberLength sequence_number_length_;
262 // packet_size_ is mutable because it's just a cache of the current size. 284 // packet_size_ is mutable because it's just a cache of the current size.
263 // packet_size should never be read directly, use PacketSize() instead. 285 // packet_size should never be read directly, use PacketSize() instead.
264 mutable size_t packet_size_; 286 mutable size_t packet_size_;
265 QuicFrames queued_frames_; 287 QuicFrames queued_frames_;
266 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; 288 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_;
267 289
268 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); 290 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator);
269 }; 291 };
270 292
271 } // namespace net 293 } // namespace net
272 294
273 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ 295 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_
OLDNEW
« no previous file with comments | « net/quic/quic_framer_test.cc ('k') | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698