| 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_generator.h" | 5 #include "net/quic/quic_packet_generator.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/quic_fec_group.h" | 9 #include "net/quic/quic_fec_group.h" |
| 10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 has_handshake && packet_creator_.HasPendingRetransmittableFrames(); | 111 has_handshake && packet_creator_.HasPendingRetransmittableFrames(); |
| 112 SendQueuedFrames(flush, /*is_fec_timeout=*/false); | 112 SendQueuedFrames(flush, /*is_fec_timeout=*/false); |
| 113 | 113 |
| 114 size_t total_bytes_consumed = 0; | 114 size_t total_bytes_consumed = 0; |
| 115 bool fin_consumed = false; | 115 bool fin_consumed = false; |
| 116 | 116 |
| 117 if (!packet_creator_.HasRoomForStreamFrame(id, offset)) { | 117 if (!packet_creator_.HasRoomForStreamFrame(id, offset)) { |
| 118 packet_creator_.Flush(); | 118 packet_creator_.Flush(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 if (fec_protection == MUST_FEC_PROTECT) { | |
| 122 packet_creator_.set_should_fec_protect(true); | |
| 123 packet_creator_.MaybeStartFecProtection(); | |
| 124 } | |
| 125 | |
| 126 if (!fin && (iov.total_length == 0)) { | 121 if (!fin && (iov.total_length == 0)) { |
| 127 LOG(DFATAL) << "Attempt to consume empty data without FIN."; | 122 LOG(DFATAL) << "Attempt to consume empty data without FIN."; |
| 128 return QuicConsumedData(0, false); | 123 return QuicConsumedData(0, false); |
| 129 } | 124 } |
| 130 | 125 |
| 131 while (delegate_->ShouldGeneratePacket( | 126 while (delegate_->ShouldGeneratePacket( |
| 132 HAS_RETRANSMITTABLE_DATA, has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) { | 127 HAS_RETRANSMITTABLE_DATA, has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) { |
| 133 QuicFrame frame; | 128 QuicFrame frame; |
| 134 if (!packet_creator_.ConsumeData(id, iov, total_bytes_consumed, | 129 if (!packet_creator_.ConsumeData(id, iov, total_bytes_consumed, |
| 135 offset + total_bytes_consumed, fin, | 130 offset + total_bytes_consumed, fin, |
| 136 has_handshake, &frame)) { | 131 has_handshake, &frame, fec_protection)) { |
| 137 // Current packet is full and flushed. | 132 // Current packet is full and flushed. |
| 138 continue; | 133 continue; |
| 139 } | 134 } |
| 140 | 135 |
| 141 // A stream frame is created and added. | 136 // A stream frame is created and added. |
| 142 size_t bytes_consumed = frame.stream_frame->frame_length; | 137 size_t bytes_consumed = frame.stream_frame->frame_length; |
| 143 if (debug_delegate_ != nullptr) { | 138 if (debug_delegate_ != nullptr) { |
| 144 debug_delegate_->OnFrameAddedToPacket(frame); | 139 debug_delegate_->OnFrameAddedToPacket(frame); |
| 145 } | 140 } |
| 146 | 141 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 160 packet_creator_.Flush(); | 155 packet_creator_.Flush(); |
| 161 } | 156 } |
| 162 | 157 |
| 163 if (total_bytes_consumed == iov.total_length) { | 158 if (total_bytes_consumed == iov.total_length) { |
| 164 // We're done writing the data. Exit the loop. | 159 // We're done writing the data. Exit the loop. |
| 165 // We don't make this a precondition because we could have 0 bytes of data | 160 // We don't make this a precondition because we could have 0 bytes of data |
| 166 // if we're simply writing a fin. | 161 // if we're simply writing a fin. |
| 167 if (fec_protection == MUST_FEC_PROTECT) { | 162 if (fec_protection == MUST_FEC_PROTECT) { |
| 168 // Turn off FEC protection when we're done writing protected data. | 163 // Turn off FEC protection when we're done writing protected data. |
| 169 DVLOG(1) << "Turning FEC protection OFF"; | 164 DVLOG(1) << "Turning FEC protection OFF"; |
| 170 packet_creator_.set_should_fec_protect(false); | 165 packet_creator_.set_should_fec_protect_next_packet(false); |
| 171 } | 166 } |
| 172 break; | 167 break; |
| 173 } | 168 } |
| 174 } | 169 } |
| 175 | 170 |
| 176 // Don't allow the handshake to be bundled with other retransmittable frames. | 171 // Don't allow the handshake to be bundled with other retransmittable frames. |
| 177 if (has_handshake) { | 172 if (has_handshake) { |
| 178 SendQueuedFrames(/*flush=*/true, /*is_fec_timeout=*/false); | 173 SendQueuedFrames(/*flush=*/true, /*is_fec_timeout=*/false); |
| 179 } | 174 } |
| 180 | 175 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 void QuicPacketGenerator::SetEncrypter(EncryptionLevel level, | 396 void QuicPacketGenerator::SetEncrypter(EncryptionLevel level, |
| 402 QuicEncrypter* encrypter) { | 397 QuicEncrypter* encrypter) { |
| 403 packet_creator_.SetEncrypter(level, encrypter); | 398 packet_creator_.SetEncrypter(level, encrypter); |
| 404 } | 399 } |
| 405 | 400 |
| 406 void QuicPacketGenerator::OnSerializedPacket( | 401 void QuicPacketGenerator::OnSerializedPacket( |
| 407 SerializedPacket* serialized_packet) { | 402 SerializedPacket* serialized_packet) { |
| 408 if (serialized_packet->packet == nullptr) { | 403 if (serialized_packet->packet == nullptr) { |
| 409 LOG(DFATAL) << "Failed to SerializePacket. fec_policy:" << fec_send_policy() | 404 LOG(DFATAL) << "Failed to SerializePacket. fec_policy:" << fec_send_policy() |
| 410 << " should_fec_protect_:" | 405 << " should_fec_protect_:" |
| 411 << packet_creator_.should_fec_protect(); | 406 << packet_creator_.should_fec_protect_next_packet(); |
| 412 delegate_->CloseConnection(QUIC_FAILED_TO_SERIALIZE_PACKET, false); | 407 delegate_->CloseConnection(QUIC_FAILED_TO_SERIALIZE_PACKET, false); |
| 413 return; | 408 return; |
| 414 } | 409 } |
| 415 | 410 |
| 416 // There may be AckListeners interested in this packet. | 411 // There may be AckListeners interested in this packet. |
| 417 serialized_packet->listeners.swap(ack_listeners_); | 412 serialized_packet->listeners.swap(ack_listeners_); |
| 418 ack_listeners_.clear(); | 413 ack_listeners_.clear(); |
| 419 | 414 |
| 420 delegate_->OnSerializedPacket(*serialized_packet); | 415 delegate_->OnSerializedPacket(*serialized_packet); |
| 421 packet_creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/false, | 416 packet_creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/false, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 444 | 439 |
| 445 FecSendPolicy QuicPacketGenerator::fec_send_policy() { | 440 FecSendPolicy QuicPacketGenerator::fec_send_policy() { |
| 446 return packet_creator_.fec_send_policy(); | 441 return packet_creator_.fec_send_policy(); |
| 447 } | 442 } |
| 448 | 443 |
| 449 void QuicPacketGenerator::set_fec_send_policy(FecSendPolicy fec_send_policy) { | 444 void QuicPacketGenerator::set_fec_send_policy(FecSendPolicy fec_send_policy) { |
| 450 packet_creator_.set_fec_send_policy(fec_send_policy); | 445 packet_creator_.set_fec_send_policy(fec_send_policy); |
| 451 } | 446 } |
| 452 | 447 |
| 453 } // namespace net | 448 } // namespace net |
| OLD | NEW |