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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 self_ip_changed_(false), | 265 self_ip_changed_(false), |
266 self_port_changed_(false), | 266 self_port_changed_(false), |
267 can_truncate_connection_ids_(true), | 267 can_truncate_connection_ids_(true), |
268 is_secure_(is_secure) { | 268 is_secure_(is_secure) { |
269 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " | 269 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " |
270 << connection_id; | 270 << connection_id; |
271 framer_.set_visitor(this); | 271 framer_.set_visitor(this); |
272 framer_.set_received_entropy_calculator(&received_packet_manager_); | 272 framer_.set_received_entropy_calculator(&received_packet_manager_); |
273 stats_.connection_creation_time = clock_->ApproximateNow(); | 273 stats_.connection_creation_time = clock_->ApproximateNow(); |
274 sent_packet_manager_.set_network_change_visitor(this); | 274 sent_packet_manager_.set_network_change_visitor(this); |
| 275 if (FLAGS_quic_small_default_packet_size && is_server_) { |
| 276 set_max_packet_length(kDefaultServerMaxPacketSize); |
| 277 } |
275 } | 278 } |
276 | 279 |
277 QuicConnection::~QuicConnection() { | 280 QuicConnection::~QuicConnection() { |
278 if (owns_writer_) { | 281 if (owns_writer_) { |
279 delete writer_; | 282 delete writer_; |
280 } | 283 } |
281 STLDeleteElements(&undecryptable_packets_); | 284 STLDeleteElements(&undecryptable_packets_); |
282 STLDeleteValues(&group_map_); | 285 STLDeleteValues(&group_map_); |
283 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 286 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
284 it != queued_packets_.end(); ++it) { | 287 it != queued_packets_.end(); ++it) { |
285 delete it->serialized_packet.retransmittable_frames; | 288 delete it->serialized_packet.retransmittable_frames; |
286 delete it->serialized_packet.packet; | 289 delete it->serialized_packet.packet; |
287 } | 290 } |
288 } | 291 } |
289 | 292 |
290 void QuicConnection::SetFromConfig(const QuicConfig& config) { | 293 void QuicConnection::SetFromConfig(const QuicConfig& config) { |
291 if (config.negotiated()) { | 294 if (config.negotiated()) { |
292 SetNetworkTimeouts(QuicTime::Delta::Infinite(), | 295 SetNetworkTimeouts(QuicTime::Delta::Infinite(), |
293 config.IdleConnectionStateLifetime()); | 296 config.IdleConnectionStateLifetime()); |
294 if (FLAGS_quic_allow_silent_close && config.SilentClose()) { | 297 if (config.SilentClose()) { |
295 silent_close_enabled_ = true; | 298 silent_close_enabled_ = true; |
296 } | 299 } |
297 } else { | 300 } else { |
298 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), | 301 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), |
299 config.max_idle_time_before_crypto_handshake()); | 302 config.max_idle_time_before_crypto_handshake()); |
300 } | 303 } |
301 | 304 |
302 sent_packet_manager_.SetFromConfig(config); | 305 sent_packet_manager_.SetFromConfig(config); |
303 if (config.HasReceivedBytesForConnectionId() && | 306 if (config.HasReceivedBytesForConnectionId() && |
304 can_truncate_connection_ids_) { | 307 can_truncate_connection_ids_) { |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 } | 965 } |
963 // This occurs if there are received packet gaps and the peer does not raise | 966 // This occurs if there are received packet gaps and the peer does not raise |
964 // the least unacked fast enough. | 967 // the least unacked fast enough. |
965 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) { | 968 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) { |
966 SendConnectionCloseWithDetails( | 969 SendConnectionCloseWithDetails( |
967 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, | 970 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, |
968 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets)); | 971 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets)); |
969 } | 972 } |
970 } | 973 } |
971 | 974 |
972 QuicAckFrame* QuicConnection::CreateAckFrame() { | 975 void QuicConnection::PopulateAckFrame(QuicAckFrame* ack) { |
973 QuicAckFrame* outgoing_ack = new QuicAckFrame(); | 976 received_packet_manager_.UpdateReceivedPacketInfo(ack, |
974 received_packet_manager_.UpdateReceivedPacketInfo( | 977 clock_->ApproximateNow()); |
975 outgoing_ack, clock_->ApproximateNow()); | |
976 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; | |
977 return outgoing_ack; | |
978 } | 978 } |
979 | 979 |
980 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() { | 980 void QuicConnection::PopulateStopWaitingFrame( |
981 QuicStopWaitingFrame stop_waiting; | 981 QuicStopWaitingFrame* stop_waiting) { |
982 UpdateStopWaiting(&stop_waiting); | 982 stop_waiting->least_unacked = GetLeastUnacked(); |
983 return new QuicStopWaitingFrame(stop_waiting); | 983 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( |
| 984 stop_waiting->least_unacked - 1); |
984 } | 985 } |
985 | 986 |
986 bool QuicConnection::ShouldLastPacketInstigateAck() const { | 987 bool QuicConnection::ShouldLastPacketInstigateAck() const { |
987 if (!last_stream_frames_.empty() || | 988 if (!last_stream_frames_.empty() || |
988 !last_goaway_frames_.empty() || | 989 !last_goaway_frames_.empty() || |
989 !last_rst_frames_.empty() || | 990 !last_rst_frames_.empty() || |
990 !last_window_update_frames_.empty() || | 991 !last_window_update_frames_.empty() || |
991 !last_blocked_frames_.empty() || | 992 !last_blocked_frames_.empty() || |
992 !last_ping_frames_.empty()) { | 993 !last_ping_frames_.empty()) { |
993 return true; | 994 return true; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); | 1117 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); |
1117 } | 1118 } |
1118 | 1119 |
1119 void QuicConnection::SendBlocked(QuicStreamId id) { | 1120 void QuicConnection::SendBlocked(QuicStreamId id) { |
1120 // Opportunistically bundle an ack with this outgoing packet. | 1121 // Opportunistically bundle an ack with this outgoing packet. |
1121 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1122 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); |
1122 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); | 1123 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); |
1123 } | 1124 } |
1124 | 1125 |
1125 const QuicConnectionStats& QuicConnection::GetStats() { | 1126 const QuicConnectionStats& QuicConnection::GetStats() { |
1126 if (!FLAGS_quic_use_initial_rtt_for_stats) { | 1127 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 | 1128 |
1134 // Update rtt and estimated bandwidth. | 1129 // Update rtt and estimated bandwidth. |
1135 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); | 1130 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); |
1136 if (min_rtt.IsZero()) { | 1131 if (min_rtt.IsZero()) { |
1137 // If min RTT has not been set, use initial RTT instead. | 1132 // If min RTT has not been set, use initial RTT instead. |
1138 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); | 1133 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); |
1139 } | 1134 } |
1140 stats_.min_rtt_us = min_rtt.ToMicroseconds(); | 1135 stats_.min_rtt_us = min_rtt.ToMicroseconds(); |
1141 | 1136 |
1142 QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); | 1137 QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
1143 if (srtt.IsZero()) { | 1138 if (srtt.IsZero()) { |
1144 // If SRTT has not been set, use initial RTT instead. | 1139 // If SRTT has not been set, use initial RTT instead. |
1145 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); | 1140 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); |
1146 } | |
1147 stats_.srtt_us = srtt.ToMicroseconds(); | |
1148 } | 1141 } |
| 1142 stats_.srtt_us = srtt.ToMicroseconds(); |
1149 | 1143 |
1150 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); | 1144 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); |
1151 stats_.max_packet_size = packet_generator_.max_packet_length(); | 1145 stats_.max_packet_size = packet_generator_.max_packet_length(); |
1152 return stats_; | 1146 return stats_; |
1153 } | 1147 } |
1154 | 1148 |
1155 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, | 1149 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, |
1156 const IPEndPoint& peer_address, | 1150 const IPEndPoint& peer_address, |
1157 const QuicEncryptedPacket& packet) { | 1151 const QuicEncryptedPacket& packet) { |
1158 if (!connected_) { | 1152 if (!connected_) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 | 1303 |
1310 // Re-packetize the frames with a new sequence number for retransmission. | 1304 // Re-packetize the frames with a new sequence number for retransmission. |
1311 // Retransmitted data packets do not use FEC, even when it's enabled. | 1305 // Retransmitted data packets do not use FEC, even when it's enabled. |
1312 // Retransmitted packets use the same sequence number length as the | 1306 // Retransmitted packets use the same sequence number length as the |
1313 // original. | 1307 // original. |
1314 // Flush the packet generator before making a new packet. | 1308 // Flush the packet generator before making a new packet. |
1315 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that | 1309 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that |
1316 // does not require the creator to be flushed. | 1310 // does not require the creator to be flushed. |
1317 packet_generator_.FlushAllQueuedFrames(); | 1311 packet_generator_.FlushAllQueuedFrames(); |
1318 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( | 1312 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( |
1319 pending.retransmittable_frames.frames(), | 1313 pending.retransmittable_frames, pending.sequence_number_length); |
1320 pending.sequence_number_length); | 1314 if (serialized_packet.packet == nullptr) { |
| 1315 // We failed to serialize the packet, so close the connection. |
| 1316 // CloseConnection does not send close packet, so no infinite loop here. |
| 1317 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
| 1318 return; |
| 1319 } |
1321 | 1320 |
1322 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number | 1321 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number |
1323 << " as " << serialized_packet.sequence_number; | 1322 << " as " << serialized_packet.sequence_number; |
1324 SendOrQueuePacket( | 1323 SendOrQueuePacket( |
1325 QueuedPacket(serialized_packet, | 1324 QueuedPacket(serialized_packet, |
1326 pending.retransmittable_frames.encryption_level(), | 1325 pending.retransmittable_frames.encryption_level(), |
1327 pending.transmission_type, | 1326 pending.transmission_type, |
1328 pending.sequence_number)); | 1327 pending.sequence_number)); |
1329 } | 1328 } |
1330 } | 1329 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 packet->serialized_packet.packet = nullptr; | 1395 packet->serialized_packet.packet = nullptr; |
1397 return true; | 1396 return true; |
1398 } | 1397 } |
1399 | 1398 |
1400 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { | 1399 bool QuicConnection::WritePacketInner(QueuedPacket* packet) { |
1401 if (ShouldDiscardPacket(*packet)) { | 1400 if (ShouldDiscardPacket(*packet)) { |
1402 ++stats_.packets_discarded; | 1401 ++stats_.packets_discarded; |
1403 return true; | 1402 return true; |
1404 } | 1403 } |
1405 // Connection close packets are encrypted and saved, so don't exit early. | 1404 // Connection close packets are encrypted and saved, so don't exit early. |
1406 if (writer_->IsWriteBlocked() && !IsConnectionClose(*packet)) { | 1405 const bool is_connection_close = IsConnectionClose(*packet); |
| 1406 if (writer_->IsWriteBlocked() && !is_connection_close) { |
1407 return false; | 1407 return false; |
1408 } | 1408 } |
1409 | 1409 |
1410 QuicPacketSequenceNumber sequence_number = | 1410 QuicPacketSequenceNumber sequence_number = |
1411 packet->serialized_packet.sequence_number; | 1411 packet->serialized_packet.sequence_number; |
1412 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); | 1412 DCHECK_LE(sequence_number_of_last_sent_packet_, sequence_number); |
1413 sequence_number_of_last_sent_packet_ = sequence_number; | 1413 sequence_number_of_last_sent_packet_ = sequence_number; |
1414 | 1414 |
1415 QuicEncryptedPacket* encrypted = framer_.EncryptPacket( | 1415 QuicEncryptedPacket* encrypted = packet->serialized_packet.packet; |
1416 packet->encryption_level, | |
1417 sequence_number, | |
1418 *packet->serialized_packet.packet); | |
1419 if (encrypted == nullptr) { | |
1420 LOG(DFATAL) << ENDPOINT << "Failed to encrypt packet number " | |
1421 << sequence_number; | |
1422 // CloseConnection does not send close packet, so no infinite loop here. | |
1423 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); | |
1424 return false; | |
1425 } | |
1426 | |
1427 // Connection close packets are eventually owned by TimeWaitListManager. | 1416 // Connection close packets are eventually owned by TimeWaitListManager. |
1428 // Others are deleted at the end of this call. | 1417 // Others are deleted at the end of this call. |
1429 scoped_ptr<QuicEncryptedPacket> encrypted_deleter; | 1418 if (is_connection_close) { |
1430 if (IsConnectionClose(*packet)) { | |
1431 DCHECK(connection_close_packet_.get() == nullptr); | 1419 DCHECK(connection_close_packet_.get() == nullptr); |
1432 connection_close_packet_.reset(encrypted); | 1420 connection_close_packet_.reset(encrypted); |
| 1421 packet->serialized_packet.packet = nullptr; |
1433 // This assures we won't try to write *forced* packets when blocked. | 1422 // This assures we won't try to write *forced* packets when blocked. |
1434 // Return true to stop processing. | 1423 // Return true to stop processing. |
1435 if (writer_->IsWriteBlocked()) { | 1424 if (writer_->IsWriteBlocked()) { |
1436 visitor_->OnWriteBlocked(); | 1425 visitor_->OnWriteBlocked(); |
1437 return true; | 1426 return true; |
1438 } | 1427 } |
1439 } else { | |
1440 encrypted_deleter.reset(encrypted); | |
1441 } | 1428 } |
1442 | 1429 |
1443 if (!FLAGS_quic_allow_oversized_packets_for_test) { | 1430 if (!FLAGS_quic_allow_oversized_packets_for_test) { |
1444 DCHECK_LE(encrypted->length(), kMaxPacketSize); | 1431 DCHECK_LE(encrypted->length(), kMaxPacketSize); |
1445 } | 1432 } |
1446 DCHECK_LE(encrypted->length(), packet_generator_.max_packet_length()); | 1433 DCHECK_LE(encrypted->length(), packet_generator_.max_packet_length()); |
1447 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number << " : " | 1434 DVLOG(1) << ENDPOINT << "Sending packet " << sequence_number << " : " |
1448 << (packet->serialized_packet.packet->is_fec_packet() ? "FEC " : | 1435 << (packet->serialized_packet.is_fec_packet |
1449 (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA | 1436 ? "FEC " |
1450 ? "data bearing " : " ack only ")) | 1437 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA |
1451 << ", encryption level: " | 1438 ? "data bearing " |
| 1439 : " ack only ")) << ", encryption level: " |
1452 << QuicUtils::EncryptionLevelToString(packet->encryption_level) | 1440 << QuicUtils::EncryptionLevelToString(packet->encryption_level) |
1453 << ", length:" | 1441 << ", encrypted length:" << encrypted->length(); |
1454 << packet->serialized_packet.packet->length() | |
1455 << ", encrypted length:" | |
1456 << encrypted->length(); | |
1457 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl | 1442 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl |
1458 << QuicUtils::StringToHexASCIIDump( | 1443 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); |
1459 packet->serialized_packet.packet->AsStringPiece()); | |
1460 | 1444 |
1461 QuicTime packet_send_time = QuicTime::Zero(); | 1445 QuicTime packet_send_time = QuicTime::Zero(); |
1462 if (FLAGS_quic_record_send_time_before_write) { | 1446 if (FLAGS_quic_record_send_time_before_write) { |
1463 // Measure the RTT from before the write begins to avoid underestimating the | 1447 // Measure the RTT from before the write begins to avoid underestimating the |
1464 // min_rtt_, especially in cases where the thread blocks or gets swapped out | 1448 // min_rtt_, especially in cases where the thread blocks or gets swapped out |
1465 // during the WritePacket below. | 1449 // during the WritePacket below. |
1466 packet_send_time = clock_->Now(); | 1450 packet_send_time = clock_->Now(); |
1467 } | 1451 } |
1468 WriteResult result = writer_->WritePacket(encrypted->data(), | 1452 WriteResult result = writer_->WritePacket(encrypted->data(), |
1469 encrypted->length(), | 1453 encrypted->length(), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 | 1519 |
1536 stats_.bytes_sent += result.bytes_written; | 1520 stats_.bytes_sent += result.bytes_written; |
1537 ++stats_.packets_sent; | 1521 ++stats_.packets_sent; |
1538 if (packet->transmission_type != NOT_RETRANSMISSION) { | 1522 if (packet->transmission_type != NOT_RETRANSMISSION) { |
1539 stats_.bytes_retransmitted += result.bytes_written; | 1523 stats_.bytes_retransmitted += result.bytes_written; |
1540 ++stats_.packets_retransmitted; | 1524 ++stats_.packets_retransmitted; |
1541 } | 1525 } |
1542 | 1526 |
1543 if (result.status == WRITE_STATUS_ERROR) { | 1527 if (result.status == WRITE_STATUS_ERROR) { |
1544 OnWriteError(result.error_code); | 1528 OnWriteError(result.error_code); |
| 1529 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() |
| 1530 << "bytes " |
| 1531 << " from host " << self_address().ToStringWithoutPort() |
| 1532 << " to address " << peer_address().ToString(); |
1545 return false; | 1533 return false; |
1546 } | 1534 } |
1547 | 1535 |
1548 return true; | 1536 return true; |
1549 } | 1537 } |
1550 | 1538 |
1551 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { | 1539 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { |
1552 if (!connected_) { | 1540 if (!connected_) { |
1553 DVLOG(1) << ENDPOINT | 1541 DVLOG(1) << ENDPOINT |
1554 << "Not sending packet as connection is disconnected."; | 1542 << "Not sending packet as connection is disconnected."; |
(...skipping 27 matching lines...) Expand all Loading... |
1582 | 1570 |
1583 void QuicConnection::OnWriteError(int error_code) { | 1571 void QuicConnection::OnWriteError(int error_code) { |
1584 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code | 1572 DVLOG(1) << ENDPOINT << "Write failed with error: " << error_code |
1585 << " (" << ErrorToString(error_code) << ")"; | 1573 << " (" << ErrorToString(error_code) << ")"; |
1586 // We can't send an error as the socket is presumably borked. | 1574 // We can't send an error as the socket is presumably borked. |
1587 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); | 1575 CloseConnection(QUIC_PACKET_WRITE_ERROR, false); |
1588 } | 1576 } |
1589 | 1577 |
1590 void QuicConnection::OnSerializedPacket( | 1578 void QuicConnection::OnSerializedPacket( |
1591 const SerializedPacket& serialized_packet) { | 1579 const SerializedPacket& serialized_packet) { |
1592 // If a forward-secure encrypter is available but is not being used and this | 1580 if (serialized_packet.packet == nullptr) { |
1593 // packet's sequence number is after the first packet which requires | 1581 // We failed to serialize the packet, so close the connection. |
1594 // forward security, start using the forward-secure encrypter. | 1582 // CloseConnection does not send close packet, so no infinite loop here. |
1595 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | 1583 CloseConnection(QUIC_ENCRYPTION_FAILURE, false); |
1596 has_forward_secure_encrypter_ && | 1584 return; |
1597 serialized_packet.sequence_number >= | |
1598 first_required_forward_secure_packet_) { | |
1599 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | |
1600 } | 1585 } |
1601 if (serialized_packet.retransmittable_frames) { | 1586 if (serialized_packet.retransmittable_frames) { |
1602 serialized_packet.retransmittable_frames-> | 1587 serialized_packet.retransmittable_frames-> |
1603 set_encryption_level(encryption_level_); | 1588 set_encryption_level(encryption_level_); |
1604 | 1589 |
1605 if (FLAGS_quic_ack_notifier_informed_on_serialized) { | 1590 sent_packet_manager_.OnSerializedPacket(serialized_packet); |
1606 sent_packet_manager_.OnSerializedPacket(serialized_packet); | |
1607 } | |
1608 } | 1591 } |
1609 if (serialized_packet.packet->is_fec_packet() && fec_alarm_->IsSet()) { | 1592 if (serialized_packet.is_fec_packet && fec_alarm_->IsSet()) { |
1610 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. | 1593 // If an FEC packet is serialized with the FEC alarm set, cancel the alarm. |
1611 fec_alarm_->Cancel(); | 1594 fec_alarm_->Cancel(); |
1612 } | 1595 } |
1613 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); | 1596 SendOrQueuePacket(QueuedPacket(serialized_packet, encryption_level_)); |
1614 } | 1597 } |
1615 | 1598 |
1616 void QuicConnection::OnCongestionWindowChange() { | 1599 void QuicConnection::OnCongestionWindowChange() { |
1617 packet_generator_.OnCongestionWindowChange( | 1600 packet_generator_.OnCongestionWindowChange( |
1618 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); | 1601 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); |
1619 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); | 1602 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); |
(...skipping 26 matching lines...) Expand all Loading... |
1646 << "packet.serialized_packet.packet == nullptr in to SendOrQueuePacket"; | 1629 << "packet.serialized_packet.packet == nullptr in to SendOrQueuePacket"; |
1647 return; | 1630 return; |
1648 } | 1631 } |
1649 | 1632 |
1650 sent_entropy_manager_.RecordPacketEntropyHash( | 1633 sent_entropy_manager_.RecordPacketEntropyHash( |
1651 packet.serialized_packet.sequence_number, | 1634 packet.serialized_packet.sequence_number, |
1652 packet.serialized_packet.entropy_hash); | 1635 packet.serialized_packet.entropy_hash); |
1653 if (!WritePacket(&packet)) { | 1636 if (!WritePacket(&packet)) { |
1654 queued_packets_.push_back(packet); | 1637 queued_packets_.push_back(packet); |
1655 } | 1638 } |
1656 } | |
1657 | 1639 |
1658 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { | 1640 // If a forward-secure encrypter is available but is not being used and the |
1659 stop_waiting->least_unacked = GetLeastUnacked(); | 1641 // next sequence number is the first packet which requires |
1660 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( | 1642 // forward security, start using the forward-secure encrypter. |
1661 stop_waiting->least_unacked - 1); | 1643 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && |
| 1644 has_forward_secure_encrypter_ && |
| 1645 packet.serialized_packet.sequence_number >= |
| 1646 first_required_forward_secure_packet_ - 1) { |
| 1647 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); |
| 1648 } |
1662 } | 1649 } |
1663 | 1650 |
1664 void QuicConnection::SendPing() { | 1651 void QuicConnection::SendPing() { |
1665 if (retransmission_alarm_->IsSet()) { | 1652 if (retransmission_alarm_->IsSet()) { |
1666 return; | 1653 return; |
1667 } | 1654 } |
1668 packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); | 1655 packet_generator_.AddControlFrame(QuicFrame(new QuicPingFrame)); |
1669 } | 1656 } |
1670 | 1657 |
1671 void QuicConnection::SendAck() { | 1658 void QuicConnection::SendAck() { |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 // Retransmitted packets retransmittable frames are owned by the unacked | 2084 // Retransmitted packets retransmittable frames are owned by the unacked |
2098 // packet map, but are not present in the serialized packet. | 2085 // packet map, but are not present in the serialized packet. |
2099 if (packet.transmission_type != NOT_RETRANSMISSION || | 2086 if (packet.transmission_type != NOT_RETRANSMISSION || |
2100 packet.serialized_packet.retransmittable_frames != nullptr) { | 2087 packet.serialized_packet.retransmittable_frames != nullptr) { |
2101 return HAS_RETRANSMITTABLE_DATA; | 2088 return HAS_RETRANSMITTABLE_DATA; |
2102 } else { | 2089 } else { |
2103 return NO_RETRANSMITTABLE_DATA; | 2090 return NO_RETRANSMITTABLE_DATA; |
2104 } | 2091 } |
2105 } | 2092 } |
2106 | 2093 |
2107 bool QuicConnection::IsConnectionClose( | 2094 bool QuicConnection::IsConnectionClose(const QueuedPacket& packet) { |
2108 QueuedPacket packet) { | 2095 const RetransmittableFrames* retransmittable_frames = |
2109 RetransmittableFrames* retransmittable_frames = | |
2110 packet.serialized_packet.retransmittable_frames; | 2096 packet.serialized_packet.retransmittable_frames; |
2111 if (!retransmittable_frames) { | 2097 if (retransmittable_frames == nullptr) { |
2112 return false; | 2098 return false; |
2113 } | 2099 } |
2114 for (size_t i = 0; i < retransmittable_frames->frames().size(); ++i) { | 2100 for (const QuicFrame& frame : retransmittable_frames->frames()) { |
2115 if (retransmittable_frames->frames()[i].type == CONNECTION_CLOSE_FRAME) { | 2101 if (frame.type == CONNECTION_CLOSE_FRAME) { |
2116 return true; | 2102 return true; |
2117 } | 2103 } |
2118 } | 2104 } |
2119 return false; | 2105 return false; |
2120 } | 2106 } |
2121 | 2107 |
2122 } // namespace net | 2108 } // namespace net |
OLD | NEW |