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

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

Issue 12806002: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor comment fix Created 7 years, 9 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_network_transaction_unittest.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_
11 11
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/string_piece.h" 16 #include "base/string_piece.h"
17 #include "net/quic/quic_fec_group.h" 17 #include "net/quic/quic_fec_group.h"
18 #include "net/quic/quic_framer.h" 18 #include "net/quic/quic_framer.h"
19 #include "net/quic/quic_protocol.h" 19 #include "net/quic/quic_protocol.h"
20 20
21 namespace net { 21 namespace net {
22 namespace test {
23 class QuicPacketCreatorPeer;
24 }
22 25
23 class QuicRandom; 26 class QuicRandom;
24 27
25 class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface { 28 class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface {
26 public: 29 public:
27 // Options for controlling how packets are created. 30 // Options for controlling how packets are created.
28 struct Options { 31 struct Options {
29 Options() 32 Options()
30 : max_packet_length(kMaxPacketSize), 33 : max_packet_length(kMaxPacketSize),
31 random_reorder(false), 34 random_reorder(false),
32 max_packets_per_fec_group(0) { 35 max_packets_per_fec_group(0) {
33 } 36 }
34 37
35 size_t max_packet_length; 38 size_t max_packet_length;
36 bool random_reorder; // Inefficient: rewrite if used at scale. 39 bool random_reorder; // Inefficient: rewrite if used at scale.
37 // 0 indicates fec is disabled. 40 // 0 indicates fec is disabled.
38 size_t max_packets_per_fec_group; 41 size_t max_packets_per_fec_group;
39 }; 42 };
40 43
41 // QuicRandom* required for packet entropy. 44 // QuicRandom* required for packet entropy.
42 QuicPacketCreator(QuicGuid guid, 45 QuicPacketCreator(QuicGuid guid,
43 QuicFramer* framer, 46 QuicFramer* framer,
44 QuicRandom* random_generator); 47 QuicRandom* random_generator,
48 bool is_server);
45 49
46 virtual ~QuicPacketCreator(); 50 virtual ~QuicPacketCreator();
47 51
48 // QuicFecBuilderInterface 52 // QuicFecBuilderInterface
49 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, 53 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header,
50 base::StringPiece payload) OVERRIDE; 54 base::StringPiece payload) OVERRIDE;
51 55
52 // Checks if it's time to send an FEC packet. |force_close| forces this to 56 // Checks if it's time to send an FEC packet. |force_close| forces this to
53 // return true if an fec group is open. 57 // return true if an fec group is open.
54 bool ShouldSendFec(bool force_close) const; 58 bool ShouldSendFec(bool force_close) const;
55 59
56 // Starts a new FEC group with the next serialized packet, if FEC is enabled 60 // Starts a new FEC group with the next serialized packet, if FEC is enabled
57 // and there is not already an FEC group open. 61 // and there is not already an FEC group open.
58 void MaybeStartFEC(); 62 void MaybeStartFEC();
59 63
64 // Makes the framer not serialize the protocol version in sent packets.
65 void StopSendingVersion();
66
60 // The overhead the framing will add for a packet with num_frames frames. 67 // The overhead the framing will add for a packet with num_frames frames.
61 static size_t StreamFramePacketOverhead(int num_frames, bool include_version); 68 static size_t StreamFramePacketOverhead(int num_frames, bool include_version);
62 69
63 bool HasRoomForStreamFrame() const; 70 bool HasRoomForStreamFrame() const;
64 71
65 // Converts a raw payload to a frame which fits into the currently open 72 // Converts a raw payload to a frame which fits into the currently open
66 // packet if there is one. Returns the number of bytes consumed from data. 73 // packet if there is one. Returns the number of bytes consumed from data.
67 // If data is empty and fin is true, the expected behavior is to consume the 74 // If data is empty and fin is true, the expected behavior is to consume the
68 // fin but return 0. 75 // fin but return 0.
69 size_t CreateStreamFrame(QuicStreamId id, 76 size_t CreateStreamFrame(QuicStreamId id,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // the entropy hash of the serialized packet to a random bool and returns 108 // the entropy hash of the serialized packet to a random bool and returns
102 // that value as a member of SerializedPacket. 109 // that value as a member of SerializedPacket.
103 SerializedPacket SerializeFec(); 110 SerializedPacket SerializeFec();
104 111
105 // Creates a packet with connection close frame. Caller owns the created 112 // Creates a packet with connection close frame. Caller owns the created
106 // packet. Also, sets the entropy hash of the serialized packet to a random 113 // packet. Also, sets the entropy hash of the serialized packet to a random
107 // bool and returns that value as a member of SerializedPacket. 114 // bool and returns that value as a member of SerializedPacket.
108 SerializedPacket SerializeConnectionClose( 115 SerializedPacket SerializeConnectionClose(
109 QuicConnectionCloseFrame* close_frame); 116 QuicConnectionCloseFrame* close_frame);
110 117
118 // Creates a version negotiation packet which supports |supported_versions|.
119 // Caller owns the created packet. Also, sets the entropy hash of the
120 // serialized packet to a random bool and returns that value as a member of
121 // SerializedPacket.
122 QuicEncryptedPacket* SerializeVersionNegotiationPacket(
123 const QuicVersionTagList& supported_versions);
124
111 QuicPacketSequenceNumber sequence_number() const { 125 QuicPacketSequenceNumber sequence_number() const {
112 return sequence_number_; 126 return sequence_number_;
113 } 127 }
114 128
115 void set_sequence_number(QuicPacketSequenceNumber s) { 129 void set_sequence_number(QuicPacketSequenceNumber s) {
116 sequence_number_ = s; 130 sequence_number_ = s;
117 } 131 }
118 132
119 Options* options() { 133 Options* options() {
120 return &options_; 134 return &options_;
121 } 135 }
122 136
123 private: 137 private:
138 friend class test::QuicPacketCreatorPeer;
139
124 static bool ShouldRetransmit(const QuicFrame& frame); 140 static bool ShouldRetransmit(const QuicFrame& frame);
125 141
126 void FillPacketHeader(QuicFecGroupNumber fec_group, 142 void FillPacketHeader(QuicFecGroupNumber fec_group,
127 bool fec_flag, 143 bool fec_flag,
128 bool fec_entropy_flag, 144 bool fec_entropy_flag,
129 QuicPacketHeader* header); 145 QuicPacketHeader* header);
130 146
131 // Allows a frame to be added without creating retransmittable frames. 147 // Allows a frame to be added without creating retransmittable frames.
132 // Particularly useful for retransmits using SerializeAllFrames(). 148 // Particularly useful for retransmits using SerializeAllFrames().
133 bool AddFrame(const QuicFrame& frame, bool save_retransmittable_frames); 149 bool AddFrame(const QuicFrame& frame, bool save_retransmittable_frames);
134 150
135 Options options_; 151 Options options_;
136 QuicGuid guid_; 152 QuicGuid guid_;
137 QuicFramer* framer_; 153 QuicFramer* framer_;
138 QuicRandom* random_generator_; 154 QuicRandom* random_generator_;
139 QuicPacketSequenceNumber sequence_number_; 155 QuicPacketSequenceNumber sequence_number_;
140 QuicFecGroupNumber fec_group_number_; 156 QuicFecGroupNumber fec_group_number_;
141 scoped_ptr<QuicFecGroup> fec_group_; 157 scoped_ptr<QuicFecGroup> fec_group_;
158 // bool to keep track if this packet creator is being used the server.
159 bool is_server_;
160 // Controls whether protocol version should be included while serializing the
161 // packet.
162 bool send_version_in_packet_;
142 size_t packet_size_; 163 size_t packet_size_;
143 QuicFrames queued_frames_; 164 QuicFrames queued_frames_;
144 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; 165 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_;
145 166
146 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); 167 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator);
147 }; 168 };
148 169
149 } // namespace net 170 } // namespace net
150 171
151 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ 172 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_
OLDNEW
« no previous file with comments | « net/quic/quic_network_transaction_unittest.cc ('k') | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698