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

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

Issue 476023002: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0814_2
Patch Set: Created 6 years, 4 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_alarm_test.cc ('k') | net/quic/quic_connection_helper_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 <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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), 221 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))),
222 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), 222 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))),
223 packet_generator_(connection_id_, &framer_, random_generator_, this), 223 packet_generator_(connection_id_, &framer_, random_generator_, this),
224 idle_network_timeout_( 224 idle_network_timeout_(
225 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), 225 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)),
226 overall_connection_timeout_(QuicTime::Delta::Infinite()), 226 overall_connection_timeout_(QuicTime::Delta::Infinite()),
227 time_of_last_received_packet_(clock_->ApproximateNow()), 227 time_of_last_received_packet_(clock_->ApproximateNow()),
228 time_of_last_sent_new_packet_(clock_->ApproximateNow()), 228 time_of_last_sent_new_packet_(clock_->ApproximateNow()),
229 sequence_number_of_last_sent_packet_(0), 229 sequence_number_of_last_sent_packet_(0),
230 sent_packet_manager_( 230 sent_packet_manager_(
231 is_server, clock_, &stats_, kCubic, 231 is_server, clock_, &stats_,
232 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic,
232 FLAGS_quic_use_time_loss_detection ? kTime : kNack), 233 FLAGS_quic_use_time_loss_detection ? kTime : kNack),
233 version_negotiation_state_(START_NEGOTIATION), 234 version_negotiation_state_(START_NEGOTIATION),
234 is_server_(is_server), 235 is_server_(is_server),
235 connected_(true), 236 connected_(true),
236 peer_ip_changed_(false), 237 peer_ip_changed_(false),
237 peer_port_changed_(false), 238 peer_port_changed_(false),
238 self_ip_changed_(false), 239 self_ip_changed_(false),
239 self_port_changed_(false) { 240 self_port_changed_(false) {
240 #if 0 241 #if 0
241 // TODO(rtenneti): Should we enable this code in chromium? 242 // TODO(rtenneti): Should we enable this code in chromium?
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 CloseConnection(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, false); 402 CloseConnection(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, false);
402 return; 403 return;
403 } 404 }
404 405
405 if (!SelectMutualVersion(packet.versions)) { 406 if (!SelectMutualVersion(packet.versions)) {
406 SendConnectionCloseWithDetails(QUIC_INVALID_VERSION, 407 SendConnectionCloseWithDetails(QUIC_INVALID_VERSION,
407 "no common version found"); 408 "no common version found");
408 return; 409 return;
409 } 410 }
410 411
411 DVLOG(1) << ENDPOINT << "negotiating version " << version(); 412 DVLOG(1) << ENDPOINT
413 << "Negotiated version: " << QuicVersionToString(version());
412 server_supported_versions_ = packet.versions; 414 server_supported_versions_ = packet.versions;
413 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; 415 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS;
414 RetransmitUnackedPackets(ALL_PACKETS); 416 RetransmitUnackedPackets(ALL_PACKETS);
415 } 417 }
416 418
417 void QuicConnection::OnRevivedPacket() { 419 void QuicConnection::OnRevivedPacket() {
418 } 420 }
419 421
420 bool QuicConnection::OnUnauthenticatedPublicHeader( 422 bool QuicConnection::OnUnauthenticatedPublicHeader(
421 const QuicPacketPublicHeader& header) { 423 const QuicPacketPublicHeader& header) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 received_packet_manager_.least_packet_awaited_by_peer() - 1); 564 received_packet_manager_.least_packet_awaited_by_peer() - 1);
563 565
564 sent_packet_manager_.OnIncomingAck(incoming_ack, 566 sent_packet_manager_.OnIncomingAck(incoming_ack,
565 time_of_last_received_packet_); 567 time_of_last_received_packet_);
566 if (sent_packet_manager_.HasPendingRetransmissions()) { 568 if (sent_packet_manager_.HasPendingRetransmissions()) {
567 WriteIfNotBlocked(); 569 WriteIfNotBlocked();
568 } 570 }
569 571
570 // Always reset the retransmission alarm when an ack comes in, since we now 572 // Always reset the retransmission alarm when an ack comes in, since we now
571 // have a better estimate of the current rtt than when it was set. 573 // have a better estimate of the current rtt than when it was set.
572 retransmission_alarm_->Cancel();
573 QuicTime retransmission_time = 574 QuicTime retransmission_time =
574 sent_packet_manager_.GetRetransmissionTime(); 575 sent_packet_manager_.GetRetransmissionTime();
575 if (retransmission_time != QuicTime::Zero()) { 576 retransmission_alarm_->Update(retransmission_time,
576 retransmission_alarm_->Set(retransmission_time); 577 QuicTime::Delta::FromMilliseconds(1));
577 }
578 } 578 }
579 579
580 void QuicConnection::ProcessStopWaitingFrame( 580 void QuicConnection::ProcessStopWaitingFrame(
581 const QuicStopWaitingFrame& stop_waiting) { 581 const QuicStopWaitingFrame& stop_waiting) {
582 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; 582 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number;
583 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); 583 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting);
584 // Possibly close any FecGroups which are now irrelevant. 584 // Possibly close any FecGroups which are now irrelevant.
585 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); 585 CloseFecGroupsBefore(stop_waiting.least_unacked + 1);
586 } 586 }
587 587
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 } 963 }
964 } 964 }
965 965
966 void QuicConnection::SendVersionNegotiationPacket() { 966 void QuicConnection::SendVersionNegotiationPacket() {
967 // TODO(alyssar): implement zero server state negotiation. 967 // TODO(alyssar): implement zero server state negotiation.
968 pending_version_negotiation_packet_ = true; 968 pending_version_negotiation_packet_ = true;
969 if (writer_->IsWriteBlocked()) { 969 if (writer_->IsWriteBlocked()) {
970 visitor_->OnWriteBlocked(); 970 visitor_->OnWriteBlocked();
971 return; 971 return;
972 } 972 }
973 DVLOG(1) << ENDPOINT << "Sending version negotiation packet: {"
974 << QuicVersionVectorToString(framer_.supported_versions()) << "}";
973 scoped_ptr<QuicEncryptedPacket> version_packet( 975 scoped_ptr<QuicEncryptedPacket> version_packet(
974 packet_generator_.SerializeVersionNegotiationPacket( 976 packet_generator_.SerializeVersionNegotiationPacket(
975 framer_.supported_versions())); 977 framer_.supported_versions()));
976 WriteResult result = writer_->WritePacket( 978 WriteResult result = writer_->WritePacket(
977 version_packet->data(), version_packet->length(), 979 version_packet->data(), version_packet->length(),
978 self_address().address(), peer_address()); 980 self_address().address(), peer_address());
979 981
980 if (result.status == WRITE_STATUS_ERROR) { 982 if (result.status == WRITE_STATUS_ERROR) {
981 // We can't send an error as the socket is presumably borked. 983 // We can't send an error as the socket is presumably borked.
982 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); 984 CloseConnection(QUIC_PACKET_WRITE_ERROR, false);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 void QuicConnection::RetransmitUnackedPackets( 1273 void QuicConnection::RetransmitUnackedPackets(
1272 RetransmissionType retransmission_type) { 1274 RetransmissionType retransmission_type) {
1273 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type); 1275 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type);
1274 1276
1275 WriteIfNotBlocked(); 1277 WriteIfNotBlocked();
1276 } 1278 }
1277 1279
1278 void QuicConnection::NeuterUnencryptedPackets() { 1280 void QuicConnection::NeuterUnencryptedPackets() {
1279 sent_packet_manager_.NeuterUnencryptedPackets(); 1281 sent_packet_manager_.NeuterUnencryptedPackets();
1280 // This may have changed the retransmission timer, so re-arm it. 1282 // This may have changed the retransmission timer, so re-arm it.
1281 retransmission_alarm_->Cancel();
1282 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); 1283 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime();
1283 if (retransmission_time != QuicTime::Zero()) { 1284 retransmission_alarm_->Update(retransmission_time,
1284 retransmission_alarm_->Set(retransmission_time); 1285 QuicTime::Delta::FromMilliseconds(1));
1285 }
1286 } 1286 }
1287 1287
1288 bool QuicConnection::ShouldGeneratePacket( 1288 bool QuicConnection::ShouldGeneratePacket(
1289 TransmissionType transmission_type, 1289 TransmissionType transmission_type,
1290 HasRetransmittableData retransmittable, 1290 HasRetransmittableData retransmittable,
1291 IsHandshake handshake) { 1291 IsHandshake handshake) {
1292 // We should serialize handshake packets immediately to ensure that they 1292 // We should serialize handshake packets immediately to ensure that they
1293 // end up sent at the right encryption level. 1293 // end up sent at the right encryption level.
1294 if (handshake == IS_HANDSHAKE) { 1294 if (handshake == IS_HANDSHAKE) {
1295 return true; 1295 return true;
1296 } 1296 }
1297 1297
1298 return CanWrite(retransmittable); 1298 return CanWrite(retransmittable);
1299 } 1299 }
1300 1300
1301 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) { 1301 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) {
1302 if (writer_->IsWriteBlocked()) { 1302 if (writer_->IsWriteBlocked()) {
1303 visitor_->OnWriteBlocked(); 1303 visitor_->OnWriteBlocked();
1304 return false; 1304 return false;
1305 } 1305 }
1306 1306
1307 send_alarm_->Cancel();
1308 QuicTime now = clock_->Now(); 1307 QuicTime now = clock_->Now();
1309 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend( 1308 QuicTime::Delta delay = sent_packet_manager_.TimeUntilSend(
1310 now, retransmittable); 1309 now, retransmittable);
1311 if (delay.IsInfinite()) { 1310 if (delay.IsInfinite()) {
1311 send_alarm_->Cancel();
1312 return false; 1312 return false;
1313 } 1313 }
1314 1314
1315 // If the scheduler requires a delay, then we can not send this packet now. 1315 // If the scheduler requires a delay, then we can not send this packet now.
1316 if (!delay.IsZero()) { 1316 if (!delay.IsZero()) {
1317 send_alarm_->Set(now.Add(delay)); 1317 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1));
1318 DVLOG(1) << "Delaying sending."; 1318 DVLOG(1) << "Delaying sending.";
1319 return false; 1319 return false;
1320 } 1320 }
1321 send_alarm_->Cancel();
1321 return true; 1322 return true;
1322 } 1323 }
1323 1324
1324 bool QuicConnection::WritePacket(QueuedPacket packet) { 1325 bool QuicConnection::WritePacket(QueuedPacket packet) {
1325 QuicPacketSequenceNumber sequence_number = packet.sequence_number; 1326 QuicPacketSequenceNumber sequence_number = packet.sequence_number;
1326 if (ShouldDiscardPacket(packet.encryption_level, 1327 if (ShouldDiscardPacket(packet.encryption_level,
1327 sequence_number, 1328 sequence_number,
1328 packet.retransmittable)) { 1329 packet.retransmittable)) {
1329 ++stats_.packets_discarded; 1330 ++stats_.packets_discarded;
1330 return true; 1331 return true;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 // options by a more explicit API than setting a struct value directly. 1505 // options by a more explicit API than setting a struct value directly.
1505 packet_generator_.UpdateSequenceNumberLength( 1506 packet_generator_.UpdateSequenceNumberLength(
1506 received_packet_manager_.least_packet_awaited_by_peer(), 1507 received_packet_manager_.least_packet_awaited_by_peer(),
1507 sent_packet_manager_.GetCongestionWindow()); 1508 sent_packet_manager_.GetCongestionWindow());
1508 1509
1509 bool reset_retransmission_alarm = 1510 bool reset_retransmission_alarm =
1510 sent_packet_manager_.OnPacketSent(sequence_number, now, length, 1511 sent_packet_manager_.OnPacketSent(sequence_number, now, length,
1511 transmission_type, retransmittable); 1512 transmission_type, retransmittable);
1512 1513
1513 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1514 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1514 retransmission_alarm_->Cancel();
1515 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); 1515 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime();
1516 if (retransmission_time != QuicTime::Zero()) { 1516 retransmission_alarm_->Update(retransmission_time,
1517 retransmission_alarm_->Set(retransmission_time); 1517 QuicTime::Delta::FromMilliseconds(1));
1518 }
1519 } 1518 }
1520 1519
1521 stats_.bytes_sent += result.bytes_written; 1520 stats_.bytes_sent += result.bytes_written;
1522 ++stats_.packets_sent; 1521 ++stats_.packets_sent;
1523 1522
1524 if (transmission_type != NOT_RETRANSMISSION) { 1523 if (transmission_type != NOT_RETRANSMISSION) {
1525 stats_.bytes_retransmitted += result.bytes_written; 1524 stats_.bytes_retransmitted += result.bytes_written;
1526 ++stats_.packets_retransmitted; 1525 ++stats_.packets_retransmitted;
1527 } 1526 }
1528 1527
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 // to send new data before retransmitting. 1624 // to send new data before retransmitting.
1626 if (sent_packet_manager_.MaybeRetransmitTailLossProbe()) { 1625 if (sent_packet_manager_.MaybeRetransmitTailLossProbe()) {
1627 // Send the pending retransmission now that it's been queued. 1626 // Send the pending retransmission now that it's been queued.
1628 WriteIfNotBlocked(); 1627 WriteIfNotBlocked();
1629 } 1628 }
1630 1629
1631 // Ensure the retransmission alarm is always set if there are unacked packets 1630 // Ensure the retransmission alarm is always set if there are unacked packets
1632 // and nothing waiting to be sent. 1631 // and nothing waiting to be sent.
1633 if (!HasQueuedData() && !retransmission_alarm_->IsSet()) { 1632 if (!HasQueuedData() && !retransmission_alarm_->IsSet()) {
1634 QuicTime rto_timeout = sent_packet_manager_.GetRetransmissionTime(); 1633 QuicTime rto_timeout = sent_packet_manager_.GetRetransmissionTime();
1635 if (rto_timeout != QuicTime::Zero()) { 1634 if (rto_timeout.IsInitialized()) {
1636 retransmission_alarm_->Set(rto_timeout); 1635 retransmission_alarm_->Set(rto_timeout);
1637 } 1636 }
1638 } 1637 }
1639 } 1638 }
1640 1639
1641 void QuicConnection::SetEncrypter(EncryptionLevel level, 1640 void QuicConnection::SetEncrypter(EncryptionLevel level,
1642 QuicEncrypter* encrypter) { 1641 QuicEncrypter* encrypter) {
1643 framer_.SetEncrypter(level, encrypter); 1642 framer_.SetEncrypter(level, encrypter);
1644 } 1643 }
1645 1644
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 IS_HANDSHAKE : NOT_HANDSHAKE; 1874 IS_HANDSHAKE : NOT_HANDSHAKE;
1876 // Sending queued packets may have caused the socket to become write blocked, 1875 // Sending queued packets may have caused the socket to become write blocked,
1877 // or the congestion manager to prohibit sending. If we've sent everything 1876 // or the congestion manager to prohibit sending. If we've sent everything
1878 // we had queued and we're still not blocked, let the visitor know it can 1877 // we had queued and we're still not blocked, let the visitor know it can
1879 // write more. 1878 // write more.
1880 return ShouldGeneratePacket(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, 1879 return ShouldGeneratePacket(NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA,
1881 pending_handshake); 1880 pending_handshake);
1882 } 1881 }
1883 1882
1884 void QuicConnection::SetIdleNetworkTimeout(QuicTime::Delta timeout) { 1883 void QuicConnection::SetIdleNetworkTimeout(QuicTime::Delta timeout) {
1884 // Adjust the idle timeout on client and server to prevent clients from
1885 // sending requests to servers which have already closed the connection.
1886 if (is_server_) {
1887 timeout = timeout.Add(QuicTime::Delta::FromSeconds(1));
1888 } else if (timeout > QuicTime::Delta::FromSeconds(1)) {
1889 timeout = timeout.Subtract(QuicTime::Delta::FromSeconds(1));
1890 }
1891
1885 if (timeout < idle_network_timeout_) { 1892 if (timeout < idle_network_timeout_) {
1886 idle_network_timeout_ = timeout; 1893 idle_network_timeout_ = timeout;
1887 CheckForTimeout(); 1894 CheckForTimeout();
1888 } else { 1895 } else {
1889 idle_network_timeout_ = timeout; 1896 idle_network_timeout_ = timeout;
1890 } 1897 }
1891 } 1898 }
1892 1899
1893 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { 1900 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) {
1894 if (timeout < overall_connection_timeout_) { 1901 if (timeout < overall_connection_timeout_) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 1944
1938 // Take the min timeout. 1945 // Take the min timeout.
1939 QuicTime::Delta connection_timeout = 1946 QuicTime::Delta connection_timeout =
1940 overall_connection_timeout_.Subtract(connected_time); 1947 overall_connection_timeout_.Subtract(connected_time);
1941 if (connection_timeout < timeout) { 1948 if (connection_timeout < timeout) {
1942 timeout = connection_timeout; 1949 timeout = connection_timeout;
1943 } 1950 }
1944 } 1951 }
1945 1952
1946 timeout_alarm_->Cancel(); 1953 timeout_alarm_->Cancel();
1947 timeout_alarm_->Set(clock_->ApproximateNow().Add(timeout)); 1954 timeout_alarm_->Set(now.Add(timeout));
1948 return false; 1955 return false;
1949 } 1956 }
1950 1957
1951 void QuicConnection::SetPingAlarm() { 1958 void QuicConnection::SetPingAlarm() {
1952 if (is_server_) { 1959 if (is_server_) {
1953 // Only clients send pings. 1960 // Only clients send pings.
1954 return; 1961 return;
1955 } 1962 }
1956 ping_alarm_->Cancel();
1957 if (!visitor_->HasOpenDataStreams()) { 1963 if (!visitor_->HasOpenDataStreams()) {
1964 ping_alarm_->Cancel();
1958 // Don't send a ping unless there are open streams. 1965 // Don't send a ping unless there are open streams.
1959 return; 1966 return;
1960 } 1967 }
1961 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); 1968 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs);
1962 ping_alarm_->Set(clock_->ApproximateNow().Add(ping_timeout)); 1969 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout),
1970 QuicTime::Delta::FromSeconds(1));
1963 } 1971 }
1964 1972
1965 QuicConnection::ScopedPacketBundler::ScopedPacketBundler( 1973 QuicConnection::ScopedPacketBundler::ScopedPacketBundler(
1966 QuicConnection* connection, 1974 QuicConnection* connection,
1967 AckBundling send_ack) 1975 AckBundling send_ack)
1968 : connection_(connection), 1976 : connection_(connection),
1969 already_in_batch_mode_(connection != NULL && 1977 already_in_batch_mode_(connection != NULL &&
1970 connection->packet_generator_.InBatchMode()) { 1978 connection->packet_generator_.InBatchMode()) {
1971 if (connection_ == NULL) { 1979 if (connection_ == NULL) {
1972 return; 1980 return;
(...skipping 21 matching lines...) Expand all
1994 // If we changed the generator's batch state, restore original batch state. 2002 // If we changed the generator's batch state, restore original batch state.
1995 if (!already_in_batch_mode_) { 2003 if (!already_in_batch_mode_) {
1996 DVLOG(1) << "Leaving Batch Mode."; 2004 DVLOG(1) << "Leaving Batch Mode.";
1997 connection_->packet_generator_.FinishBatchOperations(); 2005 connection_->packet_generator_.FinishBatchOperations();
1998 } 2006 }
1999 DCHECK_EQ(already_in_batch_mode_, 2007 DCHECK_EQ(already_in_batch_mode_,
2000 connection_->packet_generator_.InBatchMode()); 2008 connection_->packet_generator_.InBatchMode());
2001 } 2009 }
2002 2010
2003 } // namespace net 2011 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_alarm_test.cc ('k') | net/quic/quic_connection_helper_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698