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

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

Issue 1979763002: Landing Recent QUIC changes until Sun May 8 00:39:29 2016 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 << " packet_number:" << last_header_.packet_number 696 << " packet_number:" << last_header_.packet_number
697 << " stream_id:" << frame.stream_id 697 << " stream_id:" << frame.stream_id
698 << " received_packets:" << received_packet_manager_.ack_frame(); 698 << " received_packets:" << received_packet_manager_.ack_frame();
699 CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA, 699 CloseConnection(QUIC_UNENCRYPTED_STREAM_DATA,
700 "Unencrypted stream data seen.", 700 "Unencrypted stream data seen.",
701 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 701 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
702 return false; 702 return false;
703 } 703 }
704 visitor_->OnStreamFrame(frame); 704 visitor_->OnStreamFrame(frame);
705 visitor_->PostProcessAfterData(); 705 visitor_->PostProcessAfterData();
706 stats_.stream_bytes_received += frame.frame_length; 706 stats_.stream_bytes_received += frame.data_length;
707 should_last_packet_instigate_acks_ = true; 707 should_last_packet_instigate_acks_ = true;
708 return connected_; 708 return connected_;
709 } 709 }
710 710
711 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { 711 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) {
712 DCHECK(connected_); 712 DCHECK(connected_);
713 if (debug_visitor_ != nullptr) { 713 if (debug_visitor_ != nullptr) {
714 debug_visitor_->OnAckFrame(incoming_ack); 714 debug_visitor_->OnAckFrame(incoming_ack);
715 } 715 }
716 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; 716 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack;
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 if (!IsInitializedIPEndPoint(self_address_)) { 1296 if (!IsInitializedIPEndPoint(self_address_)) {
1297 self_address_ = last_packet_destination_address_; 1297 self_address_ = last_packet_destination_address_;
1298 } 1298 }
1299 if (!IsInitializedIPEndPoint(peer_address_)) { 1299 if (!IsInitializedIPEndPoint(peer_address_)) {
1300 peer_address_ = last_packet_source_address_; 1300 peer_address_ = last_packet_source_address_;
1301 } 1301 }
1302 1302
1303 stats_.bytes_received += packet.length(); 1303 stats_.bytes_received += packet.length();
1304 ++stats_.packets_received; 1304 ++stats_.packets_received;
1305 1305
1306 if (FLAGS_quic_use_socket_timestamp) { 1306 time_of_last_received_packet_ = packet.receipt_time();
1307 time_of_last_received_packet_ = packet.receipt_time(); 1307 DVLOG(1) << ENDPOINT << "time of last received packet: "
1308 DVLOG(1) << ENDPOINT << "time of last received packet: " 1308 << time_of_last_received_packet_.ToDebuggingValue();
1309 << time_of_last_received_packet_.ToDebuggingValue();
1310 }
1311 1309
1312 ScopedRetransmissionScheduler alarm_delayer(this); 1310 ScopedRetransmissionScheduler alarm_delayer(this);
1313 if (!framer_.ProcessPacket(packet)) { 1311 if (!framer_.ProcessPacket(packet)) {
1314 // If we are unable to decrypt this packet, it might be 1312 // If we are unable to decrypt this packet, it might be
1315 // because the CHLO or SHLO packet was lost. 1313 // because the CHLO or SHLO packet was lost.
1316 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { 1314 if (framer_.error() == QUIC_DECRYPTION_FAILURE) {
1317 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && 1315 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE &&
1318 undecryptable_packets_.size() < max_undecryptable_packets_) { 1316 undecryptable_packets_.size() < max_undecryptable_packets_) {
1319 QueueUndecryptablePacket(packet); 1317 QueueUndecryptablePacket(packet);
1320 } else if (debug_visitor_ != nullptr) { 1318 } else if (debug_visitor_ != nullptr) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 visitor_->PostProcessAfterData(); 1357 visitor_->PostProcessAfterData();
1360 } 1358 }
1361 1359
1362 // After the visitor writes, it may have caused the socket to become write 1360 // After the visitor writes, it may have caused the socket to become write
1363 // blocked or the congestion manager to prohibit sending, so check again. 1361 // blocked or the congestion manager to prohibit sending, so check again.
1364 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && 1362 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() &&
1365 CanWrite(HAS_RETRANSMITTABLE_DATA)) { 1363 CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1366 // We're not write blocked, but some stream didn't write out all of its 1364 // We're not write blocked, but some stream didn't write out all of its
1367 // bytes. Register for 'immediate' resumption so we'll keep writing after 1365 // bytes. Register for 'immediate' resumption so we'll keep writing after
1368 // other connections and events have had a chance to use the thread. 1366 // other connections and events have had a chance to use the thread.
1369 resume_writes_alarm_->Set(clock_->ApproximateNow()); 1367 if (FLAGS_quic_only_one_sending_alarm) {
1368 send_alarm_->Update(clock_->ApproximateNow(), QuicTime::Delta::Zero());
1369 } else {
1370 resume_writes_alarm_->Set(clock_->ApproximateNow());
1371 }
1370 } 1372 }
1371 } 1373 }
1372 1374
1373 void QuicConnection::WriteIfNotBlocked() { 1375 void QuicConnection::WriteIfNotBlocked() {
1374 if (!writer_->IsWriteBlocked()) { 1376 if (!writer_->IsWriteBlocked()) {
1375 OnCanWrite(); 1377 OnCanWrite();
1376 } 1378 }
1377 } 1379 }
1378 1380
1379 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { 1381 void QuicConnection::WriteAndBundleAcksIfNotBlocked() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 received_packet_manager_.SetVersion(version()); 1441 received_packet_manager_.SetVersion(version());
1440 visitor_->OnSuccessfulVersionNegotiation(version()); 1442 visitor_->OnSuccessfulVersionNegotiation(version());
1441 if (debug_visitor_ != nullptr) { 1443 if (debug_visitor_ != nullptr) {
1442 debug_visitor_->OnSuccessfulVersionNegotiation(version()); 1444 debug_visitor_->OnSuccessfulVersionNegotiation(version());
1443 } 1445 }
1444 } 1446 }
1445 } 1447 }
1446 1448
1447 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); 1449 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_);
1448 1450
1449 if (!FLAGS_quic_use_socket_timestamp) {
1450 time_of_last_received_packet_ = clock_->Now();
1451 DVLOG(1) << ENDPOINT << "time of last received packet: "
1452 << time_of_last_received_packet_.ToDebuggingValue();
1453 }
1454
1455 if (last_size_ > largest_received_packet_size_) { 1451 if (last_size_ > largest_received_packet_size_) {
1456 largest_received_packet_size_ = last_size_; 1452 largest_received_packet_size_ = last_size_;
1457 } 1453 }
1458 1454
1459 if (perspective_ == Perspective::IS_SERVER && 1455 if (perspective_ == Perspective::IS_SERVER &&
1460 encryption_level_ == ENCRYPTION_NONE && 1456 encryption_level_ == ENCRYPTION_NONE &&
1461 last_size_ > packet_generator_.GetCurrentMaxPacketLength()) { 1457 last_size_ > packet_generator_.GetCurrentMaxPacketLength()) {
1462 SetMaxPacketLength(last_size_); 1458 SetMaxPacketLength(last_size_);
1463 } 1459 }
1464 return true; 1460 return true;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 // If the socket buffers the the data, then the packet should not 1633 // If the socket buffers the the data, then the packet should not
1638 // be queued and sent again, which would result in an unnecessary 1634 // be queued and sent again, which would result in an unnecessary
1639 // duplicate packet being sent. The helper must call OnCanWrite 1635 // duplicate packet being sent. The helper must call OnCanWrite
1640 // when the write completes, and OnWriteError if an error occurs. 1636 // when the write completes, and OnWriteError if an error occurs.
1641 if (!writer_->IsWriteBlockedDataBuffered()) { 1637 if (!writer_->IsWriteBlockedDataBuffered()) {
1642 return false; 1638 return false;
1643 } 1639 }
1644 } 1640 }
1645 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) { 1641 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) {
1646 // Pass the write result to the visitor. 1642 // Pass the write result to the visitor.
1647 debug_visitor_->OnPacketSent(*packet, packet->original_packet_number, 1643 debug_visitor_->OnPacketSent(*packet, packet->original_path_id,
1644 packet->original_packet_number,
1648 packet->transmission_type, packet_send_time); 1645 packet->transmission_type, packet_send_time);
1649 } 1646 }
1650 if (packet->transmission_type == NOT_RETRANSMISSION) { 1647 if (packet->transmission_type == NOT_RETRANSMISSION) {
1651 time_of_last_sent_new_packet_ = packet_send_time; 1648 time_of_last_sent_new_packet_ = packet_send_time;
1652 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA && 1649 if (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA &&
1653 last_send_for_timeout_ <= time_of_last_received_packet_) { 1650 last_send_for_timeout_ <= time_of_last_received_packet_) {
1654 last_send_for_timeout_ = packet_send_time; 1651 last_send_for_timeout_ = packet_send_time;
1655 } 1652 }
1656 } 1653 }
1657 SetPingAlarm(); 1654 SetPingAlarm();
1658 MaybeSetMtuAlarm(); 1655 MaybeSetMtuAlarm();
1659 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " 1656 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: "
1660 << packet_send_time.ToDebuggingValue(); 1657 << packet_send_time.ToDebuggingValue();
1661 1658
1662 // TODO(ianswett): Change the packet number length and other packet creator 1659 // TODO(ianswett): Change the packet number length and other packet creator
1663 // options by a more explicit API than setting a struct value directly, 1660 // options by a more explicit API than setting a struct value directly,
1664 // perhaps via the NetworkChangeVisitor. 1661 // perhaps via the NetworkChangeVisitor.
1665 packet_generator_.UpdateSequenceNumberLength( 1662 packet_generator_.UpdateSequenceNumberLength(
1666 sent_packet_manager_.least_packet_awaited_by_peer(), 1663 sent_packet_manager_.least_packet_awaited_by_peer(),
1667 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1664 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1668 1665
1669 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1666 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
1670 packet, packet->original_packet_number, packet_send_time, 1667 packet, packet->original_path_id, packet->original_packet_number,
1671 packet->transmission_type, IsRetransmittable(*packet)); 1668 packet_send_time, packet->transmission_type, IsRetransmittable(*packet));
1672 1669
1673 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1670 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1674 SetRetransmissionAlarm(); 1671 SetRetransmissionAlarm();
1675 } 1672 }
1676 1673
1677 stats_.bytes_sent += result.bytes_written; 1674 stats_.bytes_sent += result.bytes_written;
1678 ++stats_.packets_sent; 1675 ++stats_.packets_sent;
1679 if (packet->transmission_type != NOT_RETRANSMISSION) { 1676 if (packet->transmission_type != NOT_RETRANSMISSION) {
1680 stats_.bytes_retransmitted += result.bytes_written; 1677 stats_.bytes_retransmitted += result.bytes_written;
1681 ++stats_.packets_retransmitted; 1678 ++stats_.packets_retransmitted;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 } 1750 }
1754 1751
1755 void QuicConnection::OnUnrecoverableError(QuicErrorCode error, 1752 void QuicConnection::OnUnrecoverableError(QuicErrorCode error,
1756 const string& error_details, 1753 const string& error_details,
1757 ConnectionCloseSource source) { 1754 ConnectionCloseSource source) {
1758 // The packet creator or generator encountered an unrecoverable error: tear 1755 // The packet creator or generator encountered an unrecoverable error: tear
1759 // down local connection state immediately. 1756 // down local connection state immediately.
1760 TearDownLocalConnectionState(error, error_details, source); 1757 TearDownLocalConnectionState(error, error_details, source);
1761 } 1758 }
1762 1759
1763 void QuicConnection::OnCongestionWindowChange() { 1760 void QuicConnection::OnCongestionChange() {
1764 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); 1761 visitor_->OnCongestionWindowChange(clock_->ApproximateNow());
1765 }
1766 1762
1767 void QuicConnection::OnRttChange() {
1768 // Uses the connection's smoothed RTT. If zero, uses initial_rtt. 1763 // Uses the connection's smoothed RTT. If zero, uses initial_rtt.
1769 QuicTime::Delta rtt = sent_packet_manager_.GetRttStats()->smoothed_rtt(); 1764 QuicTime::Delta rtt = sent_packet_manager_.GetRttStats()->smoothed_rtt();
1770 if (rtt.IsZero()) { 1765 if (rtt.IsZero()) {
1771 rtt = QuicTime::Delta::FromMicroseconds( 1766 rtt = QuicTime::Delta::FromMicroseconds(
1772 sent_packet_manager_.GetRttStats()->initial_rtt_us()); 1767 sent_packet_manager_.GetRttStats()->initial_rtt_us());
1773 } 1768 }
1774 1769
1775 if (debug_visitor_) 1770 if (debug_visitor_)
1776 debug_visitor_->OnRttChanged(rtt); 1771 debug_visitor_->OnRttChanged(rtt);
1777 } 1772 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 } 1850 }
1856 1851
1857 if (close_connection_after_five_rtos_ && 1852 if (close_connection_after_five_rtos_ &&
1858 sent_packet_manager_.consecutive_rto_count() >= 4) { 1853 sent_packet_manager_.consecutive_rto_count() >= 4) {
1859 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. 1854 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred.
1860 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", 1855 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts",
1861 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 1856 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
1862 return; 1857 return;
1863 } 1858 }
1864 1859
1860 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated.
1861 if (FLAGS_quic_only_one_sending_alarm) {
1862 send_alarm_->Cancel();
1863 }
1865 sent_packet_manager_.OnRetransmissionTimeout(); 1864 sent_packet_manager_.OnRetransmissionTimeout();
1866 WriteIfNotBlocked(); 1865 WriteIfNotBlocked();
1867 1866
1868 // A write failure can result in the connection being closed, don't attempt to 1867 // A write failure can result in the connection being closed, don't attempt to
1869 // write further packets, or to set alarms. 1868 // write further packets, or to set alarms.
1870 if (!connected_) { 1869 if (!connected_) {
1871 return; 1870 return;
1872 } 1871 }
1873 1872
1874 // In the TLP case, the SentPacketManager gives the connection the opportunity 1873 // In the TLP case, the SentPacketManager gives the connection the opportunity
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); 2175 QuicTime::Delta ping_timeout = QuicTime::Delta::FromSeconds(kPingTimeoutSecs);
2177 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout), 2176 ping_alarm_->Update(clock_->ApproximateNow().Add(ping_timeout),
2178 QuicTime::Delta::FromSeconds(1)); 2177 QuicTime::Delta::FromSeconds(1));
2179 } 2178 }
2180 2179
2181 void QuicConnection::SetRetransmissionAlarm() { 2180 void QuicConnection::SetRetransmissionAlarm() {
2182 if (delay_setting_retransmission_alarm_) { 2181 if (delay_setting_retransmission_alarm_) {
2183 pending_retransmission_alarm_ = true; 2182 pending_retransmission_alarm_ = true;
2184 return; 2183 return;
2185 } 2184 }
2185 // Once the handshake has been confirmed, the retransmission alarm should
2186 // never fire before the send alarm.
2187 if (FLAGS_quic_only_one_sending_alarm &&
2188 sent_packet_manager_.handshake_confirmed() && send_alarm_->IsSet()) {
2189 DCHECK(!sent_packet_manager_.GetRetransmissionTime().IsInitialized() ||
2190 sent_packet_manager_.GetRetransmissionTime() >=
2191 send_alarm_->deadline())
2192 << " retransmission_time:"
2193 << sent_packet_manager_.GetRetransmissionTime().ToDebuggingValue()
2194 << " send_alarm:" << send_alarm_->deadline().ToDebuggingValue();
2195 retransmission_alarm_->Cancel();
2196 return;
2197 }
2186 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); 2198 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime();
2187 retransmission_alarm_->Update(retransmission_time, 2199 retransmission_alarm_->Update(retransmission_time,
2188 QuicTime::Delta::FromMilliseconds(1)); 2200 QuicTime::Delta::FromMilliseconds(1));
2189 } 2201 }
2190 2202
2191 void QuicConnection::MaybeSetMtuAlarm() { 2203 void QuicConnection::MaybeSetMtuAlarm() {
2192 // Do not set the alarm if the target size is less than the current size. 2204 // Do not set the alarm if the target size is less than the current size.
2193 // This covers the case when |mtu_discovery_target_| is at its default value, 2205 // This covers the case when |mtu_discovery_target_| is at its default value,
2194 // zero. 2206 // zero.
2195 if (mtu_discovery_target_ <= max_packet_length()) { 2207 if (mtu_discovery_target_ <= max_packet_length()) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 } 2434 }
2423 2435
2424 StringPiece QuicConnection::GetCurrentPacket() { 2436 StringPiece QuicConnection::GetCurrentPacket() {
2425 if (current_packet_data_ == nullptr) { 2437 if (current_packet_data_ == nullptr) {
2426 return StringPiece(); 2438 return StringPiece();
2427 } 2439 }
2428 return StringPiece(current_packet_data_, last_size_); 2440 return StringPiece(current_packet_data_, last_size_);
2429 } 2441 }
2430 2442
2431 } // namespace net 2443 } // 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