Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: net/quic/quic_connection.cc

Issue 523813003: Revert of Landing Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_logger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 connection_->SendPing(); 147 connection_->SendPing();
148 return QuicTime::Zero(); 148 return QuicTime::Zero();
149 } 149 }
150 150
151 private: 151 private:
152 QuicConnection* connection_; 152 QuicConnection* connection_;
153 153
154 DISALLOW_COPY_AND_ASSIGN(PingAlarm); 154 DISALLOW_COPY_AND_ASSIGN(PingAlarm);
155 }; 155 };
156 156
157 QuicConnection::PacketType GetPacketType(
158 const RetransmittableFrames* retransmittable_frames) {
159 if (!retransmittable_frames) {
160 return QuicConnection::NORMAL;
161 }
162 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
163 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
164 return QuicConnection::CONNECTION_CLOSE;
165 }
166 }
167 return QuicConnection::NORMAL;
168 }
169
157 } // namespace 170 } // namespace
158 171
159 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet, 172 QuicConnection::QueuedPacket::QueuedPacket(SerializedPacket packet,
160 EncryptionLevel level, 173 EncryptionLevel level,
161 TransmissionType transmission_type) 174 TransmissionType transmission_type)
162 : serialized_packet(packet), 175 : sequence_number(packet.sequence_number),
176 packet(packet.packet),
163 encryption_level(level), 177 encryption_level(level),
164 transmission_type(transmission_type) { 178 transmission_type(transmission_type),
179 retransmittable((transmission_type != NOT_RETRANSMISSION ||
180 packet.retransmittable_frames != NULL) ?
181 HAS_RETRANSMITTABLE_DATA : NO_RETRANSMITTABLE_DATA),
182 handshake(packet.retransmittable_frames == NULL ?
183 NOT_HANDSHAKE : packet.retransmittable_frames->HasCryptoHandshake()),
184 type(GetPacketType(packet.retransmittable_frames)),
185 length(packet.packet->length()) {
165 } 186 }
166 187
167 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") 188 #define ENDPOINT (is_server_ ? "Server: " : " Client: ")
168 189
169 QuicConnection::QuicConnection(QuicConnectionId connection_id, 190 QuicConnection::QuicConnection(QuicConnectionId connection_id,
170 IPEndPoint address, 191 IPEndPoint address,
171 QuicConnectionHelperInterface* helper, 192 QuicConnectionHelperInterface* helper,
172 const PacketWriterFactory& writer_factory, 193 const PacketWriterFactory& writer_factory,
173 bool owns_writer, 194 bool owns_writer,
174 bool is_server, 195 bool is_server,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 255 }
235 256
236 QuicConnection::~QuicConnection() { 257 QuicConnection::~QuicConnection() {
237 if (owns_writer_) { 258 if (owns_writer_) {
238 delete writer_; 259 delete writer_;
239 } 260 }
240 STLDeleteElements(&undecryptable_packets_); 261 STLDeleteElements(&undecryptable_packets_);
241 STLDeleteValues(&group_map_); 262 STLDeleteValues(&group_map_);
242 for (QueuedPacketList::iterator it = queued_packets_.begin(); 263 for (QueuedPacketList::iterator it = queued_packets_.begin();
243 it != queued_packets_.end(); ++it) { 264 it != queued_packets_.end(); ++it) {
244 delete it->serialized_packet.packet; 265 delete it->packet;
245 } 266 }
246 } 267 }
247 268
248 void QuicConnection::SetFromConfig(const QuicConfig& config) { 269 void QuicConnection::SetFromConfig(const QuicConfig& config) {
249 SetIdleNetworkTimeout(config.idle_connection_state_lifetime()); 270 SetIdleNetworkTimeout(config.idle_connection_state_lifetime());
250 sent_packet_manager_.SetFromConfig(config); 271 sent_packet_manager_.SetFromConfig(config);
251 } 272 }
252 273
253 bool QuicConnection::SelectMutualVersion( 274 bool QuicConnection::SelectMutualVersion(
254 const QuicVersionVector& available_versions) { 275 const QuicVersionVector& available_versions) {
(...skipping 17 matching lines...) Expand all
272 // Packets that we cannot decrypt are dropped. 293 // Packets that we cannot decrypt are dropped.
273 // TODO(rch): add stats to measure this. 294 // TODO(rch): add stats to measure this.
274 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) { 295 if (!connected_ || framer->error() == QUIC_DECRYPTION_FAILURE) {
275 return; 296 return;
276 } 297 }
277 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error()); 298 SendConnectionCloseWithDetails(framer->error(), framer->detailed_error());
278 } 299 }
279 300
280 void QuicConnection::OnPacket() { 301 void QuicConnection::OnPacket() {
281 DCHECK(last_stream_frames_.empty() && 302 DCHECK(last_stream_frames_.empty() &&
282 last_ack_frames_.empty() &&
283 last_congestion_frames_.empty() &&
284 last_stop_waiting_frames_.empty() &&
285 last_rst_frames_.empty() &&
286 last_goaway_frames_.empty() && 303 last_goaway_frames_.empty() &&
287 last_window_update_frames_.empty() && 304 last_window_update_frames_.empty() &&
288 last_blocked_frames_.empty() && 305 last_blocked_frames_.empty() &&
289 last_ping_frames_.empty() && 306 last_rst_frames_.empty() &&
290 last_close_frames_.empty()); 307 last_ack_frames_.empty() &&
308 last_congestion_frames_.empty() &&
309 last_stop_waiting_frames_.empty());
291 } 310 }
292 311
293 void QuicConnection::OnPublicResetPacket( 312 void QuicConnection::OnPublicResetPacket(
294 const QuicPublicResetPacket& packet) { 313 const QuicPublicResetPacket& packet) {
295 if (debug_visitor_.get() != NULL) { 314 if (debug_visitor_.get() != NULL) {
296 debug_visitor_->OnPublicResetPacket(packet); 315 debug_visitor_->OnPublicResetPacket(packet);
297 } 316 }
298 CloseConnection(QUIC_PUBLIC_RESET, true); 317 CloseConnection(QUIC_PUBLIC_RESET, true);
299 318
300 DVLOG(1) << ENDPOINT << "Connection " << connection_id() 319 DVLOG(1) << ENDPOINT << "Connection " << connection_id()
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // Might be old packets that were sent by the client before the version 356 // Might be old packets that were sent by the client before the version
338 // was negotiated. Drop these. 357 // was negotiated. Drop these.
339 return false; 358 return false;
340 359
341 default: 360 default:
342 DCHECK(false); 361 DCHECK(false);
343 } 362 }
344 363
345 version_negotiation_state_ = NEGOTIATED_VERSION; 364 version_negotiation_state_ = NEGOTIATED_VERSION;
346 visitor_->OnSuccessfulVersionNegotiation(received_version); 365 visitor_->OnSuccessfulVersionNegotiation(received_version);
347 if (debug_visitor_.get() != NULL) {
348 debug_visitor_->OnSuccessfulVersionNegotiation(received_version);
349 }
350 DVLOG(1) << ENDPOINT << "version negotiated " << received_version; 366 DVLOG(1) << ENDPOINT << "version negotiated " << received_version;
351 367
352 // Store the new version. 368 // Store the new version.
353 framer_.set_version(received_version); 369 framer_.set_version(received_version);
354 370
355 // TODO(satyamshekhar): Store the sequence number of this packet and close the 371 // TODO(satyamshekhar): Store the sequence number of this packet and close the
356 // connection if we ever received a packet with incorrect version and whose 372 // connection if we ever received a packet with incorrect version and whose
357 // sequence number is greater. 373 // sequence number is greater.
358 return true; 374 return true;
359 } 375 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 << " without version flag before version negotiated."; 482 << " without version flag before version negotiated.";
467 // Packets should have the version flag till version negotiation is 483 // Packets should have the version flag till version negotiation is
468 // done. 484 // done.
469 CloseConnection(QUIC_INVALID_VERSION, false); 485 CloseConnection(QUIC_INVALID_VERSION, false);
470 return false; 486 return false;
471 } else { 487 } else {
472 DCHECK_EQ(1u, header.public_header.versions.size()); 488 DCHECK_EQ(1u, header.public_header.versions.size());
473 DCHECK_EQ(header.public_header.versions[0], version()); 489 DCHECK_EQ(header.public_header.versions[0], version());
474 version_negotiation_state_ = NEGOTIATED_VERSION; 490 version_negotiation_state_ = NEGOTIATED_VERSION;
475 visitor_->OnSuccessfulVersionNegotiation(version()); 491 visitor_->OnSuccessfulVersionNegotiation(version());
476 if (debug_visitor_.get() != NULL) {
477 debug_visitor_->OnSuccessfulVersionNegotiation(version());
478 }
479 } 492 }
480 } else { 493 } else {
481 DCHECK(!header.public_header.version_flag); 494 DCHECK(!header.public_header.version_flag);
482 // If the client gets a packet without the version flag from the server 495 // If the client gets a packet without the version flag from the server
483 // it should stop sending version since the version negotiation is done. 496 // it should stop sending version since the version negotiation is done.
484 packet_generator_.StopSendingVersion(); 497 packet_generator_.StopSendingVersion();
485 version_negotiation_state_ = NEGOTIATED_VERSION; 498 version_negotiation_state_ = NEGOTIATED_VERSION;
486 visitor_->OnSuccessfulVersionNegotiation(version()); 499 visitor_->OnSuccessfulVersionNegotiation(version());
487 if (debug_visitor_.get() != NULL) {
488 debug_visitor_->OnSuccessfulVersionNegotiation(version());
489 }
490 } 500 }
491 } 501 }
492 502
493 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); 503 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_);
494 504
495 --stats_.packets_dropped; 505 --stats_.packets_dropped;
496 DVLOG(1) << ENDPOINT << "Received packet header: " << header; 506 DVLOG(1) << ENDPOINT << "Received packet header: " << header;
497 last_header_ = header; 507 last_header_ = header;
498 DCHECK(connected_); 508 DCHECK(connected_);
499 return true; 509 return true;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 610
601 last_stop_waiting_frames_.push_back(frame); 611 last_stop_waiting_frames_.push_back(frame);
602 return connected_; 612 return connected_;
603 } 613 }
604 614
605 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { 615 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) {
606 DCHECK(connected_); 616 DCHECK(connected_);
607 if (debug_visitor_.get() != NULL) { 617 if (debug_visitor_.get() != NULL) {
608 debug_visitor_->OnPingFrame(frame); 618 debug_visitor_->OnPingFrame(frame);
609 } 619 }
610 last_ping_frames_.push_back(frame);
611 return true; 620 return true;
612 } 621 }
613 622
614 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { 623 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) {
615 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { 624 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) {
616 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" 625 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:"
617 << incoming_ack.largest_observed << " vs " 626 << incoming_ack.largest_observed << " vs "
618 << packet_generator_.sequence_number(); 627 << packet_generator_.sequence_number();
619 // We got an error for data we have not sent. Error out. 628 // We got an error for data we have not sent. Error out.
620 return false; 629 return false;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 771
763 void QuicConnection::OnPacketComplete() { 772 void QuicConnection::OnPacketComplete() {
764 // Don't do anything if this packet closed the connection. 773 // Don't do anything if this packet closed the connection.
765 if (!connected_) { 774 if (!connected_) {
766 ClearLastFrames(); 775 ClearLastFrames();
767 return; 776 return;
768 } 777 }
769 778
770 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got") 779 DVLOG(1) << ENDPOINT << (last_packet_revived_ ? "Revived" : "Got")
771 << " packet " << last_header_.packet_sequence_number 780 << " packet " << last_header_.packet_sequence_number
772 << " with " << last_stream_frames_.size()<< " stream frames " 781 << " with " << last_ack_frames_.size() << " acks, "
773 << last_ack_frames_.size() << " acks, "
774 << last_congestion_frames_.size() << " congestions, " 782 << last_congestion_frames_.size() << " congestions, "
775 << last_stop_waiting_frames_.size() << " stop_waiting, " 783 << last_stop_waiting_frames_.size() << " stop_waiting, "
776 << last_rst_frames_.size() << " rsts, "
777 << last_goaway_frames_.size() << " goaways, " 784 << last_goaway_frames_.size() << " goaways, "
778 << last_window_update_frames_.size() << " window updates, " 785 << last_window_update_frames_.size() << " window updates, "
779 << last_blocked_frames_.size() << " blocked, " 786 << last_blocked_frames_.size() << " blocked, "
780 << last_ping_frames_.size() << " pings, " 787 << last_rst_frames_.size() << " rsts, "
781 << last_close_frames_.size() << " closes, " 788 << last_close_frames_.size() << " closes, "
782 << "for " << last_header_.public_header.connection_id; 789 << last_stream_frames_.size()
790 << " stream frames for "
791 << last_header_.public_header.connection_id;
783 792
784 // Call MaybeQueueAck() before recording the received packet, since we want 793 // Call MaybeQueueAck() before recording the received packet, since we want
785 // to trigger an ack if the newly received packet was previously missing. 794 // to trigger an ack if the newly received packet was previously missing.
786 MaybeQueueAck(); 795 MaybeQueueAck();
787 796
788 // Record received or revived packet to populate ack info correctly before 797 // Record received or revived packet to populate ack info correctly before
789 // processing stream frames, since the processing may result in a response 798 // processing stream frames, since the processing may result in a response
790 // packet with a bundled ack. 799 // packet with a bundled ack.
791 if (last_packet_revived_) { 800 if (last_packet_revived_) {
792 received_packet_manager_.RecordPacketRevived( 801 received_packet_manager_.RecordPacketRevived(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 874 }
866 } 875 }
867 876
868 if (ack_queued_) { 877 if (ack_queued_) {
869 ack_alarm_->Cancel(); 878 ack_alarm_->Cancel();
870 } 879 }
871 } 880 }
872 881
873 void QuicConnection::ClearLastFrames() { 882 void QuicConnection::ClearLastFrames() {
874 last_stream_frames_.clear(); 883 last_stream_frames_.clear();
875 last_ack_frames_.clear();
876 last_congestion_frames_.clear();
877 last_stop_waiting_frames_.clear();
878 last_rst_frames_.clear();
879 last_goaway_frames_.clear(); 884 last_goaway_frames_.clear();
880 last_window_update_frames_.clear(); 885 last_window_update_frames_.clear();
881 last_blocked_frames_.clear(); 886 last_blocked_frames_.clear();
882 last_ping_frames_.clear(); 887 last_rst_frames_.clear();
883 last_close_frames_.clear(); 888 last_ack_frames_.clear();
889 last_stop_waiting_frames_.clear();
890 last_congestion_frames_.clear();
884 } 891 }
885 892
886 QuicAckFrame* QuicConnection::CreateAckFrame() { 893 QuicAckFrame* QuicConnection::CreateAckFrame() {
887 QuicAckFrame* outgoing_ack = new QuicAckFrame(); 894 QuicAckFrame* outgoing_ack = new QuicAckFrame();
888 received_packet_manager_.UpdateReceivedPacketInfo( 895 received_packet_manager_.UpdateReceivedPacketInfo(
889 outgoing_ack, clock_->ApproximateNow()); 896 outgoing_ack, clock_->ApproximateNow());
890 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; 897 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack;
891 return outgoing_ack; 898 return outgoing_ack;
892 } 899 }
893 900
894 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { 901 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() {
895 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_); 902 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_);
896 } 903 }
897 904
898 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() { 905 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() {
899 QuicStopWaitingFrame stop_waiting; 906 QuicStopWaitingFrame stop_waiting;
900 UpdateStopWaiting(&stop_waiting); 907 UpdateStopWaiting(&stop_waiting);
901 return new QuicStopWaitingFrame(stop_waiting); 908 return new QuicStopWaitingFrame(stop_waiting);
902 } 909 }
903 910
904 bool QuicConnection::ShouldLastPacketInstigateAck() const { 911 bool QuicConnection::ShouldLastPacketInstigateAck() const {
905 if (!last_stream_frames_.empty() || 912 if (!last_stream_frames_.empty() ||
906 !last_goaway_frames_.empty() || 913 !last_goaway_frames_.empty() ||
907 !last_rst_frames_.empty() || 914 !last_rst_frames_.empty() ||
908 !last_window_update_frames_.empty() || 915 !last_window_update_frames_.empty() ||
909 !last_blocked_frames_.empty() || 916 !last_blocked_frames_.empty()) {
910 !last_ping_frames_.empty()) {
911 return true; 917 return true;
912 } 918 }
913 919
914 if (!last_ack_frames_.empty() && last_ack_frames_.back().is_truncated) { 920 if (!last_ack_frames_.empty() && last_ack_frames_.back().is_truncated) {
915 return true; 921 return true;
916 } 922 }
917 return false; 923 return false;
918 } 924 }
919 925
920 void QuicConnection::UpdateStopWaitingCount() { 926 void QuicConnection::UpdateStopWaitingCount() {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 DCHECK(!writer_->IsWriteBlocked()); 1208 DCHECK(!writer_->IsWriteBlocked());
1203 1209
1204 if (pending_version_negotiation_packet_) { 1210 if (pending_version_negotiation_packet_) {
1205 SendVersionNegotiationPacket(); 1211 SendVersionNegotiationPacket();
1206 } 1212 }
1207 1213
1208 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); 1214 QueuedPacketList::iterator packet_iterator = queued_packets_.begin();
1209 while (!writer_->IsWriteBlocked() && 1215 while (!writer_->IsWriteBlocked() &&
1210 packet_iterator != queued_packets_.end()) { 1216 packet_iterator != queued_packets_.end()) {
1211 if (WritePacket(*packet_iterator)) { 1217 if (WritePacket(*packet_iterator)) {
1212 delete packet_iterator->serialized_packet.packet; 1218 delete packet_iterator->packet;
1213 packet_iterator = queued_packets_.erase(packet_iterator); 1219 packet_iterator = queued_packets_.erase(packet_iterator);
1214 } else { 1220 } else {
1215 // Continue, because some queued packets may still be writable. 1221 // Continue, because some queued packets may still be writable.
1216 // This can happen if a retransmit send fails. 1222 // This can happen if a retransmit send fails.
1217 ++packet_iterator; 1223 ++packet_iterator;
1218 } 1224 }
1219 } 1225 }
1220 } 1226 }
1221 1227
1222 void QuicConnection::WritePendingRetransmissions() { 1228 void QuicConnection::WritePendingRetransmissions() {
1223 // Keep writing as long as there's a pending retransmission which can be 1229 // Keep writing as long as there's a pending retransmission which can be
1224 // written. 1230 // written.
1225 while (sent_packet_manager_.HasPendingRetransmissions()) { 1231 while (sent_packet_manager_.HasPendingRetransmissions()) {
1226 const QuicSentPacketManager::PendingRetransmission pending = 1232 const QuicSentPacketManager::PendingRetransmission pending =
1227 sent_packet_manager_.NextPendingRetransmission(); 1233 sent_packet_manager_.NextPendingRetransmission();
1228 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) { 1234 if (GetPacketType(&pending.retransmittable_frames) == NORMAL &&
1235 !CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1229 break; 1236 break;
1230 } 1237 }
1231 1238
1232 // Re-packetize the frames with a new sequence number for retransmission. 1239 // Re-packetize the frames with a new sequence number for retransmission.
1233 // Retransmitted data packets do not use FEC, even when it's enabled. 1240 // Retransmitted data packets do not use FEC, even when it's enabled.
1234 // Retransmitted packets use the same sequence number length as the 1241 // Retransmitted packets use the same sequence number length as the
1235 // original. 1242 // original.
1236 // Flush the packet generator before making a new packet. 1243 // Flush the packet generator before making a new packet.
1237 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that 1244 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that
1238 // does not require the creator to be flushed. 1245 // does not require the creator to be flushed.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 if (!delay.IsZero()) { 1310 if (!delay.IsZero()) {
1304 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1)); 1311 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1));
1305 DVLOG(1) << "Delaying sending."; 1312 DVLOG(1) << "Delaying sending.";
1306 return false; 1313 return false;
1307 } 1314 }
1308 send_alarm_->Cancel(); 1315 send_alarm_->Cancel();
1309 return true; 1316 return true;
1310 } 1317 }
1311 1318
1312 bool QuicConnection::WritePacket(QueuedPacket packet) { 1319 bool QuicConnection::WritePacket(QueuedPacket packet) {
1313 QuicPacketSequenceNumber sequence_number = 1320 QuicPacketSequenceNumber sequence_number = packet.sequence_number;
1314 packet.serialized_packet.sequence_number;
1315 if (ShouldDiscardPacket(packet.encryption_level, 1321 if (ShouldDiscardPacket(packet.encryption_level,
1316 sequence_number, 1322 sequence_number,
1317 IsRetransmittable(packet))) { 1323 packet.retransmittable)) {
1318 ++stats_.packets_discarded; 1324 ++stats_.packets_discarded;
1319 return true; 1325 return true;
1320 } 1326 }
1321 1327
1328 // If the packet is CONNECTION_CLOSE, we need to try to send it immediately
1329 // and encrypt it to hand it off to TimeWaitListManager.
1330 // If the packet is QUEUED, we don't re-consult the congestion control.
1331 // This ensures packets are sent in sequence number order.
1332 // TODO(ianswett): The congestion control should have been consulted before
1333 // serializing the packet, so this could be turned into a LOG_IF(DFATAL).
1334 if (packet.type == NORMAL && !CanWrite(packet.retransmittable)) {
1335 return false;
1336 }
1337
1322 // Some encryption algorithms require the packet sequence numbers not be 1338 // Some encryption algorithms require the packet sequence numbers not be
1323 // repeated. 1339 // repeated.
1324 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); 1340 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number);
1325 sequence_number_of_last_sent_packet_ = sequence_number; 1341 sequence_number_of_last_sent_packet_ = sequence_number;
1326 1342
1327 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( 1343 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(
1328 packet.encryption_level, 1344 packet.encryption_level, sequence_number, *packet.packet);
1329 sequence_number,
1330 *packet.serialized_packet.packet);
1331 if (encrypted == NULL) { 1345 if (encrypted == NULL) {
1332 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " 1346 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number "
1333 << sequence_number; 1347 << sequence_number;
1334 // CloseConnection does not send close packet, so no infinite loop here. 1348 // CloseConnection does not send close packet, so no infinite loop here.
1335 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); 1349 CloseConnection(QUIC_ENCRYPTION_FAILURE, false);
1336 return false; 1350 return false;
1337 } 1351 }
1338 1352
1339 // Connection close packets are eventually owned by TimeWaitListManager. 1353 // Connection close packets are eventually owned by TimeWaitListManager.
1340 // Others are deleted at the end of this call. 1354 // Others are deleted at the end of this call.
1341 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; 1355 scoped_ptr<QuicEncryptedPacket> encrypted_deleter;
1342 if (IsConnectionClose(packet)) { 1356 if (packet.type == CONNECTION_CLOSE) {
1343 DCHECK(connection_close_packet_.get() == NULL); 1357 DCHECK(connection_close_packet_.get() == NULL);
1344 connection_close_packet_.reset(encrypted); 1358 connection_close_packet_.reset(encrypted);
1345 // This assures we won't try to write *forced* packets when blocked. 1359 // This assures we won't try to write *forced* packets when blocked.
1346 // Return true to stop processing. 1360 // Return true to stop processing.
1347 if (writer_->IsWriteBlocked()) { 1361 if (writer_->IsWriteBlocked()) {
1348 visitor_->OnWriteBlocked(); 1362 visitor_->OnWriteBlocked();
1349 return true; 1363 return true;
1350 } 1364 }
1351 } else { 1365 } else {
1352 encrypted_deleter.reset(encrypted); 1366 encrypted_deleter.reset(encrypted);
1353 } 1367 }
1354 1368
1355 if (!FLAGS_quic_allow_oversized_packets_for_test) { 1369 if (!FLAGS_quic_allow_oversized_packets_for_test) {
1356 DCHECK_LE(encrypted->length(), kMaxPacketSize); 1370 DCHECK_LE(encrypted->length(), kMaxPacketSize);
1357 } 1371 }
1358 DCHECK_LE(encrypted->length(), packet_generator_.max_packet_length()); 1372 DCHECK_LE(encrypted->length(), packet_generator_.max_packet_length());
1359 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number << " : " 1373 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number
1360 << (packet.serialized_packet.packet->is_fec_packet() ? "FEC " : 1374 << " : " << (packet.packet->is_fec_packet() ? "FEC " :
1361 (IsRetransmittable(packet) == HAS_RETRANSMITTABLE_DATA 1375 (packet.retransmittable == HAS_RETRANSMITTABLE_DATA
1362 ? "data bearing " : " ack only ")) 1376 ? "data bearing " : " ack only "))
1363 << ", encryption level: " 1377 << ", encryption level: "
1364 << QuicUtils::EncryptionLevelToString(packet.encryption_level) 1378 << QuicUtils::EncryptionLevelToString(packet.encryption_level)
1365 << ", length:" 1379 << ", length:" << packet.packet->length() << ", encrypted length:"
1366 << packet.serialized_packet.packet->length()
1367 << ", encrypted length:"
1368 << encrypted->length(); 1380 << encrypted->length();
1369 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl 1381 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl
1370 << QuicUtils::StringToHexASCIIDump( 1382 << QuicUtils::StringToHexASCIIDump(packet.packet->AsStringPiece());
1371 packet.serialized_packet.packet->AsStringPiece());
1372 1383
1373 WriteResult result = writer_->WritePacket(encrypted->data(), 1384 WriteResult result = writer_->WritePacket(encrypted->data(),
1374 encrypted->length(), 1385 encrypted->length(),
1375 self_address().address(), 1386 self_address().address(),
1376 peer_address()); 1387 peer_address());
1377 if (result.error_code == ERR_IO_PENDING) { 1388 if (result.error_code == ERR_IO_PENDING) {
1378 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); 1389 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status);
1379 } 1390 }
1380 if (debug_visitor_.get() != NULL) { 1391 if (debug_visitor_.get() != NULL) {
1381 // Pass the write result to the visitor. 1392 // Pass the write result to the visitor.
(...skipping 22 matching lines...) Expand all
1404 DVLOG(1) << ENDPOINT << "time of last sent packet: " 1415 DVLOG(1) << ENDPOINT << "time of last sent packet: "
1405 << now.ToDebuggingValue(); 1416 << now.ToDebuggingValue();
1406 1417
1407 // TODO(ianswett): Change the sequence number length and other packet creator 1418 // TODO(ianswett): Change the sequence number length and other packet creator
1408 // options by a more explicit API than setting a struct value directly, 1419 // options by a more explicit API than setting a struct value directly,
1409 // perhaps via the NetworkChangeVisitor. 1420 // perhaps via the NetworkChangeVisitor.
1410 packet_generator_.UpdateSequenceNumberLength( 1421 packet_generator_.UpdateSequenceNumberLength(
1411 sent_packet_manager_.least_packet_awaited_by_peer(), 1422 sent_packet_manager_.least_packet_awaited_by_peer(),
1412 sent_packet_manager_.GetCongestionWindow()); 1423 sent_packet_manager_.GetCongestionWindow());
1413 1424
1414 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1425 bool reset_retransmission_alarm =
1415 sequence_number, 1426 sent_packet_manager_.OnPacketSent(sequence_number,
1416 now, 1427 now,
1417 encrypted->length(), 1428 encrypted->length(),
1418 packet.transmission_type, 1429 packet.transmission_type,
1419 IsRetransmittable(packet)); 1430 packet.retransmittable);
1420 1431
1421 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1432 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1422 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(), 1433 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(),
1423 QuicTime::Delta::FromMilliseconds(1)); 1434 QuicTime::Delta::FromMilliseconds(1));
1424 } 1435 }
1425 1436
1426 stats_.bytes_sent += result.bytes_written; 1437 stats_.bytes_sent += result.bytes_written;
1427 ++stats_.packets_sent; 1438 ++stats_.packets_sent;
1428 if (packet.transmission_type != NOT_RETRANSMISSION) { 1439 if (packet.transmission_type != NOT_RETRANSMISSION) {
1429 stats_.bytes_retransmitted += result.bytes_written; 1440 stats_.bytes_retransmitted += result.bytes_written;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); 1516 visitor_->OnCongestionWindowChange(clock_->ApproximateNow());
1506 } 1517 }
1507 1518
1508 void QuicConnection::OnHandshakeComplete() { 1519 void QuicConnection::OnHandshakeComplete() {
1509 sent_packet_manager_.SetHandshakeConfirmed(); 1520 sent_packet_manager_.SetHandshakeConfirmed();
1510 } 1521 }
1511 1522
1512 bool QuicConnection::SendOrQueuePacket(EncryptionLevel level, 1523 bool QuicConnection::SendOrQueuePacket(EncryptionLevel level,
1513 const SerializedPacket& packet, 1524 const SerializedPacket& packet,
1514 TransmissionType transmission_type) { 1525 TransmissionType transmission_type) {
1515 // The caller of this function is responsible for checking CanWrite().
1516 if (packet.packet == NULL) { 1526 if (packet.packet == NULL) {
1517 LOG(DFATAL) << "NULL packet passed in to SendOrQueuePacket"; 1527 LOG(DFATAL) << "NULL packet passed in to SendOrQueuePacket";
1518 return true; 1528 return true;
1519 } 1529 }
1520 1530
1521 sent_entropy_manager_.RecordPacketEntropyHash(packet.sequence_number, 1531 sent_entropy_manager_.RecordPacketEntropyHash(packet.sequence_number,
1522 packet.entropy_hash); 1532 packet.entropy_hash);
1523 QueuedPacket queued_packet(packet, level, transmission_type); 1533 QueuedPacket queued_packet(packet, level, transmission_type);
1524 // If there are already queued packets, put this at the end, 1534 // If there are already queued packets, put this at the end,
1525 // unless it's ConnectionClose, in which case it is written immediately. 1535 // unless it's ConnectionClose, in which case it is written immediately.
1526 if ((IsConnectionClose(queued_packet) 1536 if ((queued_packet.type == CONNECTION_CLOSE || queued_packets_.empty()) &&
1527 || queued_packets_.empty()) &&
1528 WritePacket(queued_packet)) { 1537 WritePacket(queued_packet)) {
1529 delete packet.packet; 1538 delete packet.packet;
1530 return true; 1539 return true;
1531 } 1540 }
1541 queued_packet.type = QUEUED;
1532 queued_packets_.push_back(queued_packet); 1542 queued_packets_.push_back(queued_packet);
1533 return false; 1543 return false;
1534 } 1544 }
1535 1545
1536 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { 1546 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) {
1537 stop_waiting->least_unacked = GetLeastUnacked(); 1547 stop_waiting->least_unacked = GetLeastUnacked();
1538 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( 1548 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy(
1539 stop_waiting->least_unacked - 1); 1549 stop_waiting->least_unacked - 1);
1540 } 1550 }
1541 1551
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 } 1984 }
1975 // If we changed the generator's batch state, restore original batch state. 1985 // If we changed the generator's batch state, restore original batch state.
1976 if (!already_in_batch_mode_) { 1986 if (!already_in_batch_mode_) {
1977 DVLOG(1) << "Leaving Batch Mode."; 1987 DVLOG(1) << "Leaving Batch Mode.";
1978 connection_->packet_generator_.FinishBatchOperations(); 1988 connection_->packet_generator_.FinishBatchOperations();
1979 } 1989 }
1980 DCHECK_EQ(already_in_batch_mode_, 1990 DCHECK_EQ(already_in_batch_mode_,
1981 connection_->packet_generator_.InBatchMode()); 1991 connection_->packet_generator_.InBatchMode());
1982 } 1992 }
1983 1993
1984 HasRetransmittableData QuicConnection::IsRetransmittable(
1985 QueuedPacket packet) {
1986 // TODO(cyr): Understand why the first check here is necessary. Without it,
1987 // DiscardRetransmit test fails.
1988 if (packet.transmission_type != NOT_RETRANSMISSION ||
1989 packet.serialized_packet.retransmittable_frames != NULL) {
1990 return HAS_RETRANSMITTABLE_DATA;
1991 } else {
1992 return NO_RETRANSMITTABLE_DATA;
1993 }
1994 }
1995
1996 bool QuicConnection::IsConnectionClose(
1997 QueuedPacket packet) {
1998 RetransmittableFrames* retransmittable_frames =
1999 packet.serialized_packet.retransmittable_frames;
2000 if (!retransmittable_frames) {
2001 return false;
2002 }
2003 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2004 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2005 return true;
2006 }
2007 }
2008 return false;
2009 }
2010
2011 } // namespace net 1994 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698