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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 per_packet_options_(nullptr), | 216 per_packet_options_(nullptr), |
217 writer_(writer), | 217 writer_(writer), |
218 owns_writer_(owns_writer), | 218 owns_writer_(owns_writer), |
219 encryption_level_(ENCRYPTION_NONE), | 219 encryption_level_(ENCRYPTION_NONE), |
220 has_forward_secure_encrypter_(false), | 220 has_forward_secure_encrypter_(false), |
221 first_required_forward_secure_packet_(0), | 221 first_required_forward_secure_packet_(0), |
222 clock_(helper->GetClock()), | 222 clock_(helper->GetClock()), |
223 random_generator_(helper->GetRandomGenerator()), | 223 random_generator_(helper->GetRandomGenerator()), |
224 connection_id_(connection_id), | 224 connection_id_(connection_id), |
225 peer_address_(address), | 225 peer_address_(address), |
226 migrating_peer_port_(0), | |
227 last_packet_decrypted_(false), | 226 last_packet_decrypted_(false), |
228 last_size_(0), | 227 last_size_(0), |
229 current_packet_data_(nullptr), | 228 current_packet_data_(nullptr), |
230 last_decrypted_packet_level_(ENCRYPTION_NONE), | 229 last_decrypted_packet_level_(ENCRYPTION_NONE), |
231 should_last_packet_instigate_acks_(false), | 230 should_last_packet_instigate_acks_(false), |
232 largest_seen_packet_with_ack_(0), | 231 largest_seen_packet_with_ack_(0), |
233 largest_seen_packet_with_stop_waiting_(0), | 232 largest_seen_packet_with_stop_waiting_(0), |
234 max_undecryptable_packets_(0), | 233 max_undecryptable_packets_(0), |
235 pending_version_negotiation_packet_(false), | 234 pending_version_negotiation_packet_(false), |
236 save_crypto_packets_as_termination_packets_(false), | 235 save_crypto_packets_as_termination_packets_(false), |
237 silent_close_enabled_(false), | 236 silent_close_enabled_(false), |
| 237 close_connection_after_five_rtos_(false), |
238 received_packet_manager_(&stats_), | 238 received_packet_manager_(&stats_), |
239 ack_queued_(false), | 239 ack_queued_(false), |
240 num_retransmittable_packets_received_since_last_ack_sent_(0), | 240 num_retransmittable_packets_received_since_last_ack_sent_(0), |
241 last_ack_had_missing_packets_(false), | 241 last_ack_had_missing_packets_(false), |
242 num_packets_received_since_last_ack_sent_(0), | 242 num_packets_received_since_last_ack_sent_(0), |
243 stop_waiting_count_(0), | 243 stop_waiting_count_(0), |
244 ack_mode_(TCP_ACKING), | 244 ack_mode_(TCP_ACKING), |
245 delay_setting_retransmission_alarm_(false), | 245 delay_setting_retransmission_alarm_(false), |
246 pending_retransmission_alarm_(false), | 246 pending_retransmission_alarm_(false), |
247 defer_send_in_response_to_packets_(false), | 247 defer_send_in_response_to_packets_(false), |
(...skipping 26 matching lines...) Expand all Loading... |
274 perspective, | 274 perspective, |
275 kDefaultPathId, | 275 kDefaultPathId, |
276 clock_, | 276 clock_, |
277 &stats_, | 277 &stats_, |
278 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, | 278 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, |
279 FLAGS_quic_use_time_loss_detection ? kTime : kNack, | 279 FLAGS_quic_use_time_loss_detection ? kTime : kNack, |
280 /*delegate=*/nullptr), | 280 /*delegate=*/nullptr), |
281 version_negotiation_state_(START_NEGOTIATION), | 281 version_negotiation_state_(START_NEGOTIATION), |
282 perspective_(perspective), | 282 perspective_(perspective), |
283 connected_(true), | 283 connected_(true), |
284 peer_ip_changed_(false), | |
285 peer_port_changed_(false), | |
286 self_ip_changed_(false), | |
287 self_port_changed_(false), | |
288 can_truncate_connection_ids_(true), | 284 can_truncate_connection_ids_(true), |
289 mtu_discovery_target_(0), | 285 mtu_discovery_target_(0), |
290 mtu_probe_count_(0), | 286 mtu_probe_count_(0), |
291 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), | 287 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), |
292 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), | 288 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), |
293 largest_received_packet_size_(0), | 289 largest_received_packet_size_(0), |
294 goaway_sent_(false), | 290 goaway_sent_(false), |
295 goaway_received_(false), | 291 goaway_received_(false), |
296 multipath_enabled_(false) { | 292 multipath_enabled_(false) { |
297 DVLOG(1) << ENDPOINT | 293 DVLOG(1) << ENDPOINT |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 if (debug_visitor_ != nullptr) { | 359 if (debug_visitor_ != nullptr) { |
364 debug_visitor_->OnSetFromConfig(config); | 360 debug_visitor_->OnSetFromConfig(config); |
365 } | 361 } |
366 if (config.HasClientSentConnectionOption(kACKD, perspective_)) { | 362 if (config.HasClientSentConnectionOption(kACKD, perspective_)) { |
367 ack_mode_ = ACK_DECIMATION; | 363 ack_mode_ = ACK_DECIMATION; |
368 } | 364 } |
369 if (FLAGS_quic_ack_decimation2 && | 365 if (FLAGS_quic_ack_decimation2 && |
370 config.HasClientSentConnectionOption(kAKD2, perspective_)) { | 366 config.HasClientSentConnectionOption(kAKD2, perspective_)) { |
371 ack_mode_ = ACK_DECIMATION_WITH_REORDERING; | 367 ack_mode_ = ACK_DECIMATION_WITH_REORDERING; |
372 } | 368 } |
| 369 if (FLAGS_quic_enable_rto_timeout && |
| 370 config.HasClientSentConnectionOption(k5RTO, perspective_)) { |
| 371 close_connection_after_five_rtos_ = true; |
| 372 } |
373 } | 373 } |
374 | 374 |
375 void QuicConnection::OnSendConnectionState( | 375 void QuicConnection::OnSendConnectionState( |
376 const CachedNetworkParameters& cached_network_params) { | 376 const CachedNetworkParameters& cached_network_params) { |
377 if (debug_visitor_ != nullptr) { | 377 if (debug_visitor_ != nullptr) { |
378 debug_visitor_->OnSendConnectionState(cached_network_params); | 378 debug_visitor_->OnSendConnectionState(cached_network_params); |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 void QuicConnection::OnReceiveConnectionState( | 382 void QuicConnection::OnReceiveConnectionState( |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 | 573 |
574 // Multipath is not enabled, but a packet with multipath flag on is received. | 574 // Multipath is not enabled, but a packet with multipath flag on is received. |
575 if (!multipath_enabled_ && header.public_header.multipath_flag) { | 575 if (!multipath_enabled_ && header.public_header.multipath_flag) { |
576 LOG(DFATAL) << "Received a packet with multipath flag on when multipath is " | 576 LOG(DFATAL) << "Received a packet with multipath flag on when multipath is " |
577 "not enabled."; | 577 "not enabled."; |
578 SendConnectionCloseWithDetails(QUIC_BAD_MULTIPATH_FLAG, | 578 SendConnectionCloseWithDetails(QUIC_BAD_MULTIPATH_FLAG, |
579 "receive a packet with multipath flag on " | 579 "receive a packet with multipath flag on " |
580 "when multipath is not enabled."); | 580 "when multipath is not enabled."); |
581 return false; | 581 return false; |
582 } | 582 } |
| 583 if (!packet_generator_.IsPendingPacketEmpty()) { |
| 584 QUIC_BUG << "Pending frames must be serialized before incoming packets are " |
| 585 << "processed, because that may change a queued ack frame."; |
| 586 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, |
| 587 "Should not process packets while sending."); |
| 588 return false; |
| 589 } |
583 | 590 |
584 // If this packet has already been seen, or the sender has told us that it | 591 // If this packet has already been seen, or the sender has told us that it |
585 // will not be retransmitted, then stop processing the packet. | 592 // will not be retransmitted, then stop processing the packet. |
586 if (!received_packet_manager_.IsAwaitingPacket(header.packet_number)) { | 593 if (!received_packet_manager_.IsAwaitingPacket(header.packet_number)) { |
587 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number | 594 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number |
588 << " no longer being waited for. Discarding."; | 595 << " no longer being waited for. Discarding."; |
589 if (debug_visitor_ != nullptr) { | 596 if (debug_visitor_ != nullptr) { |
590 debug_visitor_->OnDuplicatePacket(header.packet_number); | 597 debug_visitor_->OnDuplicatePacket(header.packet_number); |
591 } | 598 } |
592 ++stats_.packets_dropped; | 599 ++stats_.packets_dropped; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; | 669 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; |
663 return true; | 670 return true; |
664 } | 671 } |
665 | 672 |
666 const char* error = ValidateAckFrame(incoming_ack); | 673 const char* error = ValidateAckFrame(incoming_ack); |
667 if (error != nullptr) { | 674 if (error != nullptr) { |
668 SendConnectionCloseWithDetails(QUIC_INVALID_ACK_DATA, error); | 675 SendConnectionCloseWithDetails(QUIC_INVALID_ACK_DATA, error); |
669 return false; | 676 return false; |
670 } | 677 } |
671 | 678 |
672 if (FLAGS_quic_respect_send_alarm2 && send_alarm_->IsSet()) { | 679 if (send_alarm_->IsSet()) { |
673 send_alarm_->Cancel(); | 680 send_alarm_->Cancel(); |
674 } | 681 } |
675 ProcessAckFrame(incoming_ack); | 682 ProcessAckFrame(incoming_ack); |
676 if (incoming_ack.is_truncated) { | 683 if (incoming_ack.is_truncated) { |
677 should_last_packet_instigate_acks_ = true; | 684 should_last_packet_instigate_acks_ = true; |
678 } | 685 } |
679 // If the peer is still waiting for a packet that we are no longer planning to | 686 // If the peer is still waiting for a packet that we are no longer planning to |
680 // send, send an ack to raise the high water mark. | 687 // send, send an ack to raise the high water mark. |
681 if (!incoming_ack.missing_packets.Empty() && | 688 if (!incoming_ack.missing_packets.Empty() && |
682 GetLeastUnacked() > incoming_ack.missing_packets.Min()) { | 689 GetLeastUnacked() > incoming_ack.missing_packets.Min()) { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, | 1024 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, |
1018 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets)); | 1025 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets)); |
1019 } | 1026 } |
1020 } | 1027 } |
1021 | 1028 |
1022 void QuicConnection::PopulateAckFrame(QuicAckFrame* ack) { | 1029 void QuicConnection::PopulateAckFrame(QuicAckFrame* ack) { |
1023 received_packet_manager_.UpdateReceivedPacketInfo(ack, | 1030 received_packet_manager_.UpdateReceivedPacketInfo(ack, |
1024 clock_->ApproximateNow()); | 1031 clock_->ApproximateNow()); |
1025 } | 1032 } |
1026 | 1033 |
| 1034 const QuicFrame QuicConnection::GetUpdatedAckFrame() { |
| 1035 return received_packet_manager_.GetUpdatedAckFrame(clock_->ApproximateNow()); |
| 1036 } |
| 1037 |
1027 void QuicConnection::PopulateStopWaitingFrame( | 1038 void QuicConnection::PopulateStopWaitingFrame( |
1028 QuicStopWaitingFrame* stop_waiting) { | 1039 QuicStopWaitingFrame* stop_waiting) { |
1029 stop_waiting->least_unacked = GetLeastUnacked(); | 1040 stop_waiting->least_unacked = GetLeastUnacked(); |
1030 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( | 1041 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( |
1031 stop_waiting->least_unacked - 1); | 1042 stop_waiting->least_unacked - 1); |
1032 } | 1043 } |
1033 | 1044 |
1034 QuicPacketNumber QuicConnection::GetLeastUnacked() const { | 1045 QuicPacketNumber QuicConnection::GetLeastUnacked() const { |
1035 return sent_packet_manager_.GetLeastUnacked(); | 1046 return sent_packet_manager_.GetLeastUnacked(); |
1036 } | 1047 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 // SHLO from the server, leading to two different decrypters at the server.) | 1109 // SHLO from the server, leading to two different decrypters at the server.) |
1099 // | 1110 // |
1100 // TODO(jri): Note that ConsumeData may cause a response packet to be sent. | 1111 // TODO(jri): Note that ConsumeData may cause a response packet to be sent. |
1101 // We may end up sending stale ack information if there are undecryptable | 1112 // We may end up sending stale ack information if there are undecryptable |
1102 // packets hanging around and/or there are revivable packets which may get | 1113 // packets hanging around and/or there are revivable packets which may get |
1103 // handled after this packet is sent. Change ScopedPacketBundler to do the | 1114 // handled after this packet is sent. Change ScopedPacketBundler to do the |
1104 // right thing: check ack_queued_, and then check undecryptable packets and | 1115 // right thing: check ack_queued_, and then check undecryptable packets and |
1105 // also if there is possibility of revival. Only bundle an ack if there's no | 1116 // also if there is possibility of revival. Only bundle an ack if there's no |
1106 // processing left that may cause received_info_ to change. | 1117 // processing left that may cause received_info_ to change. |
1107 ScopedRetransmissionScheduler alarm_delayer(this); | 1118 ScopedRetransmissionScheduler alarm_delayer(this); |
1108 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1119 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); |
1109 return packet_generator_.ConsumeData(id, iov, offset, fin, listener); | 1120 return packet_generator_.ConsumeData(id, iov, offset, fin, listener); |
1110 } | 1121 } |
1111 | 1122 |
1112 void QuicConnection::SendRstStream(QuicStreamId id, | 1123 void QuicConnection::SendRstStream(QuicStreamId id, |
1113 QuicRstStreamErrorCode error, | 1124 QuicRstStreamErrorCode error, |
1114 QuicStreamOffset bytes_written) { | 1125 QuicStreamOffset bytes_written) { |
1115 // Opportunistically bundle an ack with this outgoing packet. | 1126 // Opportunistically bundle an ack with this outgoing packet. |
1116 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1127 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); |
1117 packet_generator_.AddControlFrame(QuicFrame(new QuicRstStreamFrame( | 1128 packet_generator_.AddControlFrame(QuicFrame(new QuicRstStreamFrame( |
1118 id, AdjustErrorForVersion(error, version()), bytes_written))); | 1129 id, AdjustErrorForVersion(error, version()), bytes_written))); |
1119 | 1130 |
1120 if (error == QUIC_STREAM_NO_ERROR && version() > QUIC_VERSION_28) { | 1131 if (error == QUIC_STREAM_NO_ERROR && version() > QUIC_VERSION_28) { |
1121 // All data for streams which are reset with QUIC_STREAM_NO_ERROR must | 1132 // All data for streams which are reset with QUIC_STREAM_NO_ERROR must |
1122 // be received by the peer. | 1133 // be received by the peer. |
1123 return; | 1134 return; |
1124 } | 1135 } |
1125 | 1136 |
1126 sent_packet_manager_.CancelRetransmissionsForStream(id); | 1137 sent_packet_manager_.CancelRetransmissionsForStream(id); |
(...skipping 13 matching lines...) Expand all Loading... |
1140 } | 1151 } |
1141 delete[] packet_iterator->encrypted_buffer; | 1152 delete[] packet_iterator->encrypted_buffer; |
1142 QuicUtils::ClearSerializedPacket(&(*packet_iterator)); | 1153 QuicUtils::ClearSerializedPacket(&(*packet_iterator)); |
1143 packet_iterator = queued_packets_.erase(packet_iterator); | 1154 packet_iterator = queued_packets_.erase(packet_iterator); |
1144 } | 1155 } |
1145 } | 1156 } |
1146 | 1157 |
1147 void QuicConnection::SendWindowUpdate(QuicStreamId id, | 1158 void QuicConnection::SendWindowUpdate(QuicStreamId id, |
1148 QuicStreamOffset byte_offset) { | 1159 QuicStreamOffset byte_offset) { |
1149 // Opportunistically bundle an ack with this outgoing packet. | 1160 // Opportunistically bundle an ack with this outgoing packet. |
1150 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1161 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); |
1151 packet_generator_.AddControlFrame( | 1162 packet_generator_.AddControlFrame( |
1152 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); | 1163 QuicFrame(new QuicWindowUpdateFrame(id, byte_offset))); |
1153 } | 1164 } |
1154 | 1165 |
1155 void QuicConnection::SendBlocked(QuicStreamId id) { | 1166 void QuicConnection::SendBlocked(QuicStreamId id) { |
1156 // Opportunistically bundle an ack with this outgoing packet. | 1167 // Opportunistically bundle an ack with this outgoing packet. |
1157 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1168 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); |
1158 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); | 1169 packet_generator_.AddControlFrame(QuicFrame(new QuicBlockedFrame(id))); |
1159 } | 1170 } |
1160 | 1171 |
1161 void QuicConnection::SendPathClose(QuicPathId path_id) { | 1172 void QuicConnection::SendPathClose(QuicPathId path_id) { |
1162 // Opportunistically bundle an ack with this outgoing packet. | 1173 // Opportunistically bundle an ack with this outgoing packet. |
1163 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1174 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); |
1164 packet_generator_.AddControlFrame(QuicFrame(new QuicPathCloseFrame(path_id))); | 1175 packet_generator_.AddControlFrame(QuicFrame(new QuicPathCloseFrame(path_id))); |
1165 OnPathClosed(path_id); | 1176 OnPathClosed(path_id); |
1166 } | 1177 } |
1167 | 1178 |
1168 const QuicConnectionStats& QuicConnection::GetStats() { | 1179 const QuicConnectionStats& QuicConnection::GetStats() { |
1169 const RttStats* rtt_stats = sent_packet_manager_.GetRttStats(); | 1180 const RttStats* rtt_stats = sent_packet_manager_.GetRttStats(); |
1170 | 1181 |
1171 // Update rtt and estimated bandwidth. | 1182 // Update rtt and estimated bandwidth. |
1172 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); | 1183 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); |
1173 if (min_rtt.IsZero()) { | 1184 if (min_rtt.IsZero()) { |
(...skipping 20 matching lines...) Expand all Loading... |
1194 const QuicEncryptedPacket& packet) { | 1205 const QuicEncryptedPacket& packet) { |
1195 if (!connected_) { | 1206 if (!connected_) { |
1196 return; | 1207 return; |
1197 } | 1208 } |
1198 if (debug_visitor_ != nullptr) { | 1209 if (debug_visitor_ != nullptr) { |
1199 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); | 1210 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); |
1200 } | 1211 } |
1201 last_size_ = packet.length(); | 1212 last_size_ = packet.length(); |
1202 current_packet_data_ = packet.data(); | 1213 current_packet_data_ = packet.data(); |
1203 | 1214 |
1204 if (FLAGS_check_peer_address_change_after_decryption) { | 1215 last_packet_destination_address_ = self_address; |
1205 last_packet_destination_address_ = self_address; | 1216 last_packet_source_address_ = peer_address; |
1206 last_packet_source_address_ = peer_address; | 1217 if (!IsInitializedIPEndPoint(self_address_)) { |
1207 if (!IsInitializedIPEndPoint(self_address_)) { | 1218 self_address_ = last_packet_destination_address_; |
1208 self_address_ = last_packet_destination_address_; | 1219 } |
1209 } | 1220 if (!IsInitializedIPEndPoint(peer_address_)) { |
1210 if (!IsInitializedIPEndPoint(peer_address_)) { | 1221 peer_address_ = last_packet_source_address_; |
1211 peer_address_ = last_packet_source_address_; | |
1212 } | |
1213 } else { | |
1214 CheckForAddressMigration(self_address, peer_address); | |
1215 } | 1222 } |
1216 | 1223 |
1217 stats_.bytes_received += packet.length(); | 1224 stats_.bytes_received += packet.length(); |
1218 ++stats_.packets_received; | 1225 ++stats_.packets_received; |
1219 | 1226 |
1220 ScopedRetransmissionScheduler alarm_delayer(this); | 1227 ScopedRetransmissionScheduler alarm_delayer(this); |
1221 if (!framer_.ProcessPacket(packet)) { | 1228 if (!framer_.ProcessPacket(packet)) { |
1222 // If we are unable to decrypt this packet, it might be | 1229 // If we are unable to decrypt this packet, it might be |
1223 // because the CHLO or SHLO packet was lost. | 1230 // because the CHLO or SHLO packet was lost. |
1224 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { | 1231 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { |
(...skipping 10 matching lines...) Expand all Loading... |
1235 return; | 1242 return; |
1236 } | 1243 } |
1237 | 1244 |
1238 ++stats_.packets_processed; | 1245 ++stats_.packets_processed; |
1239 MaybeProcessUndecryptablePackets(); | 1246 MaybeProcessUndecryptablePackets(); |
1240 MaybeSendInResponseToPacket(); | 1247 MaybeSendInResponseToPacket(); |
1241 SetPingAlarm(); | 1248 SetPingAlarm(); |
1242 current_packet_data_ = nullptr; | 1249 current_packet_data_ = nullptr; |
1243 } | 1250 } |
1244 | 1251 |
1245 void QuicConnection::CheckForAddressMigration(const IPEndPoint& self_address, | |
1246 const IPEndPoint& peer_address) { | |
1247 peer_ip_changed_ = false; | |
1248 peer_port_changed_ = false; | |
1249 self_ip_changed_ = false; | |
1250 self_port_changed_ = false; | |
1251 | |
1252 if (peer_address_.address().empty()) { | |
1253 peer_address_ = peer_address; | |
1254 } | |
1255 if (self_address_.address().empty()) { | |
1256 self_address_ = self_address; | |
1257 } | |
1258 | |
1259 if (!peer_address.address().empty() && !peer_address_.address().empty()) { | |
1260 peer_ip_changed_ = (peer_address.address() != peer_address_.address()); | |
1261 peer_port_changed_ = (peer_address.port() != peer_address_.port()); | |
1262 | |
1263 // Store in case we want to migrate connection in ProcessValidatedPacket. | |
1264 migrating_peer_ip_ = peer_address.address(); | |
1265 migrating_peer_port_ = peer_address.port(); | |
1266 } | |
1267 | |
1268 if (!self_address.address().empty() && !self_address_.address().empty()) { | |
1269 self_ip_changed_ = (self_address.address() != self_address_.address()); | |
1270 self_port_changed_ = (self_address.port() != self_address_.port()); | |
1271 } | |
1272 } | |
1273 | |
1274 void QuicConnection::OnCanWrite() { | 1252 void QuicConnection::OnCanWrite() { |
1275 DCHECK(!writer_->IsWriteBlocked()); | 1253 DCHECK(!writer_->IsWriteBlocked()); |
1276 | 1254 |
1277 WriteQueuedPackets(); | 1255 WriteQueuedPackets(); |
1278 WritePendingRetransmissions(); | 1256 WritePendingRetransmissions(); |
1279 | 1257 |
1280 // Sending queued packets may have caused the socket to become write blocked, | 1258 // Sending queued packets may have caused the socket to become write blocked, |
1281 // or the congestion manager to prohibit sending. If we've sent everything | 1259 // or the congestion manager to prohibit sending. If we've sent everything |
1282 // we had queued and we're still not blocked, let the visitor know it can | 1260 // we had queued and we're still not blocked, let the visitor know it can |
1283 // write more. | 1261 // write more. |
1284 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) { | 1262 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) { |
1285 return; | 1263 return; |
1286 } | 1264 } |
1287 | 1265 |
1288 { // Limit the scope of the bundler. ACK inclusion happens elsewhere. | 1266 { |
1289 ScopedPacketBundler bundler(this, NO_ACK); | 1267 ScopedPacketBundler bundler(this, SEND_ACK_IF_QUEUED); |
1290 visitor_->OnCanWrite(); | 1268 visitor_->OnCanWrite(); |
1291 visitor_->PostProcessAfterData(); | 1269 visitor_->PostProcessAfterData(); |
1292 } | 1270 } |
1293 | 1271 |
1294 // After the visitor writes, it may have caused the socket to become write | 1272 // After the visitor writes, it may have caused the socket to become write |
1295 // blocked or the congestion manager to prohibit sending, so check again. | 1273 // blocked or the congestion manager to prohibit sending, so check again. |
1296 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && | 1274 if (visitor_->WillingAndAbleToWrite() && !resume_writes_alarm_->IsSet() && |
1297 CanWrite(HAS_RETRANSMITTABLE_DATA)) { | 1275 CanWrite(HAS_RETRANSMITTABLE_DATA)) { |
1298 // We're not write blocked, but some stream didn't write out all of its | 1276 // We're not write blocked, but some stream didn't write out all of its |
1299 // bytes. Register for 'immediate' resumption so we'll keep writing after | 1277 // bytes. Register for 'immediate' resumption so we'll keep writing after |
1300 // other connections and events have had a chance to use the thread. | 1278 // other connections and events have had a chance to use the thread. |
1301 resume_writes_alarm_->Set(clock_->ApproximateNow()); | 1279 resume_writes_alarm_->Set(clock_->ApproximateNow()); |
1302 } | 1280 } |
1303 } | 1281 } |
1304 | 1282 |
1305 void QuicConnection::WriteIfNotBlocked() { | 1283 void QuicConnection::WriteIfNotBlocked() { |
1306 if (!writer_->IsWriteBlocked()) { | 1284 if (!writer_->IsWriteBlocked()) { |
1307 OnCanWrite(); | 1285 OnCanWrite(); |
1308 } | 1286 } |
1309 } | 1287 } |
1310 | 1288 |
1311 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { | 1289 void QuicConnection::WriteAndBundleAcksIfNotBlocked() { |
1312 if (!writer_->IsWriteBlocked()) { | 1290 if (!writer_->IsWriteBlocked()) { |
1313 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); | 1291 ScopedPacketBundler bundler(this, SEND_ACK_IF_QUEUED); |
1314 OnCanWrite(); | 1292 OnCanWrite(); |
1315 } | 1293 } |
1316 } | 1294 } |
1317 | 1295 |
1318 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { | 1296 bool QuicConnection::ProcessValidatedPacket(const QuicPacketHeader& header) { |
1319 if (header.fec_flag) { | 1297 if (header.fec_flag) { |
1320 // Drop any FEC packet. | 1298 // Drop any FEC packet. |
1321 return false; | 1299 return false; |
1322 } | 1300 } |
1323 | 1301 |
1324 if (FLAGS_check_peer_address_change_after_decryption) { | 1302 if (perspective_ == Perspective::IS_SERVER && |
1325 if (perspective_ == Perspective::IS_SERVER && | 1303 IsInitializedIPEndPoint(self_address_) && |
1326 IsInitializedIPEndPoint(self_address_) && | 1304 IsInitializedIPEndPoint(last_packet_destination_address_) && |
1327 IsInitializedIPEndPoint(last_packet_destination_address_) && | 1305 (!(self_address_ == last_packet_destination_address_))) { |
1328 (!(self_address_ == last_packet_destination_address_))) { | 1306 SendConnectionCloseWithDetails( |
1329 SendConnectionCloseWithDetails( | 1307 QUIC_ERROR_MIGRATING_ADDRESS, |
1330 QUIC_ERROR_MIGRATING_ADDRESS, | 1308 "Self address migration is not supported at the server."); |
1331 "Self address migration is not supported at the server."); | 1309 return false; |
1332 return false; | |
1333 } | |
1334 } else { | |
1335 if (perspective_ == Perspective::IS_SERVER && | |
1336 (self_ip_changed_ || self_port_changed_)) { | |
1337 SendConnectionCloseWithDetails( | |
1338 QUIC_ERROR_MIGRATING_ADDRESS, | |
1339 "Self address migration is not supported at the server."); | |
1340 return false; | |
1341 } | |
1342 } | 1310 } |
1343 | 1311 |
1344 if (!Near(header.packet_number, last_header_.packet_number)) { | 1312 if (!Near(header.packet_number, last_header_.packet_number)) { |
1345 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number | 1313 DVLOG(1) << ENDPOINT << "Packet " << header.packet_number |
1346 << " out of bounds. Discarding"; | 1314 << " out of bounds. Discarding"; |
1347 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, | 1315 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, |
1348 "packet number out of bounds"); | 1316 "packet number out of bounds"); |
1349 return false; | 1317 return false; |
1350 } | 1318 } |
1351 | 1319 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) { | 1435 bool QuicConnection::CanWrite(HasRetransmittableData retransmittable) { |
1468 if (!connected_) { | 1436 if (!connected_) { |
1469 return false; | 1437 return false; |
1470 } | 1438 } |
1471 | 1439 |
1472 if (writer_->IsWriteBlocked()) { | 1440 if (writer_->IsWriteBlocked()) { |
1473 visitor_->OnWriteBlocked(); | 1441 visitor_->OnWriteBlocked(); |
1474 return false; | 1442 return false; |
1475 } | 1443 } |
1476 | 1444 |
1477 if (FLAGS_quic_respect_send_alarm2) { | 1445 // Allow acks to be sent immediately. |
1478 // Allow acks to be sent immediately. | 1446 // TODO(ianswett): Remove retransmittable from |
1479 // TODO(ianswett): Remove retransmittable from | 1447 // SendAlgorithmInterface::TimeUntilSend. |
1480 // SendAlgorithmInterface::TimeUntilSend. | 1448 if (retransmittable == NO_RETRANSMITTABLE_DATA) { |
1481 if (retransmittable == NO_RETRANSMITTABLE_DATA) { | 1449 return true; |
1482 return true; | 1450 } |
1483 } | 1451 // If the send alarm is set, wait for it to fire. |
1484 // If the send alarm is set, wait for it to fire. | 1452 if (send_alarm_->IsSet()) { |
1485 if (send_alarm_->IsSet()) { | 1453 return false; |
1486 return false; | |
1487 } | |
1488 } | 1454 } |
1489 | 1455 |
1490 QuicTime now = clock_->Now(); | 1456 QuicTime now = clock_->Now(); |
1491 QuicTime::Delta delay = | 1457 QuicTime::Delta delay = |
1492 sent_packet_manager_.TimeUntilSend(now, retransmittable); | 1458 sent_packet_manager_.TimeUntilSend(now, retransmittable); |
1493 if (delay.IsInfinite()) { | 1459 if (delay.IsInfinite()) { |
1494 send_alarm_->Cancel(); | 1460 send_alarm_->Cancel(); |
1495 return false; | 1461 return false; |
1496 } | 1462 } |
1497 | 1463 |
1498 // If the scheduler requires a delay, then we can not send this packet now. | 1464 // If the scheduler requires a delay, then we can not send this packet now. |
1499 if (!delay.IsZero()) { | 1465 if (!delay.IsZero()) { |
1500 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1)); | 1466 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1)); |
1501 DVLOG(1) << ENDPOINT << "Delaying sending " << delay.ToMilliseconds() | 1467 DVLOG(1) << ENDPOINT << "Delaying sending " << delay.ToMilliseconds() |
1502 << "ms"; | 1468 << "ms"; |
1503 return false; | 1469 return false; |
1504 } | 1470 } |
1505 if (!FLAGS_quic_respect_send_alarm2) { | |
1506 send_alarm_->Cancel(); | |
1507 } | |
1508 return true; | 1471 return true; |
1509 } | 1472 } |
1510 | 1473 |
1511 bool QuicConnection::WritePacket(SerializedPacket* packet) { | 1474 bool QuicConnection::WritePacket(SerializedPacket* packet) { |
1512 if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) { | 1475 if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) { |
1513 QUIC_BUG << "Attempt to write packet:" << packet->packet_number | 1476 QUIC_BUG << "Attempt to write packet:" << packet->packet_number |
1514 << " after:" << sent_packet_manager_.largest_sent_packet(); | 1477 << " after:" << sent_packet_manager_.largest_sent_packet(); |
1515 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, | 1478 SendConnectionCloseWithDetails(QUIC_INTERNAL_ERROR, |
1516 "Packet written out of order."); | 1479 "Packet written out of order."); |
1517 return true; | 1480 return true; |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 } | 1716 } |
1754 } | 1717 } |
1755 | 1718 |
1756 void QuicConnection::OnPingTimeout() { | 1719 void QuicConnection::OnPingTimeout() { |
1757 if (!retransmission_alarm_->IsSet()) { | 1720 if (!retransmission_alarm_->IsSet()) { |
1758 SendPing(); | 1721 SendPing(); |
1759 } | 1722 } |
1760 } | 1723 } |
1761 | 1724 |
1762 void QuicConnection::SendPing() { | 1725 void QuicConnection::SendPing() { |
1763 ScopedPacketBundler bundler(this, ack_queued_ ? SEND_ACK : NO_ACK); | 1726 ScopedPacketBundler bundler(this, SEND_ACK_IF_QUEUED); |
1764 packet_generator_.AddControlFrame(QuicFrame(QuicPingFrame())); | 1727 packet_generator_.AddControlFrame(QuicFrame(QuicPingFrame())); |
1765 // Send PING frame immediately, without checking for congestion window bounds. | 1728 // Send PING frame immediately, without checking for congestion window bounds. |
1766 packet_generator_.FlushAllQueuedFrames(); | 1729 packet_generator_.FlushAllQueuedFrames(); |
1767 } | 1730 } |
1768 | 1731 |
1769 void QuicConnection::SendAck() { | 1732 void QuicConnection::SendAck() { |
1770 ack_alarm_->Cancel(); | 1733 ack_alarm_->Cancel(); |
1771 ack_queued_ = false; | 1734 ack_queued_ = false; |
1772 stop_waiting_count_ = 0; | 1735 stop_waiting_count_ = 0; |
1773 num_retransmittable_packets_received_since_last_ack_sent_ = 0; | 1736 num_retransmittable_packets_received_since_last_ack_sent_ = 0; |
1774 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); | 1737 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); |
1775 num_packets_received_since_last_ack_sent_ = 0; | 1738 num_packets_received_since_last_ack_sent_ = 0; |
1776 | 1739 |
1777 packet_generator_.SetShouldSendAck(true); | 1740 packet_generator_.SetShouldSendAck(true); |
1778 } | 1741 } |
1779 | 1742 |
1780 void QuicConnection::OnRetransmissionTimeout() { | 1743 void QuicConnection::OnRetransmissionTimeout() { |
1781 if (!sent_packet_manager_.HasUnackedPackets()) { | 1744 if (!sent_packet_manager_.HasUnackedPackets()) { |
1782 return; | 1745 return; |
1783 } | 1746 } |
1784 | 1747 |
| 1748 if (close_connection_after_five_rtos_ && |
| 1749 sent_packet_manager_.consecutive_rto_count() >= 4) { |
| 1750 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. |
| 1751 SendConnectionCloseWithDetails(QUIC_TOO_MANY_RTOS, |
| 1752 "5 consecutive retransmission timeouts"); |
| 1753 return; |
| 1754 } |
| 1755 |
1785 sent_packet_manager_.OnRetransmissionTimeout(); | 1756 sent_packet_manager_.OnRetransmissionTimeout(); |
1786 WriteIfNotBlocked(); | 1757 WriteIfNotBlocked(); |
1787 | 1758 |
1788 // A write failure can result in the connection being closed, don't attempt to | 1759 // A write failure can result in the connection being closed, don't attempt to |
1789 // write further packets, or to set alarms. | 1760 // write further packets, or to set alarms. |
1790 if (!connected_) { | 1761 if (!connected_) { |
1791 return; | 1762 return; |
1792 } | 1763 } |
1793 | 1764 |
1794 // In the TLP case, the SentPacketManager gives the connection the opportunity | 1765 // In the TLP case, the SentPacketManager gives the connection the opportunity |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 const string& reason) { | 1920 const string& reason) { |
1950 if (goaway_sent_) { | 1921 if (goaway_sent_) { |
1951 return; | 1922 return; |
1952 } | 1923 } |
1953 goaway_sent_ = true; | 1924 goaway_sent_ = true; |
1954 | 1925 |
1955 DVLOG(1) << ENDPOINT << "Going away with error " | 1926 DVLOG(1) << ENDPOINT << "Going away with error " |
1956 << QuicUtils::ErrorToString(error) << " (" << error << ")"; | 1927 << QuicUtils::ErrorToString(error) << " (" << error << ")"; |
1957 | 1928 |
1958 // Opportunistically bundle an ack with this outgoing packet. | 1929 // Opportunistically bundle an ack with this outgoing packet. |
1959 ScopedPacketBundler ack_bundler(this, BUNDLE_PENDING_ACK); | 1930 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); |
1960 packet_generator_.AddControlFrame( | 1931 packet_generator_.AddControlFrame( |
1961 QuicFrame(new QuicGoAwayFrame(error, last_good_stream_id, reason))); | 1932 QuicFrame(new QuicGoAwayFrame(error, last_good_stream_id, reason))); |
1962 } | 1933 } |
1963 | 1934 |
1964 QuicByteCount QuicConnection::max_packet_length() const { | 1935 QuicByteCount QuicConnection::max_packet_length() const { |
1965 return packet_generator_.GetCurrentMaxPacketLength(); | 1936 return packet_generator_.GetCurrentMaxPacketLength(); |
1966 } | 1937 } |
1967 | 1938 |
1968 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { | 1939 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { |
1969 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length)); | 1940 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2114 | 2085 |
2115 if (packet_number_of_last_sent_packet_ >= next_mtu_probe_at_) { | 2086 if (packet_number_of_last_sent_packet_ >= next_mtu_probe_at_) { |
2116 // Use an alarm to send the MTU probe to ensure that no ScopedPacketBundlers | 2087 // Use an alarm to send the MTU probe to ensure that no ScopedPacketBundlers |
2117 // are active. | 2088 // are active. |
2118 mtu_discovery_alarm_->Set(clock_->ApproximateNow()); | 2089 mtu_discovery_alarm_->Set(clock_->ApproximateNow()); |
2119 } | 2090 } |
2120 } | 2091 } |
2121 | 2092 |
2122 QuicConnection::ScopedPacketBundler::ScopedPacketBundler( | 2093 QuicConnection::ScopedPacketBundler::ScopedPacketBundler( |
2123 QuicConnection* connection, | 2094 QuicConnection* connection, |
2124 AckBundling send_ack) | 2095 AckBundling ack_mode) |
2125 : connection_(connection), | 2096 : connection_(connection), |
2126 already_in_batch_mode_(connection != nullptr && | 2097 already_in_batch_mode_(connection != nullptr && |
2127 connection->packet_generator_.InBatchMode()) { | 2098 connection->packet_generator_.InBatchMode()) { |
2128 if (connection_ == nullptr) { | 2099 if (connection_ == nullptr) { |
2129 return; | 2100 return; |
2130 } | 2101 } |
2131 // Move generator into batch mode. If caller wants us to include an ack, | 2102 // Move generator into batch mode. If caller wants us to include an ack, |
2132 // check the delayed-ack timer to see if there's ack info to be sent. | 2103 // check the delayed-ack timer to see if there's ack info to be sent. |
2133 if (!already_in_batch_mode_) { | 2104 if (!already_in_batch_mode_) { |
2134 DVLOG(1) << "Entering Batch Mode."; | 2105 DVLOG(1) << "Entering Batch Mode."; |
2135 connection_->packet_generator_.StartBatchOperations(); | 2106 connection_->packet_generator_.StartBatchOperations(); |
2136 } | 2107 } |
2137 // Bundle an ack if the alarm is set or with every second packet if we need to | 2108 if (ShouldSendAck(ack_mode)) { |
2138 // raise the peer's least unacked. | |
2139 bool ack_pending = | |
2140 connection_->ack_alarm_->IsSet() || connection_->stop_waiting_count_ > 1; | |
2141 if (send_ack == SEND_ACK || (send_ack == BUNDLE_PENDING_ACK && ack_pending)) { | |
2142 DVLOG(1) << "Bundling ack with outgoing packet."; | 2109 DVLOG(1) << "Bundling ack with outgoing packet."; |
2143 DCHECK(send_ack == SEND_ACK || connection_->ack_frame_updated() || | 2110 DCHECK(ack_mode == SEND_ACK || connection_->ack_frame_updated() || |
2144 connection_->stop_waiting_count_ > 1); | 2111 connection_->stop_waiting_count_ > 1); |
2145 connection_->SendAck(); | 2112 connection_->SendAck(); |
2146 } | 2113 } |
2147 } | 2114 } |
2148 | 2115 |
| 2116 bool QuicConnection::ScopedPacketBundler::ShouldSendAck( |
| 2117 AckBundling ack_mode) const { |
| 2118 switch (ack_mode) { |
| 2119 case SEND_ACK: |
| 2120 return true; |
| 2121 case SEND_ACK_IF_QUEUED: |
| 2122 return connection_->ack_queued(); |
| 2123 case SEND_ACK_IF_PENDING: |
| 2124 return connection_->ack_alarm_->IsSet() || |
| 2125 connection_->stop_waiting_count_ > 1; |
| 2126 default: |
| 2127 QUIC_BUG << "Unsupported ack_mode."; |
| 2128 return true; |
| 2129 } |
| 2130 } |
| 2131 |
2149 QuicConnection::ScopedPacketBundler::~ScopedPacketBundler() { | 2132 QuicConnection::ScopedPacketBundler::~ScopedPacketBundler() { |
2150 if (connection_ == nullptr) { | 2133 if (connection_ == nullptr) { |
2151 return; | 2134 return; |
2152 } | 2135 } |
2153 // If we changed the generator's batch state, restore original batch state. | 2136 // If we changed the generator's batch state, restore original batch state. |
2154 if (!already_in_batch_mode_) { | 2137 if (!already_in_batch_mode_) { |
2155 DVLOG(1) << "Leaving Batch Mode."; | 2138 DVLOG(1) << "Leaving Batch Mode."; |
2156 connection_->packet_generator_.FinishBatchOperations(); | 2139 connection_->packet_generator_.FinishBatchOperations(); |
2157 } | 2140 } |
2158 DCHECK_EQ(already_in_batch_mode_, | 2141 DCHECK_EQ(already_in_batch_mode_, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2264 ++mtu_probe_count_; | 2247 ++mtu_probe_count_; |
2265 | 2248 |
2266 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; | 2249 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; |
2267 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2250 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2268 | 2251 |
2269 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2252 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2270 } | 2253 } |
2271 | 2254 |
2272 void QuicConnection::MaybeMigrateConnectionToNewPeerAddress() { | 2255 void QuicConnection::MaybeMigrateConnectionToNewPeerAddress() { |
2273 IPEndPoint last_peer_address; | 2256 IPEndPoint last_peer_address; |
2274 if (FLAGS_check_peer_address_change_after_decryption) { | 2257 last_peer_address = last_packet_source_address_; |
2275 last_peer_address = last_packet_source_address_; | |
2276 } else { | |
2277 last_peer_address = IPEndPoint( | |
2278 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(), | |
2279 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); | |
2280 } | |
2281 PeerAddressChangeType peer_address_change_type = | 2258 PeerAddressChangeType peer_address_change_type = |
2282 QuicUtils::DetermineAddressChangeType(peer_address_, last_peer_address); | 2259 QuicUtils::DetermineAddressChangeType(peer_address_, last_peer_address); |
2283 // TODO(fayang): Currently, all peer address change type are allowed. Need to | 2260 // TODO(fayang): Currently, all peer address change type are allowed. Need to |
2284 // add a method ShouldAllowPeerAddressChange(PeerAddressChangeType type) to | 2261 // add a method ShouldAllowPeerAddressChange(PeerAddressChangeType type) to |
2285 // determine whehter |type| is allowed. | 2262 // determine whether |type| is allowed. |
2286 if (FLAGS_check_peer_address_change_after_decryption) { | 2263 if (peer_address_change_type == NO_CHANGE) { |
2287 if (peer_address_change_type == NO_CHANGE) { | |
2288 return; | |
2289 } | |
2290 | |
2291 IPEndPoint old_peer_address = peer_address_; | |
2292 peer_address_ = last_packet_source_address_; | |
2293 | |
2294 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " | |
2295 << old_peer_address.ToString() << " to " | |
2296 << peer_address_.ToString() << ", migrating connection."; | |
2297 | |
2298 visitor_->OnConnectionMigration(peer_address_change_type); | |
2299 sent_packet_manager_.OnConnectionMigration(peer_address_change_type); | |
2300 | |
2301 return; | 2264 return; |
2302 } | 2265 } |
2303 | 2266 |
2304 if (peer_ip_changed_ || peer_port_changed_) { | 2267 IPEndPoint old_peer_address = peer_address_; |
2305 IPEndPoint old_peer_address = peer_address_; | 2268 peer_address_ = last_packet_source_address_; |
2306 peer_address_ = IPEndPoint( | |
2307 peer_ip_changed_ ? migrating_peer_ip_ : peer_address_.address(), | |
2308 peer_port_changed_ ? migrating_peer_port_ : peer_address_.port()); | |
2309 | 2269 |
2310 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " | 2270 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " |
2311 << old_peer_address.ToString() << " to " | 2271 << old_peer_address.ToString() << " to " << peer_address_.ToString() |
2312 << peer_address_.ToString() << ", migrating connection."; | 2272 << ", migrating connection."; |
2313 | 2273 |
2314 visitor_->OnConnectionMigration(peer_address_change_type); | 2274 visitor_->OnConnectionMigration(peer_address_change_type); |
2315 DCHECK_NE(peer_address_change_type, NO_CHANGE); | 2275 sent_packet_manager_.OnConnectionMigration(peer_address_change_type); |
2316 sent_packet_manager_.OnConnectionMigration(peer_address_change_type); | |
2317 } | |
2318 } | 2276 } |
2319 | 2277 |
2320 void QuicConnection::OnPathClosed(QuicPathId path_id) { | 2278 void QuicConnection::OnPathClosed(QuicPathId path_id) { |
2321 // Stop receiving packets on this path. | 2279 // Stop receiving packets on this path. |
2322 framer_.OnPathClosed(path_id); | 2280 framer_.OnPathClosed(path_id); |
2323 } | 2281 } |
2324 | 2282 |
2325 bool QuicConnection::ack_frame_updated() const { | 2283 bool QuicConnection::ack_frame_updated() const { |
2326 return received_packet_manager_.ack_frame_updated(); | 2284 return received_packet_manager_.ack_frame_updated(); |
2327 } | 2285 } |
2328 | 2286 |
2329 StringPiece QuicConnection::GetCurrentPacket() { | 2287 StringPiece QuicConnection::GetCurrentPacket() { |
2330 if (current_packet_data_ == nullptr) { | 2288 if (current_packet_data_ == nullptr) { |
2331 return StringPiece(); | 2289 return StringPiece(); |
2332 } | 2290 } |
2333 return StringPiece(current_packet_data_, last_size_); | 2291 return StringPiece(current_packet_data_, last_size_); |
2334 } | 2292 } |
2335 | 2293 |
2336 } // namespace net | 2294 } // namespace net |
OLD | NEW |