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 // 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 QuicFramer* framer, | 50 QuicFramer* framer, |
51 QuicRandom* random_generator, | 51 QuicRandom* random_generator, |
52 bool is_server); | 52 bool is_server); |
53 | 53 |
54 virtual ~QuicPacketCreator(); | 54 virtual ~QuicPacketCreator(); |
55 | 55 |
56 // QuicFecBuilderInterface | 56 // QuicFecBuilderInterface |
57 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, | 57 virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header, |
58 base::StringPiece payload) OVERRIDE; | 58 base::StringPiece payload) OVERRIDE; |
59 | 59 |
60 // Turn on FEC protection for subsequently created packets. FEC should | |
61 // be enabled first (set_max_packets_per_fec_group should be non-zero) for | |
wtc
2014/05/19 18:58:40
Typo: It seems that "set_max_packets_per_fec_group
ramant (doing other things)
2014/05/20 03:22:32
Done.
| |
62 // FEC protection to start. | |
63 void StartFecProtectingPackets(); | |
64 | |
65 // 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 | |
67 // to flush out FEC packets in generation, and to verify with ShouldSendFec() | |
68 // that there is no open FEC group. | |
69 void StopFecProtectingPackets(); | |
70 | |
60 // Checks if it's time to send an FEC packet. |force_close| forces this to | 71 // Checks if it's time to send an FEC packet. |force_close| forces this to |
61 // return true if an fec group is open. | 72 // return true if an fec group is open. |
62 bool ShouldSendFec(bool force_close) const; | 73 bool ShouldSendFec(bool force_close) const; |
63 | 74 |
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 | |
64 // Makes the framer not serialize the protocol version in sent packets. | 81 // Makes the framer not serialize the protocol version in sent packets. |
65 void StopSendingVersion(); | 82 void StopSendingVersion(); |
66 | 83 |
67 // Update the sequence number length to use in future packets as soon as it | 84 // Update the sequence number length to use in future packets as soon as it |
68 // can be safely changed. | 85 // can be safely changed. |
69 void UpdateSequenceNumberLength( | 86 void UpdateSequenceNumberLength( |
70 QuicPacketSequenceNumber least_packet_awaited_by_peer, | 87 QuicPacketSequenceNumber least_packet_awaited_by_peer, |
71 QuicByteCount congestion_window); | 88 QuicByteCount congestion_window); |
72 | 89 |
73 // The overhead the framing will add for a packet with one frame. | 90 // The overhead the framing will add for a packet with one frame. |
(...skipping 28 matching lines...) Expand all Loading... | |
102 QuicFrame* frame); | 119 QuicFrame* frame); |
103 | 120 |
104 // Serializes all frames into a single packet. All frames must fit into a | 121 // Serializes all frames into a single packet. All frames must fit into a |
105 // single packet. Also, sets the entropy hash of the serialized packet to a | 122 // single packet. Also, sets the entropy hash of the serialized packet to a |
106 // random bool and returns that value as a member of SerializedPacket. | 123 // random bool and returns that value as a member of SerializedPacket. |
107 // Never returns a RetransmittableFrames in SerializedPacket. | 124 // Never returns a RetransmittableFrames in SerializedPacket. |
108 SerializedPacket SerializeAllFrames(const QuicFrames& frames); | 125 SerializedPacket SerializeAllFrames(const QuicFrames& frames); |
109 | 126 |
110 // Re-serializes frames with the original packet's sequence number length. | 127 // Re-serializes frames with the original packet's sequence number length. |
111 // Used for retransmitting packets to ensure they aren't too long. | 128 // Used for retransmitting packets to ensure they aren't too long. |
129 // Caller must ensure that any open FEC group are closed before calling this | |
wtc
2014/05/19 18:58:40
Nit: the subject "any open FEC group" (singular) a
ramant (doing other things)
2014/05/20 03:22:32
Done.
| |
130 // method. | |
112 SerializedPacket ReserializeAllFrames( | 131 SerializedPacket ReserializeAllFrames( |
113 const QuicFrames& frames, QuicSequenceNumberLength original_length); | 132 const QuicFrames& frames, QuicSequenceNumberLength original_length); |
114 | 133 |
115 // Returns true if there are frames pending to be serialized. | 134 // Returns true if there are frames pending to be serialized. |
116 bool HasPendingFrames(); | 135 bool HasPendingFrames(); |
117 | 136 |
118 // Returns IN_FEC_GROUP or NOT_IN_FEC_GROUP, depending on whether FEC is | 137 // Returns whether FEC protection is currently enabled. Note: Enabled does not |
119 // enabled or not. Note: This does not mean that an FEC group is currently | 138 // mean that an FEC group is currently active; i.e., IsFecProtected() may |
120 // active; i.e., fec_group_.get() may still be NULL. | 139 // still return NOT_IN_FEC_GROUP, and fec_group_.get() may still be NULL. |
wtc
2014/05/19 18:58:40
Nit: "IsFecProtected() may still return NOT_IN_FEC
ramant (doing other things)
2014/05/20 03:22:32
jri and I went through the code and updated the co
| |
121 // TODO(jri): Straighten out naming: Enabling FEC for the connection | 140 bool IsFecEnabled() const; |
122 // should use FEC_ENABLED/DISABLED, and IN_FEC_GROUP/NOT_IN_FEC_GROUP should | 141 |
123 // be used if a given packet is in an fec group. | 142 // Returns true if subsequent packets will be FEC protected. Note: True does |
124 InFecGroup IsFecEnabled() const; | 143 // not mean that an FEC packet is currently under construction; i.e., |
144 // fec_group_.get() may still be NULL, until MaybeStartFec() is called. | |
145 bool IsFecProtected() const; | |
125 | 146 |
126 // Returns the number of bytes which are available to be used by additional | 147 // Returns the number of bytes which are available to be used by additional |
127 // frames in the packet. Since stream frames are slightly smaller when they | 148 // frames in the packet. Since stream frames are slightly smaller when they |
128 // are the last frame in a packet, this method will return a different | 149 // are the last frame in a packet, this method will return a different |
129 // value than max_packet_size - PacketSize(), in this case. | 150 // value than max_packet_size - PacketSize(), in this case. |
130 size_t BytesFree() const; | 151 size_t BytesFree() const; |
131 | 152 |
132 // Returns the number of bytes that the packet will expand by if a new frame | 153 // Returns the number of bytes that the packet will expand by if a new frame |
133 // is added to the packet. If the last frame was a stream frame, it will | 154 // is added to the packet. If the last frame was a stream frame, it will |
134 // expand slightly when a new frame is added, and this method returns the | 155 // expand slightly when a new frame is added, and this method returns the |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 return &options_; | 216 return &options_; |
196 } | 217 } |
197 | 218 |
198 private: | 219 private: |
199 friend class test::QuicPacketCreatorPeer; | 220 friend class test::QuicPacketCreatorPeer; |
200 | 221 |
201 static bool ShouldRetransmit(const QuicFrame& frame); | 222 static bool ShouldRetransmit(const QuicFrame& frame); |
202 | 223 |
203 // Starts a new FEC group with the next serialized packet, if FEC is enabled | 224 // Starts a new FEC group with the next serialized packet, if FEC is enabled |
204 // and there is not already an FEC group open. | 225 // and there is not already an FEC group open. |
205 InFecGroup MaybeStartFEC(); | 226 InFecGroup MaybeStartFec(); |
206 | 227 |
207 void FillPacketHeader(QuicFecGroupNumber fec_group, | 228 void FillPacketHeader(QuicFecGroupNumber fec_group, |
208 bool fec_flag, | 229 bool fec_flag, |
209 QuicPacketHeader* header); | 230 QuicPacketHeader* header); |
210 | 231 |
211 // Allows a frame to be added without creating retransmittable frames. | 232 // Allows a frame to be added without creating retransmittable frames. |
212 // Particularly useful for retransmits using SerializeAllFrames(). | 233 // Particularly useful for retransmits using SerializeAllFrames(). |
213 bool AddFrame(const QuicFrame& frame, bool save_retransmittable_frames); | 234 bool AddFrame(const QuicFrame& frame, bool save_retransmittable_frames); |
214 | 235 |
215 // Adds a padding frame to the current packet only if the current packet | 236 // Adds a padding frame to the current packet only if the current packet |
216 // contains a handshake message, and there is sufficient room to fit a | 237 // contains a handshake message, and there is sufficient room to fit a |
217 // padding frame. | 238 // padding frame. |
218 void MaybeAddPadding(); | 239 void MaybeAddPadding(); |
219 | 240 |
220 Options options_; | 241 Options options_; |
221 QuicConnectionId connection_id_; | 242 QuicConnectionId connection_id_; |
222 EncryptionLevel encryption_level_; | 243 EncryptionLevel encryption_level_; |
223 QuicFramer* framer_; | 244 QuicFramer* framer_; |
224 scoped_ptr<QuicRandomBoolSource> random_bool_source_; | 245 scoped_ptr<QuicRandomBoolSource> random_bool_source_; |
225 QuicPacketSequenceNumber sequence_number_; | 246 QuicPacketSequenceNumber sequence_number_; |
247 // If true, any created packets will be FEC protected. | |
248 bool should_fec_protect_; | |
226 QuicFecGroupNumber fec_group_number_; | 249 QuicFecGroupNumber fec_group_number_; |
227 scoped_ptr<QuicFecGroup> fec_group_; | 250 scoped_ptr<QuicFecGroup> fec_group_; |
228 // bool to keep track if this packet creator is being used the server. | 251 // bool to keep track if this packet creator is being used the server. |
229 bool is_server_; | 252 bool is_server_; |
230 // Controls whether protocol version should be included while serializing the | 253 // Controls whether protocol version should be included while serializing the |
231 // packet. | 254 // packet. |
232 bool send_version_in_packet_; | 255 bool send_version_in_packet_; |
233 // The sequence number length for the current packet and the current FEC group | 256 // The sequence number length for the current packet and the current FEC group |
234 // if FEC is enabled. | 257 // if FEC is enabled. |
235 // Mutable so PacketSize() can adjust it when the packet is empty. | 258 // Mutable so PacketSize() can adjust it when the packet is empty. |
236 mutable QuicSequenceNumberLength sequence_number_length_; | 259 mutable QuicSequenceNumberLength sequence_number_length_; |
237 // packet_size_ is mutable because it's just a cache of the current size. | 260 // packet_size_ is mutable because it's just a cache of the current size. |
238 // packet_size should never be read directly, use PacketSize() instead. | 261 // packet_size should never be read directly, use PacketSize() instead. |
239 mutable size_t packet_size_; | 262 mutable size_t packet_size_; |
240 QuicFrames queued_frames_; | 263 QuicFrames queued_frames_; |
241 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; | 264 scoped_ptr<RetransmittableFrames> queued_retransmittable_frames_; |
242 | 265 |
243 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); | 266 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); |
244 }; | 267 }; |
245 | 268 |
246 } // namespace net | 269 } // namespace net |
247 | 270 |
248 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ | 271 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ |
OLD | NEW |