OLD | NEW |
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 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); | 1116 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); |
1117 } | 1117 } |
1118 | 1118 |
1119 void QuicConnection::SendBlocked(QuicStreamId id) { | 1119 void QuicConnection::SendBlocked(QuicStreamId id) { |
1120 // Opportunistically bundle an ack with this outgoing packet. | 1120 // Opportunistically bundle an ack with this outgoing packet. |
1121 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1121 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); |
1122 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); | 1122 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); |
1123 } | 1123 } |
1124 | 1124 |
1125 const QuicConnectionStats& QuicConnection::GetStats() { | 1125 const QuicConnectionStats& QuicConnection::GetStats() { |
1126 if (!FLAGS_quic_use_initial_rtt_for_stats) { | 1126 const RttStats* rtt_stats = sent_packet_manager_.GetRttStats(); |
1127 stats_.min_rtt_us = | |
1128 sent_packet_manager_.GetRttStats()->min_rtt().ToMicroseconds(); | |
1129 stats_.srtt_us = | |
1130 sent_packet_manager_.GetRttStats()->smoothed_rtt().ToMicroseconds(); | |
1131 } else { | |
1132 const RttStats* rtt_stats = sent_packet_manager_.GetRttStats(); | |
1133 | 1127 |
1134 // Update rtt and estimated bandwidth. | 1128 // Update rtt and estimated bandwidth. |
1135 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); | 1129 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); |
1136 if (min_rtt.IsZero()) { | 1130 if (min_rtt.IsZero()) { |
1137 // If min RTT has not been set, use initial RTT instead. | 1131 // If min RTT has not been set, use initial RTT instead. |
1138 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); | 1132 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); |
1139 } | 1133 } |
1140 stats_.min_rtt_us = min_rtt.ToMicroseconds(); | 1134 stats_.min_rtt_us = min_rtt.ToMicroseconds(); |
1141 | 1135 |
1142 QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); | 1136 QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
1143 if (srtt.IsZero()) { | 1137 if (srtt.IsZero()) { |
1144 // If SRTT has not been set, use initial RTT instead. | 1138 // If SRTT has not been set, use initial RTT instead. |
1145 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); | 1139 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); |
1146 } | |
1147 stats_.srtt_us = srtt.ToMicroseconds(); | |
1148 } | 1140 } |
| 1141 stats_.srtt_us = srtt.ToMicroseconds(); |
1149 | 1142 |
1150 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); | 1143 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); |
1151 stats_.max_packet_size = packet_generator_.max_packet_length(); | 1144 stats_.max_packet_size = packet_generator_.max_packet_length(); |
1152 return stats_; | 1145 return stats_; |
1153 } | 1146 } |
1154 | 1147 |
1155 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, | 1148 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, |
1156 const IPEndPoint& peer_address, | 1149 const IPEndPoint& peer_address, |
1157 const QuicEncryptedPacket& packet) { | 1150 const QuicEncryptedPacket& packet) { |
1158 if (!connected_) { | 1151 if (!connected_) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 packet->serialized_packet.packet = nullptr; | 1389 packet->serialized_packet.packet = nullptr; |
1397 return true; | 1390 return true; |
1398 } | 1391 } |
1399 | 1392 |
1400 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { | 1393 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { |
1401 if (ShouldDiscardPacket(*packet)) { | 1394 if (ShouldDiscardPacket(*packet)) { |
1402 ++stats_.packets_discarded; | 1395 ++stats_.packets_discarded; |
1403 return true; | 1396 return true; |
1404 } | 1397 } |
1405 // Connection close packets are encrypted and saved, so don't exit early. | 1398 // Connection close packets are encrypted and saved, so don't exit early. |
1406 if (writer_->IsWriteBlocked() && !IsConnectionClose(*packet)) { | 1399 const bool is_connection_close = IsConnectionClose(*packet); |
| 1400 if (writer_->IsWriteBlocked() && !is_connection_close) { |
1407 return false; | 1401 return false; |
1408 } | 1402 } |
1409 | 1403 |
1410 QuicPacketSequenceNumber sequence_number = | 1404 QuicPacketSequenceNumber sequence_number = |
1411 packet->serialized_packet.sequence_number; | 1405 packet->serialized_packet.sequence_number; |
1412 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); | 1406 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); |
1413 sequence_number_of_last_sent_packet_ = sequence_number; | 1407 sequence_number_of_last_sent_packet_ = sequence_number; |
1414 | 1408 |
1415 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( | 1409 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( |
1416 packet->encryption_level, | 1410 packet->encryption_level, |
1417 sequence_number, | 1411 sequence_number, |
1418 *packet->serialized_packet.packet); | 1412 *packet->serialized_packet.packet); |
1419 if (encrypted == nullptr) { | 1413 if (encrypted == nullptr) { |
1420 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " | 1414 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " |
1421 << sequence_number; | 1415 << sequence_number; |
1422 // CloseConnection does not send close packet, so no infinite loop here. | 1416 // CloseConnection does not send close packet, so no infinite loop here. |
1423 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | 1417 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
1424 return false; | 1418 return false; |
1425 } | 1419 } |
1426 | 1420 |
1427 // Connection close packets are eventually owned by TimeWaitListManager. | 1421 // Connection close packets are eventually owned by TimeWaitListManager. |
1428 // Others are deleted at the end of this call. | 1422 // Others are deleted at the end of this call. |
1429 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; | 1423 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; |
1430 if (IsConnectionClose(*packet)) { | 1424 if (is_connection_close) { |
1431 DCHECK(connection_close_packet_.get() == nullptr); | 1425 DCHECK(connection_close_packet_.get() == nullptr); |
1432 connection_close_packet_.reset(encrypted); | 1426 connection_close_packet_.reset(encrypted); |
1433 // This assures we won't try to write *forced* packets when blocked. | 1427 // This assures we won't try to write *forced* packets when blocked. |
1434 // Return true to stop processing. | 1428 // Return true to stop processing. |
1435 if (writer_->IsWriteBlocked()) { | 1429 if (writer_->IsWriteBlocked()) { |
1436 visitor_->OnWriteBlocked(); | 1430 visitor_->OnWriteBlocked(); |
1437 return true; | 1431 return true; |
1438 } | 1432 } |
1439 } else { | 1433 } else { |
1440 encrypted_deleter.reset(encrypted); | 1434 encrypted_deleter.reset(encrypted); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 | 1529 |
1536 stats_.bytes_sent += result.bytes_written; | 1530 stats_.bytes_sent += result.bytes_written; |
1537 ++stats_.packets_sent; | 1531 ++stats_.packets_sent; |
1538 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1532 if (packet->transmission_type != NOT_RETRANSMISSION) { |
1539 stats_.bytes_retransmitted += result.bytes_written; | 1533 stats_.bytes_retransmitted += result.bytes_written; |
1540 ++stats_.packets_retransmitted; | 1534 ++stats_.packets_retransmitted; |
1541 } | 1535 } |
1542 | 1536 |
1543 if (result.status == WRITE_STATUS_ERROR) { | 1537 if (result.status == WRITE_STATUS_ERROR) { |
1544 OnWriteError(result.error_code); | 1538 OnWriteError(result.error_code); |
| 1539 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() |
| 1540 << "bytes " |
| 1541 << " from host " << self_address().ToStringWithoutPort() |
| 1542 << " to address " << peer_address().ToString(); |
1545 return false; | 1543 return false; |
1546 } | 1544 } |
1547 | 1545 |
1548 return true; | 1546 return true; |
1549 } | 1547 } |
1550 | 1548 |
1551 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { | 1549 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { |
1552 if (!connected_) { | 1550 if (!connected_) { |
1553 DVLOG(1) << ENDPOINT | 1551 DVLOG(1) << ENDPOINT |
1554 << "Not sending packet as connection is disconnected."; | 1552 << "Not sending packet as connection is disconnected."; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 // Retransmitted packets retransmittable frames are owned by the unacked | 2095 // Retransmitted packets retransmittable frames are owned by the unacked |
2098 // packet map, but are not present in the serialized packet. | 2096 // packet map, but are not present in the serialized packet. |
2099 if (packet.transmission_type != NOT_RETRANSMISSION || | 2097 if (packet.transmission_type != NOT_RETRANSMISSION || |
2100 packet.serialized_packet.retransmittable_frames != nullptr) { | 2098 packet.serialized_packet.retransmittable_frames != nullptr) { |
2101 return HAS_RETRANSMITTABLE_DATA; | 2099 return HAS_RETRANSMITTABLE_DATA; |
2102 } else { | 2100 } else { |
2103 return NO_RETRANSMITTABLE_DATA; | 2101 return NO_RETRANSMITTABLE_DATA; |
2104 } | 2102 } |
2105 } | 2103 } |
2106 | 2104 |
2107 bool QuicConnection::IsConnectionClose( | 2105 bool QuicConnection::IsConnectionClose(const QueuedPacket& packet) { |
2108 QueuedPacket packet) { | 2106 const RetransmittableFrames* retransmittable_frames = |
2109 RetransmittableFrames* retransmittable_frames = | |
2110 packet.serialized_packet.retransmittable_frames; | 2107 packet.serialized_packet.retransmittable_frames; |
2111 if (!retransmittable_frames) { | 2108 if (retransmittable_frames == nullptr) { |
2112 return false; | 2109 return false; |
2113 } | 2110 } |
2114 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2111 for (const QuicFrame& frame : retransmittable_frames->frames()) { |
2115 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2112 if (frame.type == CONNECTION_CLOSE_FRAME) { |
2116 return true; | 2113 return true; |
2117 } | 2114 } |
2118 } | 2115 } |
2119 return false; | 2116 return false; |
2120 } | 2117 } |
2121 | 2118 |
2122 } // namespace net | 2119 } // namespace net |
OLD | NEW |