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/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" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 next_sequence_number_length_ = | 200 next_sequence_number_length_ = |
201 QuicFramer::GetMinSequenceNumberLength(delta * 4); | 201 QuicFramer::GetMinSequenceNumberLength(delta * 4); |
202 } | 202 } |
203 | 203 |
204 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, | 204 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, |
205 QuicStreamOffset offset) const { | 205 QuicStreamOffset offset) const { |
206 // TODO(jri): This is a simple safe decision for now, but make | 206 // TODO(jri): This is a simple safe decision for now, but make |
207 // is_in_fec_group a parameter. Same as with all public methods in | 207 // is_in_fec_group a parameter. Same as with all public methods in |
208 // QuicPacketCreator. | 208 // QuicPacketCreator. |
209 return BytesFree() > | 209 return BytesFree() > |
210 QuicFramer::GetMinStreamFrameSize(framer_->version(), id, offset, true, | 210 QuicFramer::GetMinStreamFrameSize(id, offset, true, |
211 should_fec_protect_ ? IN_FEC_GROUP : | 211 should_fec_protect_ ? IN_FEC_GROUP : |
212 NOT_IN_FEC_GROUP); | 212 NOT_IN_FEC_GROUP); |
213 } | 213 } |
214 | 214 |
215 // static | 215 // static |
216 size_t QuicPacketCreator::StreamFramePacketOverhead( | 216 size_t QuicPacketCreator::StreamFramePacketOverhead( |
217 QuicVersion version, | |
218 QuicConnectionIdLength connection_id_length, | 217 QuicConnectionIdLength connection_id_length, |
219 bool include_version, | 218 bool include_version, |
220 QuicSequenceNumberLength sequence_number_length, | 219 QuicSequenceNumberLength sequence_number_length, |
221 QuicStreamOffset offset, | 220 QuicStreamOffset offset, |
222 InFecGroup is_in_fec_group) { | 221 InFecGroup is_in_fec_group) { |
223 return GetPacketHeaderSize(connection_id_length, include_version, | 222 return GetPacketHeaderSize(connection_id_length, include_version, |
224 sequence_number_length, is_in_fec_group) + | 223 sequence_number_length, is_in_fec_group) + |
225 // Assumes this is a stream with a single lone packet. | 224 // Assumes this is a stream with a single lone packet. |
226 QuicFramer::GetMinStreamFrameSize(version, 1u, offset, true, | 225 QuicFramer::GetMinStreamFrameSize(1u, offset, true, is_in_fec_group); |
227 is_in_fec_group); | |
228 } | 226 } |
229 | 227 |
230 size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, | 228 size_t QuicPacketCreator::CreateStreamFrame(QuicStreamId id, |
231 const IOVector& data, | 229 const IOVector& data, |
232 QuicStreamOffset offset, | 230 QuicStreamOffset offset, |
233 bool fin, | 231 bool fin, |
234 QuicFrame* frame) { | 232 QuicFrame* frame) { |
235 DCHECK_GT(max_packet_length_, StreamFramePacketOverhead( | 233 DCHECK_GT(max_packet_length_, StreamFramePacketOverhead( |
236 framer_->version(), PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, | 234 PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, |
237 PACKET_6BYTE_SEQUENCE_NUMBER, offset, IN_FEC_GROUP)); | 235 PACKET_6BYTE_SEQUENCE_NUMBER, offset, IN_FEC_GROUP)); |
238 | 236 |
239 InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec(); | 237 InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec(); |
240 | 238 |
241 LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset)) | 239 LOG_IF(DFATAL, !HasRoomForStreamFrame(id, offset)) |
242 << "No room for Stream frame, BytesFree: " << BytesFree() | 240 << "No room for Stream frame, BytesFree: " << BytesFree() |
243 << " MinStreamFrameSize: " | 241 << " MinStreamFrameSize: " |
244 << QuicFramer::GetMinStreamFrameSize( | 242 << QuicFramer::GetMinStreamFrameSize(id, offset, true, is_in_fec_group); |
245 framer_->version(), id, offset, true, is_in_fec_group); | |
246 | 243 |
247 if (data.Empty()) { | 244 if (data.Empty()) { |
248 LOG_IF(DFATAL, !fin) | 245 LOG_IF(DFATAL, !fin) |
249 << "Creating a stream frame with no data or fin."; | 246 << "Creating a stream frame with no data or fin."; |
250 // Create a new packet for the fin, if necessary. | 247 // Create a new packet for the fin, if necessary. |
251 *frame = QuicFrame(new QuicStreamFrame(id, true, offset, data)); | 248 *frame = QuicFrame(new QuicStreamFrame(id, true, offset, data)); |
252 return 0; | 249 return 0; |
253 } | 250 } |
254 | 251 |
255 const size_t data_size = data.TotalBufferSize(); | 252 const size_t data_size = data.TotalBufferSize(); |
256 size_t min_frame_size = QuicFramer::GetMinStreamFrameSize( | 253 size_t min_frame_size = QuicFramer::GetMinStreamFrameSize( |
257 framer_->version(), id, offset, /*last_frame_in_packet=*/ true, | 254 id, offset, /* last_frame_in_packet= */ true, is_in_fec_group); |
258 is_in_fec_group); | |
259 size_t bytes_consumed = min<size_t>(BytesFree() - min_frame_size, data_size); | 255 size_t bytes_consumed = min<size_t>(BytesFree() - min_frame_size, data_size); |
260 | 256 |
261 bool set_fin = fin && bytes_consumed == data_size; // Last frame. | 257 bool set_fin = fin && bytes_consumed == data_size; // Last frame. |
262 IOVector frame_data; | 258 IOVector frame_data; |
263 frame_data.AppendIovecAtMostBytes(data.iovec(), data.Size(), | 259 frame_data.AppendIovecAtMostBytes(data.iovec(), data.Size(), |
264 bytes_consumed); | 260 bytes_consumed); |
265 DCHECK_EQ(frame_data.TotalBufferSize(), bytes_consumed); | 261 DCHECK_EQ(frame_data.TotalBufferSize(), bytes_consumed); |
266 *frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, frame_data)); | 262 *frame = QuicFrame(new QuicStreamFrame(id, set_fin, offset, frame_data)); |
267 return bytes_consumed; | 263 return bytes_consumed; |
268 } | 264 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 if (!is_handshake) { | 520 if (!is_handshake) { |
525 return; | 521 return; |
526 } | 522 } |
527 | 523 |
528 QuicPaddingFrame padding; | 524 QuicPaddingFrame padding; |
529 bool success = AddFrame(QuicFrame(&padding), false); | 525 bool success = AddFrame(QuicFrame(&padding), false); |
530 DCHECK(success); | 526 DCHECK(success); |
531 } | 527 } |
532 | 528 |
533 } // namespace net | 529 } // namespace net |
OLD | NEW |