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

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

Issue 17302002: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const int kMaxPacketsToSerializeAtOnce = 6; 46 const int kMaxPacketsToSerializeAtOnce = 6;
47 47
48 // Limit the number of packets we send per retransmission-alarm so we 48 // Limit the number of packets we send per retransmission-alarm so we
49 // eventually cede. 10 is arbitrary. 49 // eventually cede. 10 is arbitrary.
50 const size_t kMaxPacketsPerRetransmissionAlarm = 10; 50 const size_t kMaxPacketsPerRetransmissionAlarm = 10;
51 51
52 // Limit the number of FEC groups to two. If we get enough out of order packets 52 // Limit the number of FEC groups to two. If we get enough out of order packets
53 // that this becomes limiting, we can revisit. 53 // that this becomes limiting, we can revisit.
54 const size_t kMaxFecGroups = 2; 54 const size_t kMaxFecGroups = 2;
55 55
56 // Limit the number of undecryptable packets we buffer in
57 // expectation of the CHLO/SHLO arriving.
58 const size_t kMaxUndecryptablePackets = 10;
59
56 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) { 60 bool Near(QuicPacketSequenceNumber a, QuicPacketSequenceNumber b) {
57 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a; 61 QuicPacketSequenceNumber delta = (a > b) ? a - b : b - a;
58 return delta <= kMaxPacketGap; 62 return delta <= kMaxPacketGap;
59 } 63 }
60 64
61 } // namespace 65 } // namespace
62 66
63 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") 67 #define ENDPOINT (is_server_ ? "Server: " : " Client: ")
64 68
65 QuicConnection::QuicConnection(QuicGuid guid, 69 QuicConnection::QuicConnection(QuicGuid guid,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 /* 116 /*
113 if (FLAGS_fake_packet_loss_percentage > 0) { 117 if (FLAGS_fake_packet_loss_percentage > 0) {
114 int32 seed = RandomBase::WeakSeed32(); 118 int32 seed = RandomBase::WeakSeed32();
115 LOG(INFO) << ENDPOINT << "Seeding packet loss with " << seed; 119 LOG(INFO) << ENDPOINT << "Seeding packet loss with " << seed;
116 random_.reset(new MTRandom(seed)); 120 random_.reset(new MTRandom(seed));
117 } 121 }
118 */ 122 */
119 } 123 }
120 124
121 QuicConnection::~QuicConnection() { 125 QuicConnection::~QuicConnection() {
126 STLDeleteElements(&undecryptable_packets_);
122 STLDeleteValues(&unacked_packets_); 127 STLDeleteValues(&unacked_packets_);
123 STLDeleteValues(&group_map_); 128 STLDeleteValues(&group_map_);
124 for (QueuedPacketList::iterator it = queued_packets_.begin(); 129 for (QueuedPacketList::iterator it = queued_packets_.begin();
125 it != queued_packets_.end(); ++it) { 130 it != queued_packets_.end(); ++it) {
126 delete it->packet; 131 delete it->packet;
127 } 132 }
128 DLOG(INFO) << ENDPOINT << "write_blocked: " << write_blocked_; 133 DLOG(INFO) << ENDPOINT << "write_blocked: " << write_blocked_;
129 } 134 }
130 135
131 bool QuicConnection::SelectMutualVersion( 136 bool QuicConnection::SelectMutualVersion(
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } 755 }
751 756
752 if (!(peer_address == peer_address_ && self_address == self_address_)) { 757 if (!(peer_address == peer_address_ && self_address == self_address_)) {
753 address_migrating_ = true; 758 address_migrating_ = true;
754 } 759 }
755 760
756 stats_.bytes_received += packet.length(); 761 stats_.bytes_received += packet.length();
757 ++stats_.packets_received; 762 ++stats_.packets_received;
758 763
759 if (!framer_.ProcessPacket(packet)) { 764 if (!framer_.ProcessPacket(packet)) {
765 // If we are unable to decrypt this packet, it might be
766 // because the CHLO or SHLO packet was lost.
767 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE &&
768 framer_.error() == QUIC_DECRYPTION_FAILURE &&
769 undecryptable_packets_.size() < kMaxUndecryptablePackets) {
770 QueueUndecryptablePacket(packet);
771 }
772 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: "
773 << last_header_.packet_sequence_number;
760 return; 774 return;
761 } 775 }
776 MaybeProcessUndecryptablePackets();
762 MaybeProcessRevivedPacket(); 777 MaybeProcessRevivedPacket();
763 } 778 }
764 779
765 bool QuicConnection::OnCanWrite() { 780 bool QuicConnection::OnCanWrite() {
766 write_blocked_ = false; 781 write_blocked_ = false;
767 782
768 WriteQueuedPackets(); 783 WriteQueuedPackets();
769 784
770 // Sending queued packets may have caused the socket to become write blocked, 785 // Sending queued packets may have caused the socket to become write blocked,
771 // or the congestion manager to prohibit sending. If we've sent everything 786 // or the congestion manager to prohibit sending. If we've sent everything
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } 993 }
979 994
980 bool QuicConnection::IsRetransmission( 995 bool QuicConnection::IsRetransmission(
981 QuicPacketSequenceNumber sequence_number) { 996 QuicPacketSequenceNumber sequence_number) {
982 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number); 997 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number);
983 return it != retransmission_map_.end() && 998 return it != retransmission_map_.end() &&
984 it->second.number_retransmissions > 0; 999 it->second.number_retransmissions > 0;
985 } 1000 }
986 1001
987 void QuicConnection::SetupRetransmission( 1002 void QuicConnection::SetupRetransmission(
988 QuicPacketSequenceNumber sequence_number) { 1003 QuicPacketSequenceNumber sequence_number,
1004 EncryptionLevel level) {
989 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number); 1005 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number);
990 if (it == retransmission_map_.end()) { 1006 if (it == retransmission_map_.end()) {
991 DVLOG(1) << ENDPOINT << "Will not retransmit packet " << sequence_number; 1007 DVLOG(1) << ENDPOINT << "Will not retransmit packet " << sequence_number;
992 return; 1008 return;
993 } 1009 }
994 1010
995 RetransmissionInfo retransmission_info = it->second; 1011 RetransmissionInfo retransmission_info = it->second;
1012 // TODO(rch): consider using a much smaller retransmisison_delay
1013 // for the ENCRYPTION_NONE packets.
1014 size_t effective_retransmission_count =
1015 level == ENCRYPTION_NONE ? 0 : retransmission_info.number_retransmissions;
996 QuicTime::Delta retransmission_delay = 1016 QuicTime::Delta retransmission_delay =
997 congestion_manager_.GetRetransmissionDelay( 1017 congestion_manager_.GetRetransmissionDelay(
998 unacked_packets_.size(), 1018 unacked_packets_.size(),
999 retransmission_info.number_retransmissions); 1019 effective_retransmission_count);
1000 1020
1001 retransmission_timeouts_.push(RetransmissionTime( 1021 retransmission_timeouts_.push(RetransmissionTime(
1002 sequence_number, 1022 sequence_number,
1003 clock_->ApproximateNow().Add(retransmission_delay), 1023 clock_->ApproximateNow().Add(retransmission_delay),
1004 false)); 1024 false));
1005 1025
1006 // Do not set the retransmisson alarm if we're already handling the 1026 // Do not set the retransmisson alarm if we're already handling the
1007 // retransmission alarm because the retransmission alarm will be reset when 1027 // retransmission alarm because the retransmission alarm will be reset when
1008 // OnRetransmissionTimeout completes. 1028 // OnRetransmissionTimeout completes.
1009 if (!handling_retransmission_timeout_) { 1029 if (!handling_retransmission_timeout_) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 if (!retransmission) { 1129 if (!retransmission) {
1110 time_of_last_sent_packet_ = now; 1130 time_of_last_sent_packet_ = now;
1111 } 1131 }
1112 DVLOG(1) << ENDPOINT << "time of last sent packet: " 1132 DVLOG(1) << ENDPOINT << "time of last sent packet: "
1113 << now.ToDebuggingValue(); 1133 << now.ToDebuggingValue();
1114 1134
1115 // Set the retransmit alarm only when we have sent the packet to the client 1135 // Set the retransmit alarm only when we have sent the packet to the client
1116 // and not when it goes to the pending queue, otherwise we will end up adding 1136 // and not when it goes to the pending queue, otherwise we will end up adding
1117 // an entry to retransmission_timeout_ every time we attempt a write. 1137 // an entry to retransmission_timeout_ every time we attempt a write.
1118 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { 1138 if (retransmittable == HAS_RETRANSMITTABLE_DATA) {
1119 SetupRetransmission(sequence_number); 1139 SetupRetransmission(sequence_number, level);
1120 } else if (packet->is_fec_packet()) { 1140 } else if (packet->is_fec_packet()) {
1121 SetupAbandonFecTimer(sequence_number); 1141 SetupAbandonFecTimer(sequence_number);
1122 } 1142 }
1123 1143
1124 congestion_manager_.SentPacket(sequence_number, now, packet->length(), 1144 congestion_manager_.SentPacket(sequence_number, now, packet->length(),
1125 retransmission); 1145 retransmission);
1126 1146
1127 stats_.bytes_sent += encrypted->length(); 1147 stats_.bytes_sent += encrypted->length();
1128 ++stats_.packets_sent; 1148 ++stats_.packets_sent;
1129 1149
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 } 1325 }
1306 1326
1307 const QuicDecrypter* QuicConnection::decrypter() const { 1327 const QuicDecrypter* QuicConnection::decrypter() const {
1308 return framer_.decrypter(); 1328 return framer_.decrypter();
1309 } 1329 }
1310 1330
1311 const QuicDecrypter* QuicConnection::alternative_decrypter() const { 1331 const QuicDecrypter* QuicConnection::alternative_decrypter() const {
1312 return framer_.alternative_decrypter(); 1332 return framer_.alternative_decrypter();
1313 } 1333 }
1314 1334
1335 void QuicConnection::QueueUndecryptablePacket(
1336 const QuicEncryptedPacket& packet) {
1337 DVLOG(1) << ENDPOINT << "Queueing undecryptable packet.";
1338 char* data = new char[packet.length()];
1339 memcpy(data, packet.data(), packet.length());
1340 undecryptable_packets_.push_back(
1341 new QuicEncryptedPacket(data, packet.length(), true));
1342 }
1343
1344 void QuicConnection::MaybeProcessUndecryptablePackets() {
1345 if (undecryptable_packets_.empty() ||
1346 encryption_level_ == ENCRYPTION_NONE) {
1347 return;
1348 }
1349
1350 while (!undecryptable_packets_.empty()) {
1351 DVLOG(1) << ENDPOINT << "Attempting to process undecryptable packet";
1352 QuicEncryptedPacket* packet = undecryptable_packets_.front();
1353 if (!framer_.ProcessPacket(*packet) &&
1354 framer_.error() == QUIC_DECRYPTION_FAILURE) {
1355 DVLOG(1) << ENDPOINT << "Unable to process undecryptable packet...";
1356 break;
1357 }
1358 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!";
1359 delete packet;
1360 undecryptable_packets_.pop_front();
1361 }
1362
1363 // Once forward secure encryption is in use, there will be no
1364 // new keys installed and hence any undecryptable packets will
1365 // never be able to be decrypted.
1366 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) {
1367 STLDeleteElements(&undecryptable_packets_);
1368 }
1369 }
1370
1315 void QuicConnection::MaybeProcessRevivedPacket() { 1371 void QuicConnection::MaybeProcessRevivedPacket() {
1316 QuicFecGroup* group = GetFecGroup(); 1372 QuicFecGroup* group = GetFecGroup();
1317 if (group == NULL || !group->CanRevive()) { 1373 if (group == NULL || !group->CanRevive()) {
1318 return; 1374 return;
1319 } 1375 }
1320 QuicPacketHeader revived_header; 1376 QuicPacketHeader revived_header;
1321 char revived_payload[kMaxPacketSize]; 1377 char revived_payload[kMaxPacketSize];
1322 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize); 1378 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize);
1323 revived_header.public_header.guid = guid_; 1379 revived_header.public_header.guid = guid_;
1324 revived_header.public_header.version_flag = false; 1380 revived_header.public_header.version_flag = false;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 if (connection_timeout < timeout) { 1553 if (connection_timeout < timeout) {
1498 timeout = connection_timeout; 1554 timeout = connection_timeout;
1499 } 1555 }
1500 } 1556 }
1501 1557
1502 helper_->SetTimeoutAlarm(timeout); 1558 helper_->SetTimeoutAlarm(timeout);
1503 return false; 1559 return false;
1504 } 1560 }
1505 1561
1506 } // namespace net 1562 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698