| 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" |
| 11 | 11 |
| 12 using base::StringPiece; | 12 using base::StringPiece; |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 QuicPacketGenerator::QuicPacketGenerator(QuicConnectionId connection_id, | 16 QuicPacketGenerator::QuicPacketGenerator(QuicConnectionId connection_id, |
| 17 QuicFramer* framer, | 17 QuicFramer* framer, |
| 18 QuicRandom* random_generator, | 18 QuicRandom* random_generator, |
| 19 QuicBufferAllocator* buffer_allocator, | 19 QuicBufferAllocator* buffer_allocator, |
| 20 DelegateInterface* delegate) | 20 DelegateInterface* delegate) |
| 21 : delegate_(delegate), | 21 : delegate_(delegate), |
| 22 packet_creator_(connection_id, | 22 packet_creator_(connection_id, |
| 23 framer, | 23 framer, |
| 24 random_generator, | 24 random_generator, |
| 25 buffer_allocator, | 25 buffer_allocator, |
| 26 delegate), | 26 delegate), |
| 27 batch_mode_(false), | 27 batch_mode_(false), |
| 28 should_send_ack_(false), | 28 should_send_ack_(false), |
| 29 should_send_stop_waiting_(false), | 29 should_send_stop_waiting_(false) {} |
| 30 max_packet_length_(kDefaultMaxPacketSize) {} | |
| 31 | 30 |
| 32 QuicPacketGenerator::~QuicPacketGenerator() { | 31 QuicPacketGenerator::~QuicPacketGenerator() { |
| 33 QuicUtils::DeleteFrames(&queued_control_frames_); | 32 QuicUtils::DeleteFrames(&queued_control_frames_); |
| 34 } | 33 } |
| 35 | 34 |
| 36 void QuicPacketGenerator::SetShouldSendAck(bool also_send_stop_waiting) { | 35 void QuicPacketGenerator::SetShouldSendAck(bool also_send_stop_waiting) { |
| 37 if (packet_creator_.has_ack()) { | 36 if (packet_creator_.has_ack()) { |
| 38 // Ack already queued, nothing to do. | 37 // Ack already queued, nothing to do. |
| 39 return; | 38 return; |
| 40 } | 39 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 125 |
| 127 void QuicPacketGenerator::GenerateMtuDiscoveryPacket( | 126 void QuicPacketGenerator::GenerateMtuDiscoveryPacket( |
| 128 QuicByteCount target_mtu, | 127 QuicByteCount target_mtu, |
| 129 QuicAckListenerInterface* listener) { | 128 QuicAckListenerInterface* listener) { |
| 130 // MTU discovery frames must be sent by themselves. | 129 // MTU discovery frames must be sent by themselves. |
| 131 if (!packet_creator_.CanSetMaxPacketLength()) { | 130 if (!packet_creator_.CanSetMaxPacketLength()) { |
| 132 QUIC_BUG << "MTU discovery packets should only be sent when no other " | 131 QUIC_BUG << "MTU discovery packets should only be sent when no other " |
| 133 << "frames needs to be sent."; | 132 << "frames needs to be sent."; |
| 134 return; | 133 return; |
| 135 } | 134 } |
| 136 const QuicByteCount current_mtu = GetMaxPacketLength(); | 135 const QuicByteCount current_mtu = GetCurrentMaxPacketLength(); |
| 137 | 136 |
| 138 // The MTU discovery frame is allocated on the stack, since it is going to be | 137 // The MTU discovery frame is allocated on the stack, since it is going to be |
| 139 // serialized within this function. | 138 // serialized within this function. |
| 140 QuicMtuDiscoveryFrame mtu_discovery_frame; | 139 QuicMtuDiscoveryFrame mtu_discovery_frame; |
| 141 QuicFrame frame(mtu_discovery_frame); | 140 QuicFrame frame(mtu_discovery_frame); |
| 142 | 141 |
| 143 // Send the probe packet with the new length. | 142 // Send the probe packet with the new length. |
| 144 SetMaxPacketLength(target_mtu); | 143 SetMaxPacketLength(target_mtu); |
| 145 const bool success = packet_creator_.AddPaddedSavedFrame(frame); | 144 const bool success = packet_creator_.AddPaddedSavedFrame(frame); |
| 146 if (listener != nullptr) { | 145 if (listener != nullptr) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 235 } |
| 237 | 236 |
| 238 void QuicPacketGenerator::StopSendingVersion() { | 237 void QuicPacketGenerator::StopSendingVersion() { |
| 239 packet_creator_.StopSendingVersion(); | 238 packet_creator_.StopSendingVersion(); |
| 240 } | 239 } |
| 241 | 240 |
| 242 QuicPacketNumber QuicPacketGenerator::packet_number() const { | 241 QuicPacketNumber QuicPacketGenerator::packet_number() const { |
| 243 return packet_creator_.packet_number(); | 242 return packet_creator_.packet_number(); |
| 244 } | 243 } |
| 245 | 244 |
| 246 QuicByteCount QuicPacketGenerator::GetMaxPacketLength() const { | |
| 247 return max_packet_length_; | |
| 248 } | |
| 249 | |
| 250 QuicByteCount QuicPacketGenerator::GetCurrentMaxPacketLength() const { | 245 QuicByteCount QuicPacketGenerator::GetCurrentMaxPacketLength() const { |
| 251 return packet_creator_.max_packet_length(); | 246 return packet_creator_.max_packet_length(); |
| 252 } | 247 } |
| 253 | 248 |
| 254 void QuicPacketGenerator::SetMaxPacketLength(QuicByteCount length) { | 249 void QuicPacketGenerator::SetMaxPacketLength(QuicByteCount length) { |
| 255 max_packet_length_ = length; | 250 DCHECK(packet_creator_.CanSetMaxPacketLength()); |
| 256 if (packet_creator_.CanSetMaxPacketLength()) { | 251 packet_creator_.SetMaxPacketLength(length); |
| 257 packet_creator_.SetMaxPacketLength(length); | |
| 258 } | |
| 259 } | 252 } |
| 260 | 253 |
| 261 QuicEncryptedPacket* QuicPacketGenerator::SerializeVersionNegotiationPacket( | 254 QuicEncryptedPacket* QuicPacketGenerator::SerializeVersionNegotiationPacket( |
| 262 const QuicVersionVector& supported_versions) { | 255 const QuicVersionVector& supported_versions) { |
| 263 return packet_creator_.SerializeVersionNegotiationPacket(supported_versions); | 256 return packet_creator_.SerializeVersionNegotiationPacket(supported_versions); |
| 264 } | 257 } |
| 265 | 258 |
| 266 void QuicPacketGenerator::ReserializeAllFrames( | 259 void QuicPacketGenerator::ReserializeAllFrames( |
| 267 const PendingRetransmission& retransmission, | 260 const PendingRetransmission& retransmission, |
| 268 char* buffer, | 261 char* buffer, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 293 |
| 301 void QuicPacketGenerator::SetCurrentPath( | 294 void QuicPacketGenerator::SetCurrentPath( |
| 302 QuicPathId path_id, | 295 QuicPathId path_id, |
| 303 QuicPacketNumber least_packet_awaited_by_peer, | 296 QuicPacketNumber least_packet_awaited_by_peer, |
| 304 QuicPacketCount max_packets_in_flight) { | 297 QuicPacketCount max_packets_in_flight) { |
| 305 packet_creator_.SetCurrentPath(path_id, least_packet_awaited_by_peer, | 298 packet_creator_.SetCurrentPath(path_id, least_packet_awaited_by_peer, |
| 306 max_packets_in_flight); | 299 max_packets_in_flight); |
| 307 } | 300 } |
| 308 | 301 |
| 309 } // namespace net | 302 } // namespace net |
| OLD | NEW |