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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 class MtuDiscoveryAckListener : public QuicAckNotifier::DelegateInterface { | 200 class MtuDiscoveryAckListener : public QuicAckNotifier::DelegateInterface { |
201 public: | 201 public: |
202 MtuDiscoveryAckListener(QuicConnection* connection, QuicByteCount probe_size) | 202 MtuDiscoveryAckListener(QuicConnection* connection, QuicByteCount probe_size) |
203 : connection_(connection), probe_size_(probe_size) {} | 203 : connection_(connection), probe_size_(probe_size) {} |
204 | 204 |
205 void OnAckNotification(int /*num_retransmittable_packets*/, | 205 void OnAckNotification(int /*num_retransmittable_packets*/, |
206 int /*num_retransmittable_bytes*/, | 206 int /*num_retransmittable_bytes*/, |
207 QuicTime::Delta /*delta_largest_observed*/) override { | 207 QuicTime::Delta /*delta_largest_observed*/) override { |
208 // Since the probe was successful, increase the maximum packet size to that. | 208 // Since the probe was successful, increase the maximum packet size to that. |
209 if (probe_size_ > connection_->max_packet_length()) { | 209 if (probe_size_ > connection_->max_packet_length()) { |
210 connection_->set_max_packet_length(probe_size_); | 210 connection_->SetMaxPacketLength(probe_size_); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 protected: | 214 protected: |
215 // MtuDiscoveryAckListener is ref counted. | 215 // MtuDiscoveryAckListener is ref counted. |
216 ~MtuDiscoveryAckListener() override {} | 216 ~MtuDiscoveryAckListener() override {} |
217 | 217 |
218 private: | 218 private: |
219 QuicConnection* connection_; | 219 QuicConnection* connection_; |
220 QuicByteCount probe_size_; | 220 QuicByteCount probe_size_; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), | 320 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), |
321 largest_received_packet_size_(0), | 321 largest_received_packet_size_(0), |
322 goaway_sent_(false), | 322 goaway_sent_(false), |
323 goaway_received_(false) { | 323 goaway_received_(false) { |
324 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " | 324 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " |
325 << connection_id; | 325 << connection_id; |
326 framer_.set_visitor(this); | 326 framer_.set_visitor(this); |
327 framer_.set_received_entropy_calculator(&received_packet_manager_); | 327 framer_.set_received_entropy_calculator(&received_packet_manager_); |
328 stats_.connection_creation_time = clock_->ApproximateNow(); | 328 stats_.connection_creation_time = clock_->ApproximateNow(); |
329 sent_packet_manager_.set_network_change_visitor(this); | 329 sent_packet_manager_.set_network_change_visitor(this); |
330 if (perspective_ == Perspective::IS_SERVER) { | 330 // Allow the packet writer to potentially reduce the packet size to a value |
331 set_max_packet_length(kDefaultServerMaxPacketSize); | 331 // even smaller than kDefaultMaxPacketSize. |
332 } | 332 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER |
| 333 ? kDefaultServerMaxPacketSize |
| 334 : kDefaultMaxPacketSize); |
333 } | 335 } |
334 | 336 |
335 QuicConnection::~QuicConnection() { | 337 QuicConnection::~QuicConnection() { |
336 if (owns_writer_) { | 338 if (owns_writer_) { |
337 delete writer_; | 339 delete writer_; |
338 } | 340 } |
339 STLDeleteElements(&undecryptable_packets_); | 341 STLDeleteElements(&undecryptable_packets_); |
340 STLDeleteValues(&group_map_); | 342 STLDeleteValues(&group_map_); |
341 ClearQueuedPackets(); | 343 ClearQueuedPackets(); |
342 } | 344 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 packet_generator_.set_fec_send_policy(FecSendPolicy::FEC_ALARM_TRIGGER); | 376 packet_generator_.set_fec_send_policy(FecSendPolicy::FEC_ALARM_TRIGGER); |
375 } | 377 } |
376 if (config.HasClientSentConnectionOption(kFRTT, perspective_)) { | 378 if (config.HasClientSentConnectionOption(kFRTT, perspective_)) { |
377 // TODO(rtenneti): Delete this code after the 0.25 RTT FEC experiment. | 379 // TODO(rtenneti): Delete this code after the 0.25 RTT FEC experiment. |
378 const float kFecTimeoutRttMultiplier = 0.25; | 380 const float kFecTimeoutRttMultiplier = 0.25; |
379 packet_generator_.set_rtt_multiplier_for_fec_timeout( | 381 packet_generator_.set_rtt_multiplier_for_fec_timeout( |
380 kFecTimeoutRttMultiplier); | 382 kFecTimeoutRttMultiplier); |
381 } | 383 } |
382 | 384 |
383 if (config.HasClientSentConnectionOption(kMTUH, perspective_)) { | 385 if (config.HasClientSentConnectionOption(kMTUH, perspective_)) { |
384 mtu_discovery_target_ = kMtuDiscoveryTargetPacketSizeHigh; | 386 SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeHigh); |
385 } | 387 } |
386 if (config.HasClientSentConnectionOption(kMTUL, perspective_)) { | 388 if (config.HasClientSentConnectionOption(kMTUL, perspective_)) { |
387 mtu_discovery_target_ = kMtuDiscoveryTargetPacketSizeLow; | 389 SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeLow); |
388 } | 390 } |
389 } | 391 } |
390 | 392 |
391 void QuicConnection::OnSendConnectionState( | 393 void QuicConnection::OnSendConnectionState( |
392 const CachedNetworkParameters& cached_network_params) { | 394 const CachedNetworkParameters& cached_network_params) { |
393 if (debug_visitor_ != nullptr) { | 395 if (debug_visitor_ != nullptr) { |
394 debug_visitor_->OnSendConnectionState(cached_network_params); | 396 debug_visitor_->OnSendConnectionState(cached_network_params); |
395 } | 397 } |
396 } | 398 } |
397 | 399 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 if (!ValidateAckFrame(incoming_ack)) { | 741 if (!ValidateAckFrame(incoming_ack)) { |
740 SendConnectionClose(QUIC_INVALID_ACK_DATA); | 742 SendConnectionClose(QUIC_INVALID_ACK_DATA); |
741 return false; | 743 return false; |
742 } | 744 } |
743 | 745 |
744 if (FLAGS_quic_process_frames_inline) { | 746 if (FLAGS_quic_process_frames_inline) { |
745 ProcessAckFrame(incoming_ack); | 747 ProcessAckFrame(incoming_ack); |
746 if (incoming_ack.is_truncated) { | 748 if (incoming_ack.is_truncated) { |
747 should_last_packet_instigate_acks_ = true; | 749 should_last_packet_instigate_acks_ = true; |
748 } | 750 } |
749 if (!incoming_ack.missing_packets.empty() && | 751 if (!incoming_ack.missing_packets.Empty() && |
750 GetLeastUnacked() > *incoming_ack.missing_packets.begin()) { | 752 GetLeastUnacked() > incoming_ack.missing_packets.Min()) { |
751 ++stop_waiting_count_; | 753 ++stop_waiting_count_; |
752 } else { | 754 } else { |
753 stop_waiting_count_ = 0; | 755 stop_waiting_count_ = 0; |
754 } | 756 } |
755 } else { | 757 } else { |
756 last_ack_frames_.push_back(incoming_ack); | 758 last_ack_frames_.push_back(incoming_ack); |
757 } | 759 } |
758 return connected_; | 760 return connected_; |
759 } | 761 } |
760 | 762 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 826 |
825 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { | 827 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { |
826 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" | 828 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" |
827 << incoming_ack.largest_observed << " vs " | 829 << incoming_ack.largest_observed << " vs " |
828 << sent_packet_manager_.largest_observed(); | 830 << sent_packet_manager_.largest_observed(); |
829 // A new ack has a diminished largest_observed value. Error out. | 831 // A new ack has a diminished largest_observed value. Error out. |
830 // If this was an old packet, we wouldn't even have checked. | 832 // If this was an old packet, we wouldn't even have checked. |
831 return false; | 833 return false; |
832 } | 834 } |
833 | 835 |
834 if (!incoming_ack.missing_packets.empty() && | 836 if (!incoming_ack.missing_packets.Empty() && |
835 *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) { | 837 incoming_ack.missing_packets.Max() > incoming_ack.largest_observed) { |
836 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 838 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
837 << *incoming_ack.missing_packets.rbegin() | 839 << incoming_ack.missing_packets.Max() |
838 << " which is greater than largest observed: " | 840 << " which is greater than largest observed: " |
839 << incoming_ack.largest_observed; | 841 << incoming_ack.largest_observed; |
840 return false; | 842 return false; |
841 } | 843 } |
842 | 844 |
843 if (!incoming_ack.missing_packets.empty() && | 845 if (!incoming_ack.missing_packets.Empty() && |
844 *incoming_ack.missing_packets.begin() < | 846 incoming_ack.missing_packets.Min() < |
845 sent_packet_manager_.least_packet_awaited_by_peer()) { | 847 sent_packet_manager_.least_packet_awaited_by_peer()) { |
846 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 848 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
847 << *incoming_ack.missing_packets.begin() | 849 << incoming_ack.missing_packets.Min() |
848 << " which is smaller than least_packet_awaited_by_peer_: " | 850 << " which is smaller than least_packet_awaited_by_peer_: " |
849 << sent_packet_manager_.least_packet_awaited_by_peer(); | 851 << sent_packet_manager_.least_packet_awaited_by_peer(); |
850 return false; | 852 return false; |
851 } | 853 } |
852 | 854 |
853 if (!sent_entropy_manager_.IsValidEntropy( | 855 if (!sent_entropy_manager_.IsValidEntropy( |
854 incoming_ack.largest_observed, | 856 incoming_ack.largest_observed, |
855 incoming_ack.missing_packets, | 857 incoming_ack.missing_packets, |
856 incoming_ack.entropy_hash)) { | 858 incoming_ack.entropy_hash)) { |
857 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; | 859 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; |
858 return false; | 860 return false; |
859 } | 861 } |
860 | 862 |
861 for (QuicPacketNumber revived_packet : incoming_ack.revived_packets) { | 863 for (QuicPacketNumber revived_packet : incoming_ack.revived_packets) { |
862 if (!ContainsKey(incoming_ack.missing_packets, revived_packet)) { | 864 if (!incoming_ack.missing_packets.Contains(revived_packet)) { |
863 DLOG(ERROR) << ENDPOINT | 865 DLOG(ERROR) << ENDPOINT |
864 << "Peer specified revived packet which was not missing."; | 866 << "Peer specified revived packet which was not missing."; |
865 return false; | 867 return false; |
866 } | 868 } |
867 } | 869 } |
868 return true; | 870 return true; |
869 } | 871 } |
870 | 872 |
871 bool QuicConnection::ValidateStopWaitingFrame( | 873 bool QuicConnection::ValidateStopWaitingFrame( |
872 const QuicStopWaitingFrame& stop_waiting) { | 874 const QuicStopWaitingFrame& stop_waiting) { |
(...skipping 25 matching lines...) Expand all Loading... |
898 group->UpdateFec(last_decrypted_packet_level_, | 900 group->UpdateFec(last_decrypted_packet_level_, |
899 last_header_.packet_packet_number, fec); | 901 last_header_.packet_packet_number, fec); |
900 } | 902 } |
901 } | 903 } |
902 | 904 |
903 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { | 905 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { |
904 DCHECK(connected_); | 906 DCHECK(connected_); |
905 if (debug_visitor_ != nullptr) { | 907 if (debug_visitor_ != nullptr) { |
906 debug_visitor_->OnRstStreamFrame(frame); | 908 debug_visitor_->OnRstStreamFrame(frame); |
907 } | 909 } |
908 DVLOG(1) << ENDPOINT << "Stream reset with error " | 910 DVLOG(1) << ENDPOINT |
| 911 << "RST_STREAM_FRAME received for stream: " << frame.stream_id |
| 912 << " with error: " |
909 << QuicUtils::StreamErrorToString(frame.error_code); | 913 << QuicUtils::StreamErrorToString(frame.error_code); |
910 if (FLAGS_quic_process_frames_inline) { | 914 if (FLAGS_quic_process_frames_inline) { |
911 visitor_->OnRstStream(frame); | 915 visitor_->OnRstStream(frame); |
912 should_last_packet_instigate_acks_ = true; | 916 should_last_packet_instigate_acks_ = true; |
913 } else { | 917 } else { |
914 last_rst_frames_.push_back(frame); | 918 last_rst_frames_.push_back(frame); |
915 } | 919 } |
916 return connected_; | 920 return connected_; |
917 } | 921 } |
918 | 922 |
919 bool QuicConnection::OnConnectionCloseFrame( | 923 bool QuicConnection::OnConnectionCloseFrame( |
920 const QuicConnectionCloseFrame& frame) { | 924 const QuicConnectionCloseFrame& frame) { |
921 DCHECK(connected_); | 925 DCHECK(connected_); |
922 if (debug_visitor_ != nullptr) { | 926 if (debug_visitor_ != nullptr) { |
923 debug_visitor_->OnConnectionCloseFrame(frame); | 927 debug_visitor_->OnConnectionCloseFrame(frame); |
924 } | 928 } |
925 DVLOG(1) << ENDPOINT << "Connection " << connection_id() | 929 DVLOG(1) << ENDPOINT << "CONNECTION_CLOSE_FRAME received for connection: " |
926 << " closed with error " | 930 << connection_id() |
927 << QuicUtils::ErrorToString(frame.error_code) | 931 << " with error: " << QuicUtils::ErrorToString(frame.error_code) |
928 << " " << frame.error_details; | 932 << " " << frame.error_details; |
929 if (FLAGS_quic_process_frames_inline) { | 933 if (FLAGS_quic_process_frames_inline) { |
930 CloseConnection(frame.error_code, true); | 934 CloseConnection(frame.error_code, true); |
931 } else { | 935 } else { |
932 last_close_frames_.push_back(frame); | 936 last_close_frames_.push_back(frame); |
933 } | 937 } |
934 return connected_; | 938 return connected_; |
935 } | 939 } |
936 | 940 |
937 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { | 941 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { |
938 DCHECK(connected_); | 942 DCHECK(connected_); |
939 if (debug_visitor_ != nullptr) { | 943 if (debug_visitor_ != nullptr) { |
940 debug_visitor_->OnGoAwayFrame(frame); | 944 debug_visitor_->OnGoAwayFrame(frame); |
941 } | 945 } |
942 DVLOG(1) << ENDPOINT << "Go away received with error " | 946 DVLOG(1) << ENDPOINT << "GOAWAY_FRAME received with last good stream: " |
943 << QuicUtils::ErrorToString(frame.error_code) | 947 << frame.last_good_stream_id |
944 << " and reason:" << frame.reason_phrase; | 948 << " and error: " << QuicUtils::ErrorToString(frame.error_code) |
| 949 << " and reason: " << frame.reason_phrase; |
945 | 950 |
946 goaway_received_ = true; | 951 goaway_received_ = true; |
947 if (FLAGS_quic_process_frames_inline) { | 952 if (FLAGS_quic_process_frames_inline) { |
948 visitor_->OnGoAway(frame); | 953 visitor_->OnGoAway(frame); |
949 should_last_packet_instigate_acks_ = true; | 954 should_last_packet_instigate_acks_ = true; |
950 } else { | 955 } else { |
951 last_goaway_frames_.push_back(frame); | 956 last_goaway_frames_.push_back(frame); |
952 } | 957 } |
953 return connected_; | 958 return connected_; |
954 } | 959 } |
955 | 960 |
956 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { | 961 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { |
957 DCHECK(connected_); | 962 DCHECK(connected_); |
958 if (debug_visitor_ != nullptr) { | 963 if (debug_visitor_ != nullptr) { |
959 debug_visitor_->OnWindowUpdateFrame(frame); | 964 debug_visitor_->OnWindowUpdateFrame(frame); |
960 } | 965 } |
961 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: " | 966 DVLOG(1) << ENDPOINT |
962 << frame.stream_id << " with byte offset: " << frame.byte_offset; | 967 << "WINDOW_UPDATE_FRAME received for stream: " << frame.stream_id |
| 968 << " with byte offset: " << frame.byte_offset; |
963 if (FLAGS_quic_process_frames_inline) { | 969 if (FLAGS_quic_process_frames_inline) { |
964 visitor_->OnWindowUpdateFrame(frame); | 970 visitor_->OnWindowUpdateFrame(frame); |
965 should_last_packet_instigate_acks_ = true; | 971 should_last_packet_instigate_acks_ = true; |
966 } else { | 972 } else { |
967 last_window_update_frames_.push_back(frame); | 973 last_window_update_frames_.push_back(frame); |
968 } | 974 } |
969 return connected_; | 975 return connected_; |
970 } | 976 } |
971 | 977 |
972 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { | 978 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { |
973 DCHECK(connected_); | 979 DCHECK(connected_); |
974 if (debug_visitor_ != nullptr) { | 980 if (debug_visitor_ != nullptr) { |
975 debug_visitor_->OnBlockedFrame(frame); | 981 debug_visitor_->OnBlockedFrame(frame); |
976 } | 982 } |
977 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: " | 983 DVLOG(1) << ENDPOINT |
978 << frame.stream_id; | 984 << "BLOCKED_FRAME received for stream: " << frame.stream_id; |
979 if (FLAGS_quic_process_frames_inline) { | 985 if (FLAGS_quic_process_frames_inline) { |
980 visitor_->OnBlockedFrame(frame); | 986 visitor_->OnBlockedFrame(frame); |
981 should_last_packet_instigate_acks_ = true; | 987 should_last_packet_instigate_acks_ = true; |
982 } else { | 988 } else { |
983 last_blocked_frames_.push_back(frame); | 989 last_blocked_frames_.push_back(frame); |
984 } | 990 } |
985 return connected_; | 991 return connected_; |
986 } | 992 } |
987 | 993 |
988 void QuicConnection::OnPacketComplete() { | 994 void QuicConnection::OnPacketComplete() { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 return false; | 1190 return false; |
1185 } | 1191 } |
1186 | 1192 |
1187 void QuicConnection::UpdateStopWaitingCount() { | 1193 void QuicConnection::UpdateStopWaitingCount() { |
1188 if (last_ack_frames_.empty()) { | 1194 if (last_ack_frames_.empty()) { |
1189 return; | 1195 return; |
1190 } | 1196 } |
1191 | 1197 |
1192 // If the peer is still waiting for a packet that we are no longer planning to | 1198 // If the peer is still waiting for a packet that we are no longer planning to |
1193 // send, send an ack to raise the high water mark. | 1199 // send, send an ack to raise the high water mark. |
1194 if (!last_ack_frames_.back().missing_packets.empty() && | 1200 if (!last_ack_frames_.back().missing_packets.Empty() && |
1195 GetLeastUnacked() > *last_ack_frames_.back().missing_packets.begin()) { | 1201 GetLeastUnacked() > last_ack_frames_.back().missing_packets.Min()) { |
1196 ++stop_waiting_count_; | 1202 ++stop_waiting_count_; |
1197 } else { | 1203 } else { |
1198 stop_waiting_count_ = 0; | 1204 stop_waiting_count_ = 0; |
1199 } | 1205 } |
1200 } | 1206 } |
1201 | 1207 |
1202 QuicPacketNumber QuicConnection::GetLeastUnacked() const { | 1208 QuicPacketNumber QuicConnection::GetLeastUnacked() const { |
1203 return sent_packet_manager_.GetLeastUnacked(); | 1209 return sent_packet_manager_.GetLeastUnacked(); |
1204 } | 1210 } |
1205 | 1211 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 | 1416 |
1411 // Store in case we want to migrate connection in ProcessValidatedPacket. | 1417 // Store in case we want to migrate connection in ProcessValidatedPacket. |
1412 migrating_peer_ip_ = peer_address.address(); | 1418 migrating_peer_ip_ = peer_address.address(); |
1413 migrating_peer_port_ = peer_address.port(); | 1419 migrating_peer_port_ = peer_address.port(); |
1414 } | 1420 } |
1415 | 1421 |
1416 if (!self_address.address().empty() && !self_address_.address().empty()) { | 1422 if (!self_address.address().empty() && !self_address_.address().empty()) { |
1417 self_ip_changed_ = (self_address.address() != self_address_.address()); | 1423 self_ip_changed_ = (self_address.address() != self_address_.address()); |
1418 self_port_changed_ = (self_address.port() != self_address_.port()); | 1424 self_port_changed_ = (self_address.port() != self_address_.port()); |
1419 } | 1425 } |
| 1426 |
| 1427 // TODO(vasilvv): reset maximum packet size on connection migration. Whenever |
| 1428 // the connection is migrated, it usually ends up being on a different path, |
| 1429 // with possibly smaller MTU. This means the max packet size has to be reset |
| 1430 // and MTU discovery mechanism re-initialized. The main reason the code does |
| 1431 // not do it now is that the retransmission code currently cannot deal with |
| 1432 // the case when it needs to resend a packet created with larger MTU (see |
| 1433 // b/22172803). |
1420 } | 1434 } |
1421 | 1435 |
1422 void QuicConnection::OnCanWrite() { | 1436 void QuicConnection::OnCanWrite() { |
1423 DCHECK(!writer_->IsWriteBlocked()); | 1437 DCHECK(!writer_->IsWriteBlocked()); |
1424 | 1438 |
1425 WriteQueuedPackets(); | 1439 WriteQueuedPackets(); |
1426 WritePendingRetransmissions(); | 1440 WritePendingRetransmissions(); |
1427 | 1441 |
1428 // Sending queued packets may have caused the socket to become write blocked, | 1442 // Sending queued packets may have caused the socket to become write blocked, |
1429 // or the congestion manager to prohibit sending. If we've sent everything | 1443 // or the congestion manager to prohibit sending. If we've sent everything |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 DVLOG(1) << ENDPOINT << "time of last received packet: " | 1498 DVLOG(1) << ENDPOINT << "time of last received packet: " |
1485 << time_of_last_received_packet_.ToDebuggingValue(); | 1499 << time_of_last_received_packet_.ToDebuggingValue(); |
1486 | 1500 |
1487 if (last_size_ > largest_received_packet_size_) { | 1501 if (last_size_ > largest_received_packet_size_) { |
1488 largest_received_packet_size_ = last_size_; | 1502 largest_received_packet_size_ = last_size_; |
1489 } | 1503 } |
1490 | 1504 |
1491 if (perspective_ == Perspective::IS_SERVER && | 1505 if (perspective_ == Perspective::IS_SERVER && |
1492 encryption_level_ == ENCRYPTION_NONE && | 1506 encryption_level_ == ENCRYPTION_NONE && |
1493 last_size_ > packet_generator_.GetMaxPacketLength()) { | 1507 last_size_ > packet_generator_.GetMaxPacketLength()) { |
1494 set_max_packet_length(last_size_); | 1508 SetMaxPacketLength(last_size_); |
1495 } | 1509 } |
1496 return true; | 1510 return true; |
1497 } | 1511 } |
1498 | 1512 |
1499 void QuicConnection::WriteQueuedPackets() { | 1513 void QuicConnection::WriteQueuedPackets() { |
1500 DCHECK(!writer_->IsWriteBlocked()); | 1514 DCHECK(!writer_->IsWriteBlocked()); |
1501 | 1515 |
1502 if (pending_version_negotiation_packet_) { | 1516 if (pending_version_negotiation_packet_) { |
1503 SendVersionNegotiationPacket(); | 1517 SendVersionNegotiationPacket(); |
1504 } | 1518 } |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 group_map_.erase(it); | 2150 group_map_.erase(it); |
2137 delete fec_group; | 2151 delete fec_group; |
2138 it = next; | 2152 it = next; |
2139 } | 2153 } |
2140 } | 2154 } |
2141 | 2155 |
2142 QuicByteCount QuicConnection::max_packet_length() const { | 2156 QuicByteCount QuicConnection::max_packet_length() const { |
2143 return packet_generator_.GetMaxPacketLength(); | 2157 return packet_generator_.GetMaxPacketLength(); |
2144 } | 2158 } |
2145 | 2159 |
2146 void QuicConnection::set_max_packet_length(QuicByteCount length) { | 2160 void QuicConnection::SetMaxPacketLength(QuicByteCount length) { |
2147 return packet_generator_.SetMaxPacketLength(length, /*force=*/false); | 2161 return packet_generator_.SetMaxPacketLength(LimitMaxPacketSize(length), |
| 2162 /*force=*/false); |
2148 } | 2163 } |
2149 | 2164 |
2150 bool QuicConnection::HasQueuedData() const { | 2165 bool QuicConnection::HasQueuedData() const { |
2151 return pending_version_negotiation_packet_ || | 2166 return pending_version_negotiation_packet_ || |
2152 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); | 2167 !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); |
2153 } | 2168 } |
2154 | 2169 |
2155 bool QuicConnection::CanWriteStreamData() { | 2170 bool QuicConnection::CanWriteStreamData() { |
2156 // Don't write stream data if there are negotiation or queued data packets | 2171 // Don't write stream data if there are negotiation or queued data packets |
2157 // to send. Otherwise, continue and bundle as many frames as possible. | 2172 // to send. Otherwise, continue and bundle as many frames as possible. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 return false; | 2382 return false; |
2368 } | 2383 } |
2369 for (const QuicFrame& frame : retransmittable_frames->frames()) { | 2384 for (const QuicFrame& frame : retransmittable_frames->frames()) { |
2370 if (frame.type == CONNECTION_CLOSE_FRAME) { | 2385 if (frame.type == CONNECTION_CLOSE_FRAME) { |
2371 return true; | 2386 return true; |
2372 } | 2387 } |
2373 } | 2388 } |
2374 return false; | 2389 return false; |
2375 } | 2390 } |
2376 | 2391 |
| 2392 void QuicConnection::SetMtuDiscoveryTarget(QuicByteCount target) { |
| 2393 mtu_discovery_target_ = LimitMaxPacketSize(target); |
| 2394 } |
| 2395 |
| 2396 QuicByteCount QuicConnection::LimitMaxPacketSize( |
| 2397 QuicByteCount suggested_max_packet_size) { |
| 2398 if (FLAGS_quic_allow_oversized_packets_for_test) { |
| 2399 return suggested_max_packet_size; |
| 2400 } |
| 2401 |
| 2402 if (!FLAGS_quic_limit_mtu_by_writer) { |
| 2403 return suggested_max_packet_size; |
| 2404 } |
| 2405 |
| 2406 if (peer_address_.address().empty()) { |
| 2407 LOG(DFATAL) << "Attempted to use a connection without a valid peer address"; |
| 2408 return suggested_max_packet_size; |
| 2409 } |
| 2410 |
| 2411 const QuicByteCount writer_limit = writer_->GetMaxPacketSize(peer_address()); |
| 2412 |
| 2413 QuicByteCount max_packet_size = suggested_max_packet_size; |
| 2414 if (max_packet_size > writer_limit) { |
| 2415 max_packet_size = writer_limit; |
| 2416 } |
| 2417 if (max_packet_size > kMaxPacketSize) { |
| 2418 max_packet_size = kMaxPacketSize; |
| 2419 } |
| 2420 return max_packet_size; |
| 2421 } |
| 2422 |
2377 void QuicConnection::SendMtuDiscoveryPacket(QuicByteCount target_mtu) { | 2423 void QuicConnection::SendMtuDiscoveryPacket(QuicByteCount target_mtu) { |
| 2424 // Currently, this limit is ensured by the caller. |
| 2425 DCHECK_EQ(target_mtu, LimitMaxPacketSize(target_mtu)); |
| 2426 |
2378 // Create a listener for the new probe. The ownership of the listener is | 2427 // Create a listener for the new probe. The ownership of the listener is |
2379 // transferred to the AckNotifierManager. The notifier will get destroyed | 2428 // transferred to the AckNotifierManager. The notifier will get destroyed |
2380 // before the connection (because it's stored in one of the connection's | 2429 // before the connection (because it's stored in one of the connection's |
2381 // subfields), hence |this| pointer is guaranteed to stay valid at all times. | 2430 // subfields), hence |this| pointer is guaranteed to stay valid at all times. |
2382 scoped_refptr<MtuDiscoveryAckListener> last_mtu_discovery_ack_listener( | 2431 scoped_refptr<MtuDiscoveryAckListener> last_mtu_discovery_ack_listener( |
2383 new MtuDiscoveryAckListener(this, target_mtu)); | 2432 new MtuDiscoveryAckListener(this, target_mtu)); |
2384 | 2433 |
2385 // Send the probe. | 2434 // Send the probe. |
2386 packet_generator_.GenerateMtuDiscoveryPacket( | 2435 packet_generator_.GenerateMtuDiscoveryPacket( |
2387 target_mtu, last_mtu_discovery_ack_listener.get()); | 2436 target_mtu, last_mtu_discovery_ack_listener.get()); |
(...skipping 16 matching lines...) Expand all Loading... |
2404 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; | 2453 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; |
2405 ++mtu_probe_count_; | 2454 ++mtu_probe_count_; |
2406 | 2455 |
2407 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; | 2456 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; |
2408 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2457 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2409 | 2458 |
2410 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2459 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2411 } | 2460 } |
2412 | 2461 |
2413 } // namespace net | 2462 } // namespace net |
OLD | NEW |