| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/quic/quic_bug_tracker.h" | 8 #include "net/quic/quic_bug_tracker.h" |
| 9 #include "net/quic/quic_flags.h" | 9 #include "net/quic/quic_flags.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 | 122 |
| 123 DCHECK(InBatchMode() || !packet_creator_.HasPendingFrames()); | 123 DCHECK(InBatchMode() || !packet_creator_.HasPendingFrames()); |
| 124 return QuicConsumedData(total_bytes_consumed, fin_consumed); | 124 return QuicConsumedData(total_bytes_consumed, fin_consumed); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void QuicPacketGenerator::GenerateMtuDiscoveryPacket( | 127 void QuicPacketGenerator::GenerateMtuDiscoveryPacket( |
| 128 QuicByteCount target_mtu, | 128 QuicByteCount target_mtu, |
| 129 QuicAckListenerInterface* listener) { | 129 QuicAckListenerInterface* listener) { |
| 130 // MTU discovery frames must be sent by themselves. | 130 // MTU discovery frames must be sent by themselves. |
| 131 DCHECK(!InBatchMode() && !packet_creator_.HasPendingFrames()); | 131 if (!packet_creator_.CanSetMaxPacketLength()) { |
| 132 QUIC_BUG << "MTU discovery packets should only be sent when no other " |
| 133 << "frames needs to be sent."; |
| 134 return; |
| 135 } |
| 132 const QuicByteCount current_mtu = GetMaxPacketLength(); | 136 const QuicByteCount current_mtu = GetMaxPacketLength(); |
| 133 | 137 |
| 134 // The MTU discovery frame is allocated on the stack, since it is going to be | 138 // The MTU discovery frame is allocated on the stack, since it is going to be |
| 135 // serialized within this function. | 139 // serialized within this function. |
| 136 QuicMtuDiscoveryFrame mtu_discovery_frame; | 140 QuicMtuDiscoveryFrame mtu_discovery_frame; |
| 137 QuicFrame frame(mtu_discovery_frame); | 141 QuicFrame frame(mtu_discovery_frame); |
| 138 | 142 |
| 139 // Send the probe packet with the new length. | 143 // Send the probe packet with the new length. |
| 140 SetMaxPacketLength(target_mtu, /*force=*/true); | 144 SetMaxPacketLength(target_mtu); |
| 141 const bool success = packet_creator_.AddPaddedSavedFrame(frame); | 145 const bool success = packet_creator_.AddPaddedSavedFrame(frame); |
| 142 if (listener != nullptr) { | 146 if (listener != nullptr) { |
| 143 packet_creator_.AddAckListener(listener, 0); | 147 packet_creator_.AddAckListener(listener, 0); |
| 144 } | 148 } |
| 145 packet_creator_.Flush(); | 149 packet_creator_.Flush(); |
| 146 // The only reason AddFrame can fail is that the packet is too full to fit in | 150 // The only reason AddFrame can fail is that the packet is too full to fit in |
| 147 // a ping. This is not possible for any sane MTU. | 151 // a ping. This is not possible for any sane MTU. |
| 148 DCHECK(success); | 152 DCHECK(success); |
| 149 | 153 |
| 150 // Reset the packet length back. | 154 // Reset the packet length back. |
| 151 SetMaxPacketLength(current_mtu, /*force=*/true); | 155 SetMaxPacketLength(current_mtu); |
| 152 } | 156 } |
| 153 | 157 |
| 154 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { | 158 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { |
| 155 DCHECK(HasPendingFrames()); | 159 DCHECK(HasPendingFrames()); |
| 156 HasRetransmittableData retransmittable = | 160 HasRetransmittableData retransmittable = |
| 157 (should_send_ack_ || should_send_stop_waiting_) | 161 (should_send_ack_ || should_send_stop_waiting_) |
| 158 ? NO_RETRANSMITTABLE_DATA | 162 ? NO_RETRANSMITTABLE_DATA |
| 159 : HAS_RETRANSMITTABLE_DATA; | 163 : HAS_RETRANSMITTABLE_DATA; |
| 160 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { | 164 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { |
| 161 DCHECK(!queued_control_frames_.empty()); // These are retransmittable. | 165 DCHECK(!queued_control_frames_.empty()); // These are retransmittable. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 244 } |
| 241 | 245 |
| 242 QuicByteCount QuicPacketGenerator::GetMaxPacketLength() const { | 246 QuicByteCount QuicPacketGenerator::GetMaxPacketLength() const { |
| 243 return max_packet_length_; | 247 return max_packet_length_; |
| 244 } | 248 } |
| 245 | 249 |
| 246 QuicByteCount QuicPacketGenerator::GetCurrentMaxPacketLength() const { | 250 QuicByteCount QuicPacketGenerator::GetCurrentMaxPacketLength() const { |
| 247 return packet_creator_.max_packet_length(); | 251 return packet_creator_.max_packet_length(); |
| 248 } | 252 } |
| 249 | 253 |
| 250 void QuicPacketGenerator::SetMaxPacketLength(QuicByteCount length, bool force) { | 254 void QuicPacketGenerator::SetMaxPacketLength(QuicByteCount length) { |
| 251 // If we cannot immediately set new maximum packet length, and the |force| | |
| 252 // flag is set, we have to flush the contents of the queue. | |
| 253 if (!packet_creator_.CanSetMaxPacketLength() && force) { | |
| 254 SendQueuedFrames(/*flush=*/true); | |
| 255 DCHECK(packet_creator_.CanSetMaxPacketLength()); | |
| 256 } | |
| 257 | |
| 258 max_packet_length_ = length; | 255 max_packet_length_ = length; |
| 259 if (packet_creator_.CanSetMaxPacketLength()) { | 256 if (packet_creator_.CanSetMaxPacketLength()) { |
| 260 packet_creator_.SetMaxPacketLength(length); | 257 packet_creator_.SetMaxPacketLength(length); |
| 261 } | 258 } |
| 262 } | 259 } |
| 263 | 260 |
| 264 QuicEncryptedPacket* QuicPacketGenerator::SerializeVersionNegotiationPacket( | 261 QuicEncryptedPacket* QuicPacketGenerator::SerializeVersionNegotiationPacket( |
| 265 const QuicVersionVector& supported_versions) { | 262 const QuicVersionVector& supported_versions) { |
| 266 return packet_creator_.SerializeVersionNegotiationPacket(supported_versions); | 263 return packet_creator_.SerializeVersionNegotiationPacket(supported_versions); |
| 267 } | 264 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 300 |
| 304 void QuicPacketGenerator::SetCurrentPath( | 301 void QuicPacketGenerator::SetCurrentPath( |
| 305 QuicPathId path_id, | 302 QuicPathId path_id, |
| 306 QuicPacketNumber least_packet_awaited_by_peer, | 303 QuicPacketNumber least_packet_awaited_by_peer, |
| 307 QuicPacketCount max_packets_in_flight) { | 304 QuicPacketCount max_packets_in_flight) { |
| 308 packet_creator_.SetCurrentPath(path_id, least_packet_awaited_by_peer, | 305 packet_creator_.SetCurrentPath(path_id, least_packet_awaited_by_peer, |
| 309 max_packets_in_flight); | 306 max_packets_in_flight); |
| 310 } | 307 } |
| 311 | 308 |
| 312 } // namespace net | 309 } // namespace net |
| OLD | NEW |