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

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

Issue 530343003: Landing Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0828
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_crypto_stream.cc » ('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 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 // send, send an ack to raise the high water mark. 926 // send, send an ack to raise the high water mark.
927 if (!last_ack_frames_.back().missing_packets.empty() && 927 if (!last_ack_frames_.back().missing_packets.empty() &&
928 GetLeastUnacked() > *last_ack_frames_.back().missing_packets.begin()) { 928 GetLeastUnacked() > *last_ack_frames_.back().missing_packets.begin()) {
929 ++stop_waiting_count_; 929 ++stop_waiting_count_;
930 } else { 930 } else {
931 stop_waiting_count_ = 0; 931 stop_waiting_count_ = 0;
932 } 932 }
933 } 933 }
934 934
935 QuicPacketSequenceNumber QuicConnection::GetLeastUnacked() const { 935 QuicPacketSequenceNumber QuicConnection::GetLeastUnacked() const {
936 return sent_packet_manager_.HasUnackedPackets() ? 936 return sent_packet_manager_.GetLeastUnacked();
937 sent_packet_manager_.GetLeastUnackedSentPacket() :
938 packet_generator_.sequence_number() + 1;
939 } 937 }
940 938
941 void QuicConnection::MaybeSendInResponseToPacket() { 939 void QuicConnection::MaybeSendInResponseToPacket() {
942 if (!connected_) { 940 if (!connected_) {
943 return; 941 return;
944 } 942 }
945 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); 943 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK);
946 944
947 // Now that we have received an ack, we might be able to send packets which 945 // Now that we have received an ack, we might be able to send packets which
948 // are queued locally, or drain streams which are blocked. 946 // are queued locally, or drain streams which are blocked.
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 if (!delay.IsZero()) { 1295 if (!delay.IsZero()) {
1298 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1)); 1296 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1));
1299 DVLOG(1) << "Delaying sending."; 1297 DVLOG(1) << "Delaying sending.";
1300 return false; 1298 return false;
1301 } 1299 }
1302 send_alarm_->Cancel(); 1300 send_alarm_->Cancel();
1303 return true; 1301 return true;
1304 } 1302 }
1305 1303
1306 bool QuicConnection::WritePacket(const QueuedPacket& packet) { 1304 bool QuicConnection::WritePacket(const QueuedPacket& packet) {
1307 QuicPacketSequenceNumber sequence_number = 1305 if (ShouldDiscardPacket(packet)) {
1308 packet.serialized_packet.sequence_number;
1309 if (ShouldDiscardPacket(packet.encryption_level,
1310 sequence_number,
1311 IsRetransmittable(packet))) {
1312 ++stats_.packets_discarded; 1306 ++stats_.packets_discarded;
1313 return true; 1307 return true;
1314 } 1308 }
1315 // Connection close packets are encypted and saved, so don't exit early. 1309 // Connection close packets are encypted and saved, so don't exit early.
1316 if (writer_->IsWriteBlocked() && !IsConnectionClose(packet)) { 1310 if (writer_->IsWriteBlocked() && !IsConnectionClose(packet)) {
1317 return false; 1311 return false;
1318 } 1312 }
1319 1313
1314 QuicPacketSequenceNumber sequence_number =
1315 packet.serialized_packet.sequence_number;
1320 // Some encryption algorithms require the packet sequence numbers not be 1316 // Some encryption algorithms require the packet sequence numbers not be
1321 // repeated. 1317 // repeated.
1322 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); 1318 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number);
1323 sequence_number_of_last_sent_packet_ = sequence_number; 1319 sequence_number_of_last_sent_packet_ = sequence_number;
1324 1320
1325 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( 1321 QuicEncryptedPacket* encrypted = framer_.EncryptPacket(
1326 packet.encryption_level, 1322 packet.encryption_level,
1327 sequence_number, 1323 sequence_number,
1328 *packet.serialized_packet.packet); 1324 *packet.serialized_packet.packet);
1329 if (encrypted == NULL) { 1325 if (encrypted == NULL) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 } 1425 }
1430 1426
1431 if (result.status == WRITE_STATUS_ERROR) { 1427 if (result.status == WRITE_STATUS_ERROR) {
1432 OnWriteError(result.error_code); 1428 OnWriteError(result.error_code);
1433 return false; 1429 return false;
1434 } 1430 }
1435 1431
1436 return true; 1432 return true;
1437 } 1433 }
1438 1434
1439 bool QuicConnection::ShouldDiscardPacket( 1435 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) {
1440 EncryptionLevel level,
1441 QuicPacketSequenceNumber sequence_number,
1442 HasRetransmittableData retransmittable) {
1443 if (!connected_) { 1436 if (!connected_) {
1444 DVLOG(1) << ENDPOINT 1437 DVLOG(1) << ENDPOINT
1445 << "Not sending packet as connection is disconnected."; 1438 << "Not sending packet as connection is disconnected.";
1446 return true; 1439 return true;
1447 } 1440 }
1448 1441
1442 QuicPacketSequenceNumber sequence_number =
1443 packet.serialized_packet.sequence_number;
1449 // If the packet has been discarded before sending, don't send it. 1444 // If the packet has been discarded before sending, don't send it.
1450 // This occurs if a packet gets serialized, queued, then discarded. 1445 // This occurs if a packet gets serialized, queued, then discarded.
1451 if (!sent_packet_manager_.IsUnacked(sequence_number)) { 1446 if (!sent_packet_manager_.IsUnacked(sequence_number)) {
1452 DVLOG(1) << ENDPOINT << "Dropping packet before sending: " 1447 DVLOG(1) << ENDPOINT << "Dropping packet before sending: "
1453 << sequence_number << " since it has already been discarded."; 1448 << sequence_number << " since it has already been discarded.";
1454 return true; 1449 return true;
1455 } 1450 }
1456 1451
1457 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE && 1452 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE &&
1458 level == ENCRYPTION_NONE) { 1453 packet.encryption_level == ENCRYPTION_NONE) {
1459 // Drop packets that are NULL encrypted since the peer won't accept them 1454 // Drop packets that are NULL encrypted since the peer won't accept them
1460 // anymore. 1455 // anymore.
1461 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " 1456 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: "
1462 << sequence_number << " since the connection is forward secure."; 1457 << sequence_number << " since the connection is forward secure.";
1463 LOG_IF(DFATAL, 1458 LOG_IF(DFATAL,
1464 sent_packet_manager_.HasRetransmittableFrames(sequence_number)) 1459 sent_packet_manager_.HasRetransmittableFrames(sequence_number))
1465 << "Once forward secure, all NULL encrypted packets should be " 1460 << "Once forward secure, all NULL encrypted packets should be "
1466 << "neutered."; 1461 << "neutered.";
1467 return true; 1462 return true;
1468 } 1463 }
1469 1464
1470 if (retransmittable == HAS_RETRANSMITTABLE_DATA && 1465 if (packet.transmission_type != NOT_RETRANSMISSION &&
1471 !sent_packet_manager_.HasRetransmittableFrames(sequence_number)) { 1466 !sent_packet_manager_.HasRetransmittableFrames(sequence_number)) {
1472 DVLOG(1) << ENDPOINT << "Dropping unacked packet: " << sequence_number 1467 DVLOG(1) << ENDPOINT << "Dropping unacked packet: " << sequence_number
1473 << " A previous transmission was acked while write blocked."; 1468 << " A previous transmission was acked while write blocked.";
1474 return true; 1469 return true;
1475 } 1470 }
1476 1471
1477 return false; 1472 return false;
1478 } 1473 }
1479 1474
1480 void QuicConnection::OnWriteError(int error_code) { 1475 void QuicConnection::OnWriteError(int error_code) {
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 // If we changed the generator's batch state, restore original batch state. 1966 // If we changed the generator's batch state, restore original batch state.
1972 if (!already_in_batch_mode_) { 1967 if (!already_in_batch_mode_) {
1973 DVLOG(1) << "Leaving Batch Mode."; 1968 DVLOG(1) << "Leaving Batch Mode.";
1974 connection_->packet_generator_.FinishBatchOperations(); 1969 connection_->packet_generator_.FinishBatchOperations();
1975 } 1970 }
1976 DCHECK_EQ(already_in_batch_mode_, 1971 DCHECK_EQ(already_in_batch_mode_,
1977 connection_->packet_generator_.InBatchMode()); 1972 connection_->packet_generator_.InBatchMode());
1978 } 1973 }
1979 1974
1980 HasRetransmittableData QuicConnection::IsRetransmittable( 1975 HasRetransmittableData QuicConnection::IsRetransmittable(
1981 QueuedPacket packet) { 1976 const QueuedPacket& packet) {
1982 // TODO(cyr): Understand why the first check here is necessary. Without it, 1977 // Retransmitted packets retransmittable frames are owned by the unacked
1983 // DiscardRetransmit test fails. 1978 // packet map, but are not present in the serialized packet.
1984 if (packet.transmission_type != NOT_RETRANSMISSION || 1979 if (packet.transmission_type != NOT_RETRANSMISSION ||
1985 packet.serialized_packet.retransmittable_frames != NULL) { 1980 packet.serialized_packet.retransmittable_frames != NULL) {
1986 return HAS_RETRANSMITTABLE_DATA; 1981 return HAS_RETRANSMITTABLE_DATA;
1987 } else { 1982 } else {
1988 return NO_RETRANSMITTABLE_DATA; 1983 return NO_RETRANSMITTABLE_DATA;
1989 } 1984 }
1990 } 1985 }
1991 1986
1992 bool QuicConnection::IsConnectionClose( 1987 bool QuicConnection::IsConnectionClose(
1993 QueuedPacket packet) { 1988 QueuedPacket packet) {
1994 RetransmittableFrames* retransmittable_frames = 1989 RetransmittableFrames* retransmittable_frames =
1995 packet.serialized_packet.retransmittable_frames; 1990 packet.serialized_packet.retransmittable_frames;
1996 if (!retransmittable_frames) { 1991 if (!retransmittable_frames) {
1997 return false; 1992 return false;
1998 } 1993 }
1999 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 1994 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2000 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 1995 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2001 return true; 1996 return true;
2002 } 1997 }
2003 } 1998 }
2004 return false; 1999 return false;
2005 } 2000 }
2006 2001
2007 } // namespace net 2002 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_crypto_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698