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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 DelegateInterface* delegate) | 87 DelegateInterface* delegate) |
88 : delegate_(delegate), | 88 : delegate_(delegate), |
89 debug_delegate_(nullptr), | 89 debug_delegate_(nullptr), |
90 framer_(framer), | 90 framer_(framer), |
91 random_bool_source_(new QuicRandomBoolSource(random_generator)), | 91 random_bool_source_(new QuicRandomBoolSource(random_generator)), |
92 buffer_allocator_(buffer_allocator), | 92 buffer_allocator_(buffer_allocator), |
93 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT), | 93 send_version_in_packet_(framer->perspective() == Perspective::IS_CLIENT), |
94 send_path_id_in_packet_(false), | 94 send_path_id_in_packet_(false), |
95 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), | 95 next_packet_number_length_(PACKET_1BYTE_PACKET_NUMBER), |
96 max_packet_length_(0), | 96 max_packet_length_(0), |
| 97 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), |
| 98 packet_size_(0), |
97 connection_id_(connection_id), | 99 connection_id_(connection_id), |
98 encryption_level_(ENCRYPTION_NONE), | 100 packet_(kDefaultPathId, |
99 has_ack_(false), | 101 0, |
100 has_stop_waiting_(false), | 102 next_packet_number_length_, |
101 current_path_(kDefaultPathId), | 103 nullptr, |
102 packet_number_(0), | 104 0, |
103 connection_id_length_(PACKET_8BYTE_CONNECTION_ID), | 105 false, |
104 packet_number_length_(next_packet_number_length_), | 106 false), |
105 packet_size_(0), | |
106 needs_padding_(false), | |
107 has_crypto_handshake_(NOT_HANDSHAKE), | |
108 should_fec_protect_next_packet_(false), | 107 should_fec_protect_next_packet_(false), |
109 fec_protect_(false), | 108 fec_protect_(false), |
110 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), | 109 max_packets_per_fec_group_(kDefaultMaxPacketsPerFecGroup), |
111 fec_send_policy_(FEC_ANY_TRIGGER), | 110 fec_send_policy_(FEC_ANY_TRIGGER), |
112 fec_timeout_(QuicTime::Delta::Zero()), | 111 fec_timeout_(QuicTime::Delta::Zero()), |
113 rtt_multiplier_for_fec_timeout_(kRttMultiplierForFecTimeout) { | 112 rtt_multiplier_for_fec_timeout_(kRttMultiplierForFecTimeout) { |
114 SetMaxPacketLength(kDefaultMaxPacketSize); | 113 SetMaxPacketLength(kDefaultMaxPacketSize); |
115 } | 114 } |
116 | 115 |
117 QuicPacketCreator::~QuicPacketCreator() { | 116 QuicPacketCreator::~QuicPacketCreator() { |
118 if (queued_retransmittable_frames_.get() != nullptr) { | 117 QuicUtils::DeleteFrames(&packet_.retransmittable_frames); |
119 QuicUtils::DeleteFrames(queued_retransmittable_frames_.get()); | 118 if (packet_.packet != nullptr) { |
| 119 delete packet_.packet; |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 void QuicPacketCreator::OnBuiltFecProtectedPayload( | 123 void QuicPacketCreator::OnBuiltFecProtectedPayload( |
124 const QuicPacketHeader& header, | 124 const QuicPacketHeader& header, |
125 StringPiece payload) { | 125 StringPiece payload) { |
126 if (fec_group_.get() != nullptr) { | 126 if (fec_group_.get() != nullptr) { |
127 DCHECK_NE(0u, header.fec_group); | 127 DCHECK_NE(0u, header.fec_group); |
128 fec_group_->Update(encryption_level_, header, payload); | 128 fec_group_->Update(packet_.encryption_level, header, payload); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 void QuicPacketCreator::SetEncrypter(EncryptionLevel level, | 132 void QuicPacketCreator::SetEncrypter(EncryptionLevel level, |
133 QuicEncrypter* encrypter) { | 133 QuicEncrypter* encrypter) { |
134 framer_->SetEncrypter(level, encrypter); | 134 framer_->SetEncrypter(level, encrypter); |
135 max_plaintext_size_ = framer_->GetMaxPlaintextSize(max_packet_length_); | 135 max_plaintext_size_ = framer_->GetMaxPlaintextSize(max_packet_length_); |
136 } | 136 } |
137 | 137 |
138 bool QuicPacketCreator::CanSetMaxPacketLength() const { | 138 bool QuicPacketCreator::CanSetMaxPacketLength() const { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // Don't update any lengths when an FEC group is open, to ensure same | 212 // Don't update any lengths when an FEC group is open, to ensure same |
213 // packet header size in all packets within a group. | 213 // packet header size in all packets within a group. |
214 return IN_FEC_GROUP; | 214 return IN_FEC_GROUP; |
215 } | 215 } |
216 if (!queued_frames_.empty()) { | 216 if (!queued_frames_.empty()) { |
217 // Don't change creator state if there are frames queued. | 217 // Don't change creator state if there are frames queued. |
218 return NOT_IN_FEC_GROUP; | 218 return NOT_IN_FEC_GROUP; |
219 } | 219 } |
220 | 220 |
221 // Update packet number length only on packet and FEC group boundaries. | 221 // Update packet number length only on packet and FEC group boundaries. |
222 packet_number_length_ = next_packet_number_length_; | 222 packet_.packet_number_length = next_packet_number_length_; |
223 | 223 |
224 if (!fec_protect_) { | 224 if (!fec_protect_) { |
225 return NOT_IN_FEC_GROUP; | 225 return NOT_IN_FEC_GROUP; |
226 } | 226 } |
227 // Start a new FEC group since protection is on. Set the fec group number to | 227 // Start a new FEC group since protection is on. Set the fec group number to |
228 // the packet number of the next packet. | 228 // the packet number of the next packet. |
229 fec_group_.reset(new QuicFecGroup(packet_number_ + 1)); | 229 fec_group_.reset(new QuicFecGroup(packet_.packet_number + 1)); |
230 return IN_FEC_GROUP; | 230 return IN_FEC_GROUP; |
231 } | 231 } |
232 | 232 |
233 // Stops serializing version of the protocol in packets sent after this call. | 233 // Stops serializing version of the protocol in packets sent after this call. |
234 // A packet that is already open might send kQuicVersionSize bytes less than the | 234 // A packet that is already open might send kQuicVersionSize bytes less than the |
235 // maximum packet size if we stop sending version before it is serialized. | 235 // maximum packet size if we stop sending version before it is serialized. |
236 void QuicPacketCreator::StopSendingVersion() { | 236 void QuicPacketCreator::StopSendingVersion() { |
237 DCHECK(send_version_in_packet_); | 237 DCHECK(send_version_in_packet_); |
238 send_version_in_packet_ = false; | 238 send_version_in_packet_ = false; |
239 if (packet_size_ > 0) { | 239 if (packet_size_ > 0) { |
240 DCHECK_LT(kQuicVersionSize, packet_size_); | 240 DCHECK_LT(kQuicVersionSize, packet_size_); |
241 packet_size_ -= kQuicVersionSize; | 241 packet_size_ -= kQuicVersionSize; |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 void QuicPacketCreator::UpdatePacketNumberLength( | 245 void QuicPacketCreator::UpdatePacketNumberLength( |
246 QuicPacketNumber least_packet_awaited_by_peer, | 246 QuicPacketNumber least_packet_awaited_by_peer, |
247 QuicPacketCount max_packets_in_flight) { | 247 QuicPacketCount max_packets_in_flight) { |
248 DCHECK_LE(least_packet_awaited_by_peer, packet_number_ + 1); | 248 DCHECK_LE(least_packet_awaited_by_peer, packet_.packet_number + 1); |
249 // Since the packet creator will not change packet number length mid FEC | 249 // Since the packet creator will not change packet number length mid FEC |
250 // group, include the size of an FEC group to be safe. | 250 // group, include the size of an FEC group to be safe. |
251 const QuicPacketNumber current_delta = max_packets_per_fec_group_ + | 251 const QuicPacketNumber current_delta = max_packets_per_fec_group_ + |
252 packet_number_ + 1 - | 252 packet_.packet_number + 1 - |
253 least_packet_awaited_by_peer; | 253 least_packet_awaited_by_peer; |
254 const uint64_t delta = max(current_delta, max_packets_in_flight); | 254 const uint64_t delta = max(current_delta, max_packets_in_flight); |
255 next_packet_number_length_ = | 255 next_packet_number_length_ = |
256 QuicFramer::GetMinSequenceNumberLength(delta * 4); | 256 QuicFramer::GetMinSequenceNumberLength(delta * 4); |
257 } | 257 } |
258 | 258 |
259 bool QuicPacketCreator::ConsumeData(QuicStreamId id, | 259 bool QuicPacketCreator::ConsumeData(QuicStreamId id, |
260 QuicIOVector iov, | 260 QuicIOVector iov, |
261 size_t iov_offset, | 261 size_t iov_offset, |
262 QuicStreamOffset offset, | 262 QuicStreamOffset offset, |
263 bool fin, | 263 bool fin, |
264 bool needs_padding, | 264 bool needs_padding, |
265 QuicFrame* frame, | 265 QuicFrame* frame, |
266 FecProtection fec_protection) { | 266 FecProtection fec_protection) { |
267 if (!HasRoomForStreamFrame(id, offset)) { | 267 if (!HasRoomForStreamFrame(id, offset)) { |
268 return false; | 268 return false; |
269 } | 269 } |
270 if (fec_protection == MUST_FEC_PROTECT) { | 270 if (fec_protection == MUST_FEC_PROTECT) { |
271 should_fec_protect_next_packet_ = true; | 271 should_fec_protect_next_packet_ = true; |
272 MaybeStartFecProtection(); | 272 MaybeStartFecProtection(); |
273 } | 273 } |
274 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); | 274 CreateStreamFrame(id, iov, iov_offset, offset, fin, frame); |
275 if (!AddFrame(*frame, /*save_retransmittable_frames=*/true)) { | 275 if (!AddFrame(*frame, /*save_retransmittable_frames=*/true)) { |
276 // Fails if we try to write unencrypted stream data. | 276 // Fails if we try to write unencrypted stream data. |
277 delete frame->stream_frame; | 277 delete frame->stream_frame; |
278 return false; | 278 return false; |
279 } | 279 } |
280 if (needs_padding) { | 280 if (needs_padding) { |
281 needs_padding_ = true; | 281 packet_.needs_padding = true; |
282 } | 282 } |
283 if (fec_protection == MUST_FEC_PROTECT && | 283 if (fec_protection == MUST_FEC_PROTECT && |
284 iov_offset + frame->stream_frame->frame_length == iov.total_length) { | 284 iov_offset + frame->stream_frame->frame_length == iov.total_length) { |
285 // Turn off FEC protection when we're done writing protected data. | 285 // Turn off FEC protection when we're done writing protected data. |
286 DVLOG(1) << "Turning FEC protection OFF"; | 286 DVLOG(1) << "Turning FEC protection OFF"; |
287 should_fec_protect_next_packet_ = false; | 287 should_fec_protect_next_packet_ = false; |
288 } | 288 } |
289 return true; | 289 return true; |
290 } | 290 } |
291 | 291 |
292 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, | 292 bool QuicPacketCreator::HasRoomForStreamFrame(QuicStreamId id, |
293 QuicStreamOffset offset) const { | 293 QuicStreamOffset offset) { |
294 // TODO(jri): This is a simple safe decision for now, but make | 294 // TODO(jri): This is a simple safe decision for now, but make |
295 // is_in_fec_group a parameter. Same as with all public methods in | 295 // is_in_fec_group a parameter. Same as with all public methods in |
296 // QuicPacketCreator. | 296 // QuicPacketCreator. |
297 return BytesFree() > | 297 return BytesFree() > |
298 QuicFramer::GetMinStreamFrameSize( | 298 QuicFramer::GetMinStreamFrameSize( |
299 id, offset, true, fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); | 299 id, offset, true, fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); |
300 } | 300 } |
301 | 301 |
302 // static | 302 // static |
303 size_t QuicPacketCreator::StreamFramePacketOverhead( | 303 size_t QuicPacketCreator::StreamFramePacketOverhead( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 405 } |
406 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer."; | 406 QUIC_BUG_IF(length > 0) << "Failed to copy entire length to buffer."; |
407 } | 407 } |
408 | 408 |
409 SerializedPacket QuicPacketCreator::ReserializeAllFrames( | 409 SerializedPacket QuicPacketCreator::ReserializeAllFrames( |
410 const PendingRetransmission& retransmission, | 410 const PendingRetransmission& retransmission, |
411 char* buffer, | 411 char* buffer, |
412 size_t buffer_len) { | 412 size_t buffer_len) { |
413 DCHECK(queued_frames_.empty()); | 413 DCHECK(queued_frames_.empty()); |
414 DCHECK(fec_group_.get() == nullptr); | 414 DCHECK(fec_group_.get() == nullptr); |
415 DCHECK(!needs_padding_); | 415 DCHECK(!packet_.needs_padding); |
416 const QuicPacketNumberLength saved_length = packet_number_length_; | 416 QUIC_BUG_IF(retransmission.retransmittable_frames.empty()) |
| 417 << "Attempt to serialize empty packet"; |
| 418 const QuicPacketNumberLength saved_length = packet_.packet_number_length; |
417 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; | 419 const QuicPacketNumberLength saved_next_length = next_packet_number_length_; |
418 const bool saved_should_fec_protect = fec_protect_; | 420 const bool saved_should_fec_protect = fec_protect_; |
419 const bool saved_needs_padding = needs_padding_; | 421 const bool saved_needs_padding = packet_.needs_padding; |
420 const EncryptionLevel default_encryption_level = encryption_level_; | 422 const EncryptionLevel default_encryption_level = packet_.encryption_level; |
421 | 423 |
422 // Temporarily set the packet number length, stop FEC protection, | 424 // Temporarily set the packet number length, stop FEC protection, |
423 // and change the encryption level. | 425 // and change the encryption level. |
424 packet_number_length_ = retransmission.packet_number_length; | 426 packet_.packet_number_length = retransmission.packet_number_length; |
425 next_packet_number_length_ = retransmission.packet_number_length; | 427 next_packet_number_length_ = retransmission.packet_number_length; |
426 fec_protect_ = false; | 428 fec_protect_ = false; |
427 needs_padding_ = retransmission.needs_padding; | 429 packet_.needs_padding = retransmission.needs_padding; |
428 // Only preserve the original encryption level if it's a handshake packet or | 430 // Only preserve the original encryption level if it's a handshake packet or |
429 // if we haven't gone forward secure. | 431 // if we haven't gone forward secure. |
430 if (retransmission.has_crypto_handshake || | 432 if (retransmission.has_crypto_handshake || |
431 encryption_level_ != ENCRYPTION_FORWARD_SECURE) { | 433 packet_.encryption_level != ENCRYPTION_FORWARD_SECURE) { |
432 encryption_level_ = retransmission.encryption_level; | 434 packet_.encryption_level = retransmission.encryption_level; |
433 } | 435 } |
434 | 436 |
435 // Serialize the packet and restore the FEC and packet number length state. | 437 // Serialize the packet and restore the FEC and packet number length state. |
436 SerializedPacket serialized_packet = SerializeAllFrames( | 438 for (const QuicFrame& frame : retransmission.retransmittable_frames) { |
437 retransmission.retransmittable_frames, buffer, buffer_len); | |
438 if (FLAGS_quic_retransmit_via_onserializedpacket) { | |
439 serialized_packet.original_packet_number = retransmission.packet_number; | |
440 serialized_packet.transmission_type = retransmission.transmission_type; | |
441 } | |
442 | |
443 packet_number_length_ = saved_length; | |
444 next_packet_number_length_ = saved_next_length; | |
445 fec_protect_ = saved_should_fec_protect; | |
446 encryption_level_ = default_encryption_level; | |
447 | |
448 if (FLAGS_quic_retransmit_via_onserializedpacket) { | |
449 OnSerializedPacket(&serialized_packet); | |
450 return NoPacket(); | |
451 } else { | |
452 has_crypto_handshake_ = NOT_HANDSHAKE; | |
453 needs_padding_ = saved_needs_padding; | |
454 return serialized_packet; | |
455 } | |
456 } | |
457 | |
458 SerializedPacket QuicPacketCreator::SerializeAllFrames(const QuicFrames& frames, | |
459 char* buffer, | |
460 size_t buffer_len) { | |
461 QUIC_BUG_IF(!queued_frames_.empty()) << "Frames already queued."; | |
462 QUIC_BUG_IF(frames.empty()) << "Attempt to serialize empty packet"; | |
463 for (const QuicFrame& frame : frames) { | |
464 bool success = AddFrame(frame, false); | 439 bool success = AddFrame(frame, false); |
465 DCHECK(success); | 440 DCHECK(success); |
466 } | 441 } |
467 SerializedPacket packet = SerializePacket(buffer, buffer_len); | 442 SerializePacket(buffer, buffer_len); |
468 DCHECK(packet.retransmittable_frames == nullptr); | 443 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
469 return packet; | 444 packet_.original_packet_number = retransmission.packet_number; |
| 445 packet_.transmission_type = retransmission.transmission_type; |
| 446 OnSerializedPacket(); |
| 447 // Restore old values. |
| 448 packet_.packet_number_length = saved_length; |
| 449 next_packet_number_length_ = saved_next_length; |
| 450 fec_protect_ = saved_should_fec_protect; |
| 451 packet_.encryption_level = default_encryption_level; |
| 452 return NoPacket(); |
| 453 } else { |
| 454 SerializedPacket packet_copy = packet_; |
| 455 ClearPacket(); |
| 456 // Restore old values. |
| 457 packet_.needs_padding = saved_needs_padding; |
| 458 packet_.packet_number_length = saved_length; |
| 459 next_packet_number_length_ = saved_next_length; |
| 460 fec_protect_ = saved_should_fec_protect; |
| 461 packet_.encryption_level = default_encryption_level; |
| 462 return packet_copy; |
| 463 } |
470 } | 464 } |
471 | 465 |
472 void QuicPacketCreator::Flush() { | 466 void QuicPacketCreator::Flush() { |
473 if (!HasPendingFrames()) { | 467 if (!HasPendingFrames()) { |
474 return; | 468 return; |
475 } | 469 } |
476 | 470 |
477 // TODO(rtenneti): Change the default 64 alignas value (used the default | 471 // TODO(rtenneti): Change the default 64 alignas value (used the default |
478 // value from CACHELINE_SIZE). | 472 // value from CACHELINE_SIZE). |
479 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize]; | 473 ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize]; |
480 SerializedPacket serialized_packet = | 474 SerializePacket(seralized_packet_buffer, kMaxPacketSize); |
481 SerializePacket(seralized_packet_buffer, kMaxPacketSize); | 475 OnSerializedPacket(); |
482 OnSerializedPacket(&serialized_packet); | |
483 } | 476 } |
484 | 477 |
485 void QuicPacketCreator::OnSerializedPacket(SerializedPacket* packet) { | 478 void QuicPacketCreator::OnSerializedPacket() { |
486 if (packet->packet == nullptr) { | 479 if (packet_.packet == nullptr) { |
487 QUIC_BUG << "Failed to SerializePacket. fec_policy:" << fec_send_policy() | 480 QUIC_BUG << "Failed to SerializePacket. fec_policy:" << fec_send_policy() |
488 << " should_fec_protect_:" << should_fec_protect_next_packet_; | 481 << " should_fec_protect_:" << should_fec_protect_next_packet_; |
489 delegate_->CloseConnection(QUIC_FAILED_TO_SERIALIZE_PACKET, false); | 482 delegate_->CloseConnection(QUIC_FAILED_TO_SERIALIZE_PACKET, false); |
490 return; | 483 return; |
491 } | 484 } |
492 // There may be AckListeners interested in this packet. | 485 |
493 packet->listeners.swap(ack_listeners_); | 486 delegate_->OnSerializedPacket(&packet_); |
494 DCHECK(ack_listeners_.empty()); | 487 ClearPacket(); |
495 delegate_->OnSerializedPacket(packet); | |
496 has_ack_ = false; | |
497 has_stop_waiting_ = false; | |
498 has_crypto_handshake_ = NOT_HANDSHAKE; | |
499 needs_padding_ = false; | |
500 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/false, | 488 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/false, |
501 /*is_fec_timeout=*/false); | 489 /*is_fec_timeout=*/false); |
502 // Maximum packet size may be only enacted while no packet is currently being | 490 // Maximum packet size may be only enacted while no packet is currently being |
503 // constructed, so here we have a good opportunity to actually change it. | 491 // constructed, so here we have a good opportunity to actually change it. |
504 if (CanSetMaxPacketLength()) { | 492 if (CanSetMaxPacketLength()) { |
505 SetMaxPacketLength(max_packet_length_); | 493 SetMaxPacketLength(max_packet_length_); |
506 } | 494 } |
507 } | 495 } |
508 | 496 |
| 497 void QuicPacketCreator::ClearPacket() { |
| 498 packet_.has_ack = false; |
| 499 packet_.has_stop_waiting = false; |
| 500 packet_.has_crypto_handshake = NOT_HANDSHAKE; |
| 501 packet_.needs_padding = false; |
| 502 packet_.is_fec_packet = false; |
| 503 packet_.original_packet_number = 0; |
| 504 packet_.transmission_type = NOT_RETRANSMISSION; |
| 505 packet_.packet = nullptr; |
| 506 DCHECK(packet_.retransmittable_frames.empty()); |
| 507 packet_.listeners.clear(); |
| 508 } |
| 509 |
509 bool QuicPacketCreator::HasPendingFrames() const { | 510 bool QuicPacketCreator::HasPendingFrames() const { |
510 return !queued_frames_.empty(); | 511 return !queued_frames_.empty(); |
511 } | 512 } |
512 | 513 |
513 bool QuicPacketCreator::HasPendingRetransmittableFrames() const { | 514 bool QuicPacketCreator::HasPendingRetransmittableFrames() const { |
514 return queued_retransmittable_frames_.get() != nullptr && | 515 return !packet_.retransmittable_frames.empty(); |
515 !queued_retransmittable_frames_->empty(); | |
516 } | 516 } |
517 | 517 |
518 size_t QuicPacketCreator::ExpansionOnNewFrame() const { | 518 size_t QuicPacketCreator::ExpansionOnNewFrame() const { |
519 // If packet is FEC protected, there's no expansion. | 519 // If packet is FEC protected, there's no expansion. |
520 if (fec_protect_) { | 520 if (fec_protect_) { |
521 return 0; | 521 return 0; |
522 } | 522 } |
523 // If the last frame in the packet is a stream frame, then it will expand to | 523 // If the last frame in the packet is a stream frame, then it will expand to |
524 // include the stream_length field when a new frame is added. | 524 // include the stream_length field when a new frame is added. |
525 bool has_trailing_stream_frame = | 525 bool has_trailing_stream_frame = |
526 !queued_frames_.empty() && queued_frames_.back().type == STREAM_FRAME; | 526 !queued_frames_.empty() && queued_frames_.back().type == STREAM_FRAME; |
527 return has_trailing_stream_frame ? kQuicStreamPayloadLengthSize : 0; | 527 return has_trailing_stream_frame ? kQuicStreamPayloadLengthSize : 0; |
528 } | 528 } |
529 | 529 |
530 size_t QuicPacketCreator::BytesFree() const { | 530 size_t QuicPacketCreator::BytesFree() { |
531 DCHECK_GE(max_plaintext_size_, PacketSize()); | 531 DCHECK_GE(max_plaintext_size_, PacketSize()); |
532 return max_plaintext_size_ - | 532 return max_plaintext_size_ - |
533 min(max_plaintext_size_, PacketSize() + ExpansionOnNewFrame()); | 533 min(max_plaintext_size_, PacketSize() + ExpansionOnNewFrame()); |
534 } | 534 } |
535 | 535 |
536 size_t QuicPacketCreator::PacketSize() const { | 536 size_t QuicPacketCreator::PacketSize() { |
537 if (!queued_frames_.empty()) { | 537 if (!queued_frames_.empty()) { |
538 return packet_size_; | 538 return packet_size_; |
539 } | 539 } |
540 if (fec_group_.get() == nullptr) { | 540 if (fec_group_.get() == nullptr) { |
541 // Update packet number length on packet and FEC boundary. | 541 // Update packet number length on packet and FEC boundary. |
542 packet_number_length_ = next_packet_number_length_; | 542 packet_.packet_number_length = next_packet_number_length_; |
543 } | 543 } |
544 packet_size_ = GetPacketHeaderSize( | 544 packet_size_ = |
545 connection_id_length_, send_version_in_packet_, send_path_id_in_packet_, | 545 GetPacketHeaderSize(connection_id_length_, send_version_in_packet_, |
546 packet_number_length_, fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); | 546 send_path_id_in_packet_, packet_.packet_number_length, |
| 547 fec_protect_ ? IN_FEC_GROUP : NOT_IN_FEC_GROUP); |
547 return packet_size_; | 548 return packet_size_; |
548 } | 549 } |
549 | 550 |
550 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) { | 551 bool QuicPacketCreator::AddSavedFrame(const QuicFrame& frame) { |
551 return AddFrame(frame, /*save_retransmittable_frames=*/true); | 552 return AddFrame(frame, /*save_retransmittable_frames=*/true); |
552 } | 553 } |
553 | 554 |
554 bool QuicPacketCreator::AddPaddedSavedFrame(const QuicFrame& frame) { | 555 bool QuicPacketCreator::AddPaddedSavedFrame(const QuicFrame& frame) { |
555 if (AddFrame(frame, /*save_retransmittable_frames=*/true)) { | 556 if (AddFrame(frame, /*save_retransmittable_frames=*/true)) { |
556 needs_padding_ = true; | 557 packet_.needs_padding = true; |
557 return true; | 558 return true; |
558 } | 559 } |
559 return false; | 560 return false; |
560 } | 561 } |
561 | 562 |
562 void QuicPacketCreator::AddAckListener(QuicAckListenerInterface* listener, | 563 void QuicPacketCreator::AddAckListener(QuicAckListenerInterface* listener, |
563 QuicPacketLength length) { | 564 QuicPacketLength length) { |
564 DCHECK(!queued_frames_.empty()); | 565 DCHECK(!queued_frames_.empty()); |
565 ack_listeners_.push_back(AckListenerWrapper(listener, length)); | 566 packet_.listeners.push_back(AckListenerWrapper(listener, length)); |
566 } | 567 } |
567 | 568 |
568 SerializedPacket QuicPacketCreator::SerializePacket( | 569 void QuicPacketCreator::SerializePacket(char* encrypted_buffer, |
569 char* encrypted_buffer, | 570 size_t encrypted_buffer_len) { |
570 size_t encrypted_buffer_len) { | |
571 DCHECK_LT(0u, encrypted_buffer_len); | 571 DCHECK_LT(0u, encrypted_buffer_len); |
572 QUIC_BUG_IF(queued_frames_.empty()) << "Attempt to serialize empty packet"; | 572 QUIC_BUG_IF(queued_frames_.empty()) << "Attempt to serialize empty packet"; |
573 if (fec_group_.get() != nullptr) { | 573 if (fec_group_.get() != nullptr) { |
574 DCHECK_GE(packet_number_ + 1, fec_group_->FecGroupNumber()); | 574 DCHECK_GE(packet_.packet_number + 1, fec_group_->FecGroupNumber()); |
575 } | 575 } |
576 QuicPacketHeader header; | 576 QuicPacketHeader header; |
577 // FillPacketHeader increments packet_number_. | 577 // FillPacketHeader increments packet_number_. |
578 FillPacketHeader(fec_group_ != nullptr ? fec_group_->FecGroupNumber() : 0, | 578 FillPacketHeader(fec_group_ != nullptr ? fec_group_->FecGroupNumber() : 0, |
579 false, &header); | 579 false, &header); |
580 | 580 |
581 MaybeAddPadding(); | 581 MaybeAddPadding(); |
582 | 582 |
583 DCHECK_GE(max_plaintext_size_, packet_size_); | 583 DCHECK_GE(max_plaintext_size_, packet_size_); |
584 // ACK Frames will be truncated due to length only if they're the only frame | 584 // ACK Frames will be truncated due to length only if they're the only frame |
585 // in the packet, and if packet_size_ was set to max_plaintext_size_. If | 585 // in the packet, and if packet_size_ was set to max_plaintext_size_. If |
586 // truncation due to length occurred, then GetSerializedFrameLength will have | 586 // truncation due to length occurred, then GetSerializedFrameLength will have |
587 // returned all bytes free. | 587 // returned all bytes free. |
588 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ && | 588 bool possibly_truncated_by_length = packet_size_ == max_plaintext_size_ && |
589 queued_frames_.size() == 1 && | 589 queued_frames_.size() == 1 && |
590 queued_frames_.back().type == ACK_FRAME; | 590 queued_frames_.back().type == ACK_FRAME; |
591 // Use the packet_size_ instead of the buffer size to ensure smaller | 591 // Use the packet_size_ instead of the buffer size to ensure smaller |
592 // packet sizes are properly used. | 592 // packet sizes are properly used. |
593 size_t length = framer_->BuildDataPacket(header, queued_frames_, | 593 size_t length = framer_->BuildDataPacket(header, queued_frames_, |
594 encrypted_buffer, packet_size_); | 594 encrypted_buffer, packet_size_); |
595 if (length == 0) { | 595 if (length == 0) { |
596 QUIC_BUG << "Failed to serialize " << queued_frames_.size() << " frames."; | 596 QUIC_BUG << "Failed to serialize " << queued_frames_.size() << " frames."; |
597 return NoPacket(); | 597 return; |
598 } | 598 } |
599 | 599 |
600 // TODO(ianswett) Consider replacing QuicPacket with something else, since | 600 // TODO(ianswett) Consider replacing QuicPacket with something else, since |
601 // it's only used to provide convenience methods to FEC and encryption. | 601 // it's only used to provide convenience methods to FEC and encryption. |
602 QuicPacket packet( | 602 QuicPacket packet( |
603 encrypted_buffer, length, | 603 encrypted_buffer, length, |
604 /* owns_buffer */ false, header.public_header.connection_id_length, | 604 /* owns_buffer */ false, header.public_header.connection_id_length, |
605 header.public_header.version_flag, header.public_header.multipath_flag, | 605 header.public_header.version_flag, header.public_header.multipath_flag, |
606 header.public_header.packet_number_length); | 606 header.public_header.packet_number_length); |
607 OnBuiltFecProtectedPayload(header, packet.FecProtectedData()); | 607 OnBuiltFecProtectedPayload(header, packet.FecProtectedData()); |
608 | 608 |
609 // Because of possible truncation, we can't be confident that our | 609 // Because of possible truncation, we can't be confident that our |
610 // packet size calculation worked correctly. | 610 // packet size calculation worked correctly. |
611 if (!possibly_truncated_by_length) { | 611 if (!possibly_truncated_by_length) { |
612 DCHECK_EQ(packet_size_, length); | 612 DCHECK_EQ(packet_size_, length); |
613 } | 613 } |
614 // Immediately encrypt the packet, to ensure we don't encrypt the same | 614 // Immediately encrypt the packet, to ensure we don't encrypt the same |
615 // packet number multiple times. | 615 // packet number multiple times. |
616 size_t encrypted_length = | 616 size_t encrypted_length = framer_->EncryptPayload( |
617 framer_->EncryptPayload(encryption_level_, current_path_, packet_number_, | 617 packet_.encryption_level, packet_.path_id, packet_.packet_number, packet, |
618 packet, encrypted_buffer, encrypted_buffer_len); | 618 encrypted_buffer, encrypted_buffer_len); |
619 if (encrypted_length == 0) { | 619 if (encrypted_length == 0) { |
620 QUIC_BUG << "Failed to encrypt packet number " << packet_number_; | 620 QUIC_BUG << "Failed to encrypt packet number " << packet_.packet_number; |
621 return NoPacket(); | 621 return; |
622 } | 622 } |
623 | 623 |
624 packet_size_ = 0; | 624 packet_size_ = 0; |
625 queued_frames_.clear(); | 625 queued_frames_.clear(); |
626 return SerializedPacket( | 626 packet_.entropy_hash = QuicFramer::GetPacketEntropyHash(header); |
627 current_path_, header.packet_number, | 627 packet_.packet = |
628 header.public_header.packet_number_length, encrypted_buffer, | 628 new QuicEncryptedPacket(encrypted_buffer, encrypted_length, false); |
629 encrypted_length, | |
630 /* owns_buffer*/ false, QuicFramer::GetPacketEntropyHash(header), | |
631 queued_retransmittable_frames_.release(), needs_padding_, | |
632 has_crypto_handshake_, has_ack_, has_stop_waiting_, encryption_level_); | |
633 } | 629 } |
634 | 630 |
635 SerializedPacket QuicPacketCreator::SerializeFec(char* buffer, | 631 void QuicPacketCreator::SerializeFec(char* buffer, size_t buffer_len) { |
636 size_t buffer_len) { | |
637 DCHECK_LT(0u, buffer_len); | 632 DCHECK_LT(0u, buffer_len); |
638 if (fec_group_.get() == nullptr || fec_group_->NumReceivedPackets() <= 0) { | 633 if (fec_group_.get() == nullptr || fec_group_->NumReceivedPackets() <= 0) { |
639 QUIC_BUG << "SerializeFEC called but no group or zero packets in group."; | 634 QUIC_BUG << "SerializeFEC called but no group or zero packets in group."; |
640 // TODO(jri): Make this a public method of framer? | 635 return; |
641 return NoPacket(); | |
642 } | 636 } |
643 if (FLAGS_quic_no_unencrypted_fec && encryption_level_ == ENCRYPTION_NONE) { | 637 if (FLAGS_quic_no_unencrypted_fec && |
| 638 packet_.encryption_level == ENCRYPTION_NONE) { |
644 QUIC_BUG << "SerializeFEC must be called with encryption."; | 639 QUIC_BUG << "SerializeFEC must be called with encryption."; |
645 delegate_->CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, false); | 640 delegate_->CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, false); |
646 return NoPacket(); | 641 return; |
647 } | 642 } |
648 DCHECK_EQ(0u, queued_frames_.size()); | 643 DCHECK_EQ(0u, queued_frames_.size()); |
649 QuicPacketHeader header; | 644 QuicPacketHeader header; |
650 FillPacketHeader(fec_group_->FecGroupNumber(), true, &header); | 645 FillPacketHeader(fec_group_->FecGroupNumber(), true, &header); |
651 scoped_ptr<QuicPacket> packet( | 646 scoped_ptr<QuicPacket> packet( |
652 framer_->BuildFecPacket(header, fec_group_->PayloadParity())); | 647 framer_->BuildFecPacket(header, fec_group_->PayloadParity())); |
653 fec_group_.reset(nullptr); | 648 fec_group_.reset(nullptr); |
654 packet_size_ = 0; | 649 packet_size_ = 0; |
655 QUIC_BUG_IF(packet == nullptr) << "Failed to serialize fec packet for group:" | 650 QUIC_BUG_IF(packet == nullptr) << "Failed to serialize fec packet for group:" |
656 << fec_group_->FecGroupNumber(); | 651 << fec_group_->FecGroupNumber(); |
657 DCHECK_GE(max_packet_length_, packet->length()); | 652 DCHECK_GE(max_packet_length_, packet->length()); |
658 // Immediately encrypt the packet, to ensure we don't encrypt the same packet | 653 // Immediately encrypt the packet, to ensure we don't encrypt the same packet |
659 // packet number multiple times. | 654 // packet number multiple times. |
660 size_t encrypted_length = | 655 size_t encrypted_length = framer_->EncryptPayload( |
661 framer_->EncryptPayload(encryption_level_, current_path_, packet_number_, | 656 packet_.encryption_level, packet_.path_id, packet_.packet_number, *packet, |
662 *packet, buffer, buffer_len); | 657 buffer, buffer_len); |
663 if (encrypted_length == 0) { | 658 if (encrypted_length == 0) { |
664 QUIC_BUG << "Failed to encrypt packet number " << packet_number_; | 659 QUIC_BUG << "Failed to encrypt packet number " << packet_.packet_number; |
665 return NoPacket(); | 660 return; |
666 } | 661 } |
667 SerializedPacket serialized( | 662 packet_.entropy_hash = QuicFramer::GetPacketEntropyHash(header); |
668 current_path_, header.packet_number, | 663 packet_.packet = new QuicEncryptedPacket(buffer, encrypted_length, false); |
669 header.public_header.packet_number_length, buffer, encrypted_length, | 664 packet_.is_fec_packet = true; |
670 /* owns_buffer */ false, QuicFramer::GetPacketEntropyHash(header), | |
671 nullptr, false, NOT_HANDSHAKE, false, false, encryption_level_); | |
672 serialized.is_fec_packet = true; | |
673 return serialized; | |
674 } | 665 } |
675 | 666 |
676 QuicEncryptedPacket* QuicPacketCreator::SerializeVersionNegotiationPacket( | 667 QuicEncryptedPacket* QuicPacketCreator::SerializeVersionNegotiationPacket( |
677 const QuicVersionVector& supported_versions) { | 668 const QuicVersionVector& supported_versions) { |
678 DCHECK_EQ(Perspective::IS_SERVER, framer_->perspective()); | 669 DCHECK_EQ(Perspective::IS_SERVER, framer_->perspective()); |
679 QuicEncryptedPacket* encrypted = QuicFramer::BuildVersionNegotiationPacket( | 670 QuicEncryptedPacket* encrypted = QuicFramer::BuildVersionNegotiationPacket( |
680 connection_id_, supported_versions); | 671 connection_id_, supported_versions); |
681 DCHECK(encrypted); | 672 DCHECK(encrypted); |
682 DCHECK_GE(max_packet_length_, encrypted->length()); | 673 DCHECK_GE(max_packet_length_, encrypted->length()); |
683 return encrypted; | 674 return encrypted; |
684 } | 675 } |
685 | 676 |
| 677 // TODO(jri): Make this a public method of framer? |
686 SerializedPacket QuicPacketCreator::NoPacket() { | 678 SerializedPacket QuicPacketCreator::NoPacket() { |
687 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER, | 679 return SerializedPacket(kInvalidPathId, 0, PACKET_1BYTE_PACKET_NUMBER, |
688 nullptr, 0, nullptr, false, false); | 680 nullptr, 0, false, false); |
689 } | 681 } |
690 | 682 |
691 void QuicPacketCreator::FillPacketHeader(QuicFecGroupNumber fec_group, | 683 void QuicPacketCreator::FillPacketHeader(QuicFecGroupNumber fec_group, |
692 bool fec_flag, | 684 bool fec_flag, |
693 QuicPacketHeader* header) { | 685 QuicPacketHeader* header) { |
694 header->public_header.connection_id = connection_id_; | 686 header->public_header.connection_id = connection_id_; |
695 header->public_header.connection_id_length = connection_id_length_; | 687 header->public_header.connection_id_length = connection_id_length_; |
696 header->public_header.multipath_flag = send_path_id_in_packet_; | 688 header->public_header.multipath_flag = send_path_id_in_packet_; |
697 header->public_header.reset_flag = false; | 689 header->public_header.reset_flag = false; |
698 header->public_header.version_flag = send_version_in_packet_; | 690 header->public_header.version_flag = send_version_in_packet_; |
699 header->fec_flag = fec_flag; | 691 header->fec_flag = fec_flag; |
700 header->path_id = current_path_; | 692 header->path_id = packet_.path_id; |
701 header->packet_number = ++packet_number_; | 693 header->packet_number = ++packet_.packet_number; |
702 header->public_header.packet_number_length = packet_number_length_; | 694 header->public_header.packet_number_length = packet_.packet_number_length; |
703 header->entropy_flag = random_bool_source_->RandBool(); | 695 header->entropy_flag = random_bool_source_->RandBool(); |
704 header->is_in_fec_group = fec_group == 0 ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; | 696 header->is_in_fec_group = fec_group == 0 ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; |
705 header->fec_group = fec_group; | 697 header->fec_group = fec_group; |
706 } | 698 } |
707 | 699 |
708 bool QuicPacketCreator::ShouldRetransmit(const QuicFrame& frame) { | 700 bool QuicPacketCreator::ShouldRetransmit(const QuicFrame& frame) { |
709 switch (frame.type) { | 701 switch (frame.type) { |
710 case ACK_FRAME: | 702 case ACK_FRAME: |
711 case PADDING_FRAME: | 703 case PADDING_FRAME: |
712 case STOP_WAITING_FRAME: | 704 case STOP_WAITING_FRAME: |
713 case MTU_DISCOVERY_FRAME: | 705 case MTU_DISCOVERY_FRAME: |
714 return false; | 706 return false; |
715 default: | 707 default: |
716 return true; | 708 return true; |
717 } | 709 } |
718 } | 710 } |
719 | 711 |
720 bool QuicPacketCreator::AddFrame(const QuicFrame& frame, | 712 bool QuicPacketCreator::AddFrame(const QuicFrame& frame, |
721 bool save_retransmittable_frames) { | 713 bool save_retransmittable_frames) { |
722 DVLOG(1) << "Adding frame: " << frame; | 714 DVLOG(1) << "Adding frame: " << frame; |
723 if (FLAGS_quic_never_write_unencrypted_data && frame.type == STREAM_FRAME && | 715 if (FLAGS_quic_never_write_unencrypted_data && frame.type == STREAM_FRAME && |
724 frame.stream_frame->stream_id != kCryptoStreamId && | 716 frame.stream_frame->stream_id != kCryptoStreamId && |
725 encryption_level_ == ENCRYPTION_NONE) { | 717 packet_.encryption_level == ENCRYPTION_NONE) { |
726 QUIC_BUG << "Cannot send stream data without encryption."; | 718 QUIC_BUG << "Cannot send stream data without encryption."; |
727 delegate_->CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, false); | 719 delegate_->CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, false); |
728 return false; | 720 return false; |
729 } | 721 } |
730 InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec(); | 722 InFecGroup is_in_fec_group = MaybeUpdateLengthsAndStartFec(); |
731 | 723 |
732 size_t frame_len = framer_->GetSerializedFrameLength( | 724 size_t frame_len = framer_->GetSerializedFrameLength( |
733 frame, BytesFree(), queued_frames_.empty(), true, is_in_fec_group, | 725 frame, BytesFree(), queued_frames_.empty(), true, is_in_fec_group, |
734 packet_number_length_); | 726 packet_.packet_number_length); |
735 if (frame_len == 0) { | 727 if (frame_len == 0) { |
736 // Current open packet is full. | 728 // Current open packet is full. |
737 Flush(); | 729 Flush(); |
738 return false; | 730 return false; |
739 } | 731 } |
740 DCHECK_LT(0u, packet_size_); | 732 DCHECK_LT(0u, packet_size_); |
741 packet_size_ += ExpansionOnNewFrame() + frame_len; | 733 packet_size_ += ExpansionOnNewFrame() + frame_len; |
742 | 734 |
743 if (save_retransmittable_frames && ShouldRetransmit(frame)) { | 735 if (save_retransmittable_frames && ShouldRetransmit(frame)) { |
744 if (queued_retransmittable_frames_.get() == nullptr) { | 736 if (packet_.retransmittable_frames.empty()) { |
745 queued_retransmittable_frames_.reset(new QuicFrames()); | 737 packet_.retransmittable_frames.reserve(2); |
746 queued_retransmittable_frames_->reserve(2); | |
747 } | 738 } |
748 queued_retransmittable_frames_->push_back(frame); | 739 packet_.retransmittable_frames.push_back(frame); |
749 queued_frames_.push_back(frame); | 740 queued_frames_.push_back(frame); |
750 if (frame.type == STREAM_FRAME && | 741 if (frame.type == STREAM_FRAME && |
751 frame.stream_frame->stream_id == kCryptoStreamId) { | 742 frame.stream_frame->stream_id == kCryptoStreamId) { |
752 has_crypto_handshake_ = IS_HANDSHAKE; | 743 packet_.has_crypto_handshake = IS_HANDSHAKE; |
753 } | 744 } |
754 } else { | 745 } else { |
755 queued_frames_.push_back(frame); | 746 queued_frames_.push_back(frame); |
756 } | 747 } |
757 | 748 |
758 if (frame.type == ACK_FRAME) { | 749 if (frame.type == ACK_FRAME) { |
759 has_ack_ = true; | 750 packet_.has_ack = true; |
760 } | 751 } |
761 if (frame.type == STOP_WAITING_FRAME) { | 752 if (frame.type == STOP_WAITING_FRAME) { |
762 has_stop_waiting_ = true; | 753 packet_.has_stop_waiting = true; |
763 } | 754 } |
764 if (debug_delegate_ != nullptr) { | 755 if (debug_delegate_ != nullptr) { |
765 debug_delegate_->OnFrameAddedToPacket(frame); | 756 debug_delegate_->OnFrameAddedToPacket(frame); |
766 } | 757 } |
767 | 758 |
768 return true; | 759 return true; |
769 } | 760 } |
770 | 761 |
771 void QuicPacketCreator::MaybeAddPadding() { | 762 void QuicPacketCreator::MaybeAddPadding() { |
772 if (!needs_padding_) { | 763 if (!packet_.needs_padding) { |
773 return; | 764 return; |
774 } | 765 } |
775 | 766 |
776 if (BytesFree() == 0) { | 767 if (BytesFree() == 0) { |
777 // Don't pad full packets. | 768 // Don't pad full packets. |
778 return; | 769 return; |
779 } | 770 } |
780 | 771 |
781 bool success = AddFrame(QuicFrame(QuicPaddingFrame()), false); | 772 bool success = AddFrame(QuicFrame(QuicPaddingFrame()), false); |
782 DCHECK(success); | 773 DCHECK(success); |
(...skipping 10 matching lines...) Expand all Loading... |
793 Flush(); | 784 Flush(); |
794 | 785 |
795 StartFecProtectingPackets(); | 786 StartFecProtectingPackets(); |
796 DCHECK(fec_protect_); | 787 DCHECK(fec_protect_); |
797 } | 788 } |
798 | 789 |
799 void QuicPacketCreator::MaybeSendFecPacketAndCloseGroup(bool force_send_fec, | 790 void QuicPacketCreator::MaybeSendFecPacketAndCloseGroup(bool force_send_fec, |
800 bool is_fec_timeout) { | 791 bool is_fec_timeout) { |
801 if (ShouldSendFec(force_send_fec)) { | 792 if (ShouldSendFec(force_send_fec)) { |
802 if ((FLAGS_quic_no_unencrypted_fec && | 793 if ((FLAGS_quic_no_unencrypted_fec && |
803 encryption_level_ == ENCRYPTION_NONE) || | 794 packet_.encryption_level == ENCRYPTION_NONE) || |
804 (fec_send_policy_ == FEC_ALARM_TRIGGER && !is_fec_timeout)) { | 795 (fec_send_policy_ == FEC_ALARM_TRIGGER && !is_fec_timeout)) { |
805 ResetFecGroup(); | 796 ResetFecGroup(); |
806 delegate_->OnResetFecGroup(); | 797 delegate_->OnResetFecGroup(); |
807 } else { | 798 } else { |
808 // TODO(zhongyi): Change the default 64 alignas value (used the default | 799 // TODO(zhongyi): Change the default 64 alignas value (used the default |
809 // value from CACHELINE_SIZE). | 800 // value from CACHELINE_SIZE). |
810 ALIGNAS(64) char seralized_fec_buffer[kMaxPacketSize]; | 801 ALIGNAS(64) char seralized_fec_buffer[kMaxPacketSize]; |
811 SerializedPacket serialized_fec = | 802 SerializeFec(seralized_fec_buffer, kMaxPacketSize); |
812 SerializeFec(seralized_fec_buffer, kMaxPacketSize); | 803 OnSerializedPacket(); |
813 OnSerializedPacket(&serialized_fec); | |
814 } | 804 } |
815 } | 805 } |
816 | 806 |
817 if (!should_fec_protect_next_packet_ && fec_protect_ && !IsFecGroupOpen()) { | 807 if (!should_fec_protect_next_packet_ && fec_protect_ && !IsFecGroupOpen()) { |
818 StopFecProtectingPackets(); | 808 StopFecProtectingPackets(); |
819 } | 809 } |
820 } | 810 } |
821 | 811 |
822 QuicTime::Delta QuicPacketCreator::GetFecTimeout( | 812 QuicTime::Delta QuicPacketCreator::GetFecTimeout( |
823 QuicPacketNumber packet_number) { | 813 QuicPacketNumber packet_number) { |
(...skipping 14 matching lines...) Expand all Loading... |
838 } | 828 } |
839 | 829 |
840 void QuicPacketCreator::OnRttChange(QuicTime::Delta rtt) { | 830 void QuicPacketCreator::OnRttChange(QuicTime::Delta rtt) { |
841 fec_timeout_ = rtt.Multiply(rtt_multiplier_for_fec_timeout_); | 831 fec_timeout_ = rtt.Multiply(rtt_multiplier_for_fec_timeout_); |
842 } | 832 } |
843 | 833 |
844 void QuicPacketCreator::SetCurrentPath( | 834 void QuicPacketCreator::SetCurrentPath( |
845 QuicPathId path_id, | 835 QuicPathId path_id, |
846 QuicPacketNumber least_packet_awaited_by_peer, | 836 QuicPacketNumber least_packet_awaited_by_peer, |
847 QuicPacketCount max_packets_in_flight) { | 837 QuicPacketCount max_packets_in_flight) { |
848 if (current_path_ == path_id) { | 838 if (packet_.path_id == path_id) { |
849 return; | 839 return; |
850 } | 840 } |
851 | 841 |
852 if (HasPendingFrames()) { | 842 if (HasPendingFrames()) { |
853 QUIC_BUG << "Unable to change paths when a packet is under construction."; | 843 QUIC_BUG << "Unable to change paths when a packet is under construction."; |
854 return; | 844 return; |
855 } | 845 } |
856 | 846 |
857 // Send FEC packet and close FEC group. | 847 // Send FEC packet and close FEC group. |
858 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, | 848 MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, |
859 /*is_fec_timeout=*/false); | 849 /*is_fec_timeout=*/false); |
860 // Save current packet number and load switching path's packet number. | 850 // Save current packet number and load switching path's packet number. |
861 multipath_packet_number_[current_path_] = packet_number_; | 851 multipath_packet_number_[packet_.path_id] = packet_.packet_number; |
862 hash_map<QuicPathId, QuicPacketNumber>::iterator it = | 852 std::unordered_map<QuicPathId, QuicPacketNumber>::iterator it = |
863 multipath_packet_number_.find(path_id); | 853 multipath_packet_number_.find(path_id); |
864 // If path_id is not in the map, it's a new path. Set packet_number to 0. | 854 // If path_id is not in the map, it's a new path. Set packet_number to 0. |
865 packet_number_ = it == multipath_packet_number_.end() ? 0 : it->second; | 855 packet_.packet_number = it == multipath_packet_number_.end() ? 0 : it->second; |
866 current_path_ = path_id; | 856 packet_.path_id = path_id; |
867 DCHECK(current_path_ != kInvalidPathId); | 857 DCHECK(packet_.path_id != kInvalidPathId); |
868 // Send path in packet if current path is not the default path. | 858 // Send path in packet if current path is not the default path. |
869 send_path_id_in_packet_ = current_path_ != kDefaultPathId ? true : false; | 859 send_path_id_in_packet_ = packet_.path_id != kDefaultPathId ? true : false; |
870 // Switching path needs to update packet number length. | 860 // Switching path needs to update packet number length. |
871 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); | 861 UpdatePacketNumberLength(least_packet_awaited_by_peer, max_packets_in_flight); |
872 } | 862 } |
873 | 863 |
874 } // namespace net | 864 } // namespace net |
OLD | NEW |