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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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_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 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 sent_packet_manager_.SetFromConfig(config); 275 sent_packet_manager_.SetFromConfig(config);
276 if (FLAGS_allow_truncated_connection_ids_for_quic && 276 if (FLAGS_allow_truncated_connection_ids_for_quic &&
277 config.HasReceivedBytesForConnectionId() && 277 config.HasReceivedBytesForConnectionId() &&
278 can_truncate_connection_ids_) { 278 can_truncate_connection_ids_) {
279 packet_generator_.SetConnectionIdLength( 279 packet_generator_.SetConnectionIdLength(
280 config.ReceivedBytesForConnectionId()); 280 config.ReceivedBytesForConnectionId());
281 } 281 }
282 max_undecryptable_packets_ = config.max_undecryptable_packets(); 282 max_undecryptable_packets_ = config.max_undecryptable_packets();
283 } 283 }
284 284
285 void QuicConnection::ResumeConnectionState(
286 const CachedNetworkParameters& cached_network_params) {
287 sent_packet_manager_.ResumeConnectionState(cached_network_params);
288 }
289
285 void QuicConnection::SetNumOpenStreams(size_t num_streams) { 290 void QuicConnection::SetNumOpenStreams(size_t num_streams) {
286 sent_packet_manager_.SetNumOpenStreams(num_streams); 291 sent_packet_manager_.SetNumOpenStreams(num_streams);
287 } 292 }
288 293
289 bool QuicConnection::SelectMutualVersion( 294 bool QuicConnection::SelectMutualVersion(
290 const QuicVersionVector& available_versions) { 295 const QuicVersionVector& available_versions) {
291 // Try to find the highest mutual version by iterating over supported 296 // Try to find the highest mutual version by iterating over supported
292 // versions, starting with the highest, and breaking out of the loop once we 297 // versions, starting with the highest, and breaking out of the loop once we
293 // find a matching version in the provided available_versions vector. 298 // find a matching version in the provided available_versions vector.
294 const QuicVersionVector& supported_versions = framer_.supported_versions(); 299 const QuicVersionVector& supported_versions = framer_.supported_versions();
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // If the incoming packet was missing, send an ack immediately. 909 // If the incoming packet was missing, send an ack immediately.
905 ack_queued_ = received_packet_manager_.IsMissing( 910 ack_queued_ = received_packet_manager_.IsMissing(
906 last_header_.packet_sequence_number); 911 last_header_.packet_sequence_number);
907 912
908 if (!ack_queued_ && ShouldLastPacketInstigateAck()) { 913 if (!ack_queued_ && ShouldLastPacketInstigateAck()) {
909 if (ack_alarm_->IsSet()) { 914 if (ack_alarm_->IsSet()) {
910 ack_queued_ = true; 915 ack_queued_ = true;
911 } else { 916 } else {
912 // Send an ack much more quickly for crypto handshake packets. 917 // Send an ack much more quickly for crypto handshake packets.
913 QuicTime::Delta delayed_ack_time = sent_packet_manager_.DelayedAckTime(); 918 QuicTime::Delta delayed_ack_time = sent_packet_manager_.DelayedAckTime();
914 if (last_stream_frames_.size() == 1 &&
915 last_stream_frames_[0].stream_id == kCryptoStreamId) {
916 delayed_ack_time = QuicTime::Delta::Zero();
917 }
918 ack_alarm_->Set(clock_->ApproximateNow().Add(delayed_ack_time)); 919 ack_alarm_->Set(clock_->ApproximateNow().Add(delayed_ack_time));
919 DVLOG(1) << "Ack timer set; next packet or timer will trigger ACK."; 920 DVLOG(1) << "Ack timer set; next packet or timer will trigger ACK.";
920 } 921 }
921 } 922 }
922 923
923 if (ack_queued_) { 924 if (ack_queued_) {
924 ack_alarm_->Cancel(); 925 ack_alarm_->Cancel();
925 } 926 }
926 } 927 }
927 928
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 << ", encryption level: " 1443 << ", encryption level: "
1443 << QuicUtils::EncryptionLevelToString(packet->encryption_level) 1444 << QuicUtils::EncryptionLevelToString(packet->encryption_level)
1444 << ", length:" 1445 << ", length:"
1445 << packet->serialized_packet.packet->length() 1446 << packet->serialized_packet.packet->length()
1446 << ", encrypted length:" 1447 << ", encrypted length:"
1447 << encrypted->length(); 1448 << encrypted->length();
1448 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl 1449 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl
1449 << QuicUtils::StringToHexASCIIDump( 1450 << QuicUtils::StringToHexASCIIDump(
1450 packet->serialized_packet.packet->AsStringPiece()); 1451 packet->serialized_packet.packet->AsStringPiece());
1451 1452
1453 QuicTime packet_send_time = QuicTime::Zero();
1454 if (FLAGS_quic_record_send_time_before_write) {
1455 // Measure the RTT from before the write begins to avoid underestimating the
1456 // min_rtt_, especially in cases where the thread blocks or gets swapped out
1457 // during the WritePacket below.
1458 packet_send_time = clock_->Now();
1459 }
1452 WriteResult result = writer_->WritePacket(encrypted->data(), 1460 WriteResult result = writer_->WritePacket(encrypted->data(),
1453 encrypted->length(), 1461 encrypted->length(),
1454 self_address().address(), 1462 self_address().address(),
1455 peer_address()); 1463 peer_address());
1456 if (result.error_code == ERR_IO_PENDING) { 1464 if (result.error_code == ERR_IO_PENDING) {
1457 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); 1465 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status);
1458 } 1466 }
1459 1467
1460 if (result.status == WRITE_STATUS_BLOCKED) { 1468 if (result.status == WRITE_STATUS_BLOCKED) {
1461 visitor_->OnWriteBlocked(); 1469 visitor_->OnWriteBlocked();
1462 // If the socket buffers the the data, then the packet should not 1470 // If the socket buffers the the data, then the packet should not
1463 // be queued and sent again, which would result in an unnecessary 1471 // be queued and sent again, which would result in an unnecessary
1464 // duplicate packet being sent. The helper must call OnCanWrite 1472 // duplicate packet being sent. The helper must call OnCanWrite
1465 // when the write completes, and OnWriteError if an error occurs. 1473 // when the write completes, and OnWriteError if an error occurs.
1466 if (!writer_->IsWriteBlockedDataBuffered()) { 1474 if (!writer_->IsWriteBlockedDataBuffered()) {
1467 return false; 1475 return false;
1468 } 1476 }
1469 } 1477 }
1470 QuicTime now = clock_->Now(); 1478 if (!FLAGS_quic_record_send_time_before_write) {
1479 packet_send_time = clock_->Now();
1480 }
1481 if (!packet_send_time.IsInitialized()) {
1482 // TODO(jokulik): This is only needed because of the two code paths for
1483 // initializing packet_send_time. Once "quic_record_send_time_before_write"
1484 // is deprecated, this check can be removed.
1485 LOG(DFATAL) << "The packet send time should never be zero. "
1486 << "This is a programming bug, please report it.";
1487 }
1471 if (result.status != WRITE_STATUS_ERROR && debug_visitor_.get() != nullptr) { 1488 if (result.status != WRITE_STATUS_ERROR && debug_visitor_.get() != nullptr) {
1472 // Pass the write result to the visitor. 1489 // Pass the write result to the visitor.
1473 debug_visitor_->OnPacketSent(packet->serialized_packet, 1490 debug_visitor_->OnPacketSent(packet->serialized_packet,
1474 packet->original_sequence_number, 1491 packet->original_sequence_number,
1475 packet->encryption_level, 1492 packet->encryption_level,
1476 packet->transmission_type, 1493 packet->transmission_type,
1477 *encrypted, 1494 *encrypted,
1478 now); 1495 packet_send_time);
1479 } 1496 }
1480 if (packet->transmission_type == NOT_RETRANSMISSION) { 1497 if (packet->transmission_type == NOT_RETRANSMISSION) {
1481 time_of_last_sent_new_packet_ = now; 1498 time_of_last_sent_new_packet_ = packet_send_time;
1482 } 1499 }
1483 SetPingAlarm(); 1500 SetPingAlarm();
1484 DVLOG(1) << ENDPOINT << "time of last sent packet: " 1501 DVLOG(1) << ENDPOINT << "time "
1485 << now.ToDebuggingValue(); 1502 << (FLAGS_quic_record_send_time_before_write ?
1503 "we began writing " : "we finished writing ")
1504 << "last sent packet: "
1505 << packet_send_time.ToDebuggingValue();
1486 1506
1487 // TODO(ianswett): Change the sequence number length and other packet creator 1507 // TODO(ianswett): Change the sequence number length and other packet creator
1488 // options by a more explicit API than setting a struct value directly, 1508 // options by a more explicit API than setting a struct value directly,
1489 // perhaps via the NetworkChangeVisitor. 1509 // perhaps via the NetworkChangeVisitor.
1490 packet_generator_.UpdateSequenceNumberLength( 1510 packet_generator_.UpdateSequenceNumberLength(
1491 sent_packet_manager_.least_packet_awaited_by_peer(), 1511 sent_packet_manager_.least_packet_awaited_by_peer(),
1492 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1512 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1493 1513
1494 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1514 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
1495 &packet->serialized_packet, 1515 &packet->serialized_packet,
1496 packet->original_sequence_number, 1516 packet->original_sequence_number,
1497 now, 1517 packet_send_time,
1498 encrypted->length(), 1518 encrypted->length(),
1499 packet->transmission_type, 1519 packet->transmission_type,
1500 IsRetransmittable(*packet)); 1520 IsRetransmittable(*packet));
1501 1521
1502 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1522 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1503 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(), 1523 retransmission_alarm_->Update(sent_packet_manager_.GetRetransmissionTime(),
1504 QuicTime::Delta::FromMilliseconds(1)); 1524 QuicTime::Delta::FromMilliseconds(1));
1505 } 1525 }
1506 1526
1507 stats_.bytes_sent += result.bytes_written; 1527 stats_.bytes_sent += result.bytes_written;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 } 1598 }
1579 1599
1580 void QuicConnection::OnCongestionWindowChange() { 1600 void QuicConnection::OnCongestionWindowChange() {
1581 packet_generator_.OnCongestionWindowChange( 1601 packet_generator_.OnCongestionWindowChange(
1582 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1602 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1583 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); 1603 visitor_->OnCongestionWindowChange(clock_->ApproximateNow());
1584 } 1604 }
1585 1605
1586 void QuicConnection::OnHandshakeComplete() { 1606 void QuicConnection::OnHandshakeComplete() {
1587 sent_packet_manager_.SetHandshakeConfirmed(); 1607 sent_packet_manager_.SetHandshakeConfirmed();
1608 // The client should immediately ack the SHLO to confirm the handshake is
1609 // complete with the server.
1610 if (!is_server_ && !ack_queued_) {
1611 ack_alarm_->Cancel();
1612 ack_alarm_->Set(clock_->ApproximateNow());
1613 }
1588 } 1614 }
1589 1615
1590 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) { 1616 void QuicConnection::SendOrQueuePacket(QueuedPacket packet) {
1591 // The caller of this function is responsible for checking CanWrite(). 1617 // The caller of this function is responsible for checking CanWrite().
1592 if (packet.serialized_packet.packet == nullptr) { 1618 if (packet.serialized_packet.packet == nullptr) {
1593 LOG(DFATAL) 1619 LOG(DFATAL)
1594 << "packet.serialized_packet.packet == nullptr in to SendOrQueuePacket"; 1620 << "packet.serialized_packet.packet == nullptr in to SendOrQueuePacket";
1595 return; 1621 return;
1596 } 1622 }
1597 1623
1598 sent_entropy_manager_.RecordPacketEntropyHash( 1624 sent_entropy_manager_.RecordPacketEntropyHash(
1599 packet.serialized_packet.sequence_number, 1625 packet.serialized_packet.sequence_number,
1600 packet.serialized_packet.entropy_hash); 1626 packet.serialized_packet.entropy_hash);
1601 LOG_IF(DFATAL, !queued_packets_.empty() && !writer_->IsWriteBlocked())
1602 << "Packets should only be left queued if we're write blocked.";
1603 if (!WritePacket(&packet)) { 1627 if (!WritePacket(&packet)) {
1604 queued_packets_.push_back(packet); 1628 queued_packets_.push_back(packet);
1605 } 1629 }
1606 } 1630 }
1607 1631
1608 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { 1632 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) {
1609 stop_waiting->least_unacked = GetLeastUnacked(); 1633 stop_waiting->least_unacked = GetLeastUnacked();
1610 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( 1634 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy(
1611 stop_waiting->least_unacked - 1); 1635 stop_waiting->least_unacked - 1);
1612 } 1636 }
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 } 2092 }
2069 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { 2093 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) {
2070 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { 2094 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) {
2071 return true; 2095 return true;
2072 } 2096 }
2073 } 2097 }
2074 return false; 2098 return false;
2075 } 2099 }
2076 2100
2077 } // namespace net 2101 } // 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