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

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

Issue 2002083002: Add QuicSentPacketManagerInterface, and QuicSentPacketManager implements it. No functional change e… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 16 matching lines...) Expand all
27 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
28 #include "net/quic/crypto/crypto_protocol.h" 28 #include "net/quic/crypto/crypto_protocol.h"
29 #include "net/quic/crypto/quic_decrypter.h" 29 #include "net/quic/crypto/quic_decrypter.h"
30 #include "net/quic/crypto/quic_encrypter.h" 30 #include "net/quic/crypto/quic_encrypter.h"
31 #include "net/quic/proto/cached_network_parameters.pb.h" 31 #include "net/quic/proto/cached_network_parameters.pb.h"
32 #include "net/quic/quic_bandwidth.h" 32 #include "net/quic/quic_bandwidth.h"
33 #include "net/quic/quic_bug_tracker.h" 33 #include "net/quic/quic_bug_tracker.h"
34 #include "net/quic/quic_config.h" 34 #include "net/quic/quic_config.h"
35 #include "net/quic/quic_flags.h" 35 #include "net/quic/quic_flags.h"
36 #include "net/quic/quic_packet_generator.h" 36 #include "net/quic/quic_packet_generator.h"
37 #include "net/quic/quic_sent_packet_manager.h"
37 #include "net/quic/quic_utils.h" 38 #include "net/quic/quic_utils.h"
38 39
39 using base::StringPiece; 40 using base::StringPiece;
40 using base::StringPrintf; 41 using base::StringPrintf;
41 using std::list; 42 using std::list;
42 using std::make_pair; 43 using std::make_pair;
43 using std::max; 44 using std::max;
44 using std::min; 45 using std::min;
45 using std::numeric_limits; 46 using std::numeric_limits;
46 using std::set; 47 using std::set;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 &framer_, 286 &framer_,
286 random_generator_, 287 random_generator_,
287 helper->GetBufferAllocator(), 288 helper->GetBufferAllocator(),
288 this), 289 this),
289 idle_network_timeout_(QuicTime::Delta::Infinite()), 290 idle_network_timeout_(QuicTime::Delta::Infinite()),
290 handshake_timeout_(QuicTime::Delta::Infinite()), 291 handshake_timeout_(QuicTime::Delta::Infinite()),
291 time_of_last_received_packet_(clock_->ApproximateNow()), 292 time_of_last_received_packet_(clock_->ApproximateNow()),
292 time_of_last_sent_new_packet_(clock_->ApproximateNow()), 293 time_of_last_sent_new_packet_(clock_->ApproximateNow()),
293 last_send_for_timeout_(clock_->ApproximateNow()), 294 last_send_for_timeout_(clock_->ApproximateNow()),
294 packet_number_of_last_sent_packet_(0), 295 packet_number_of_last_sent_packet_(0),
295 sent_packet_manager_( 296 sent_packet_manager_(new QuicSentPacketManager(
296 perspective, 297 perspective,
297 kDefaultPathId, 298 kDefaultPathId,
298 clock_, 299 clock_,
299 &stats_, 300 &stats_,
300 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic, 301 FLAGS_quic_use_bbr_congestion_control ? kBBR : kCubic,
301 FLAGS_quic_use_time_loss_detection ? kTime : kNack, 302 FLAGS_quic_use_time_loss_detection ? kTime : kNack,
302 /*delegate=*/nullptr), 303 /*delegate=*/nullptr)),
303 version_negotiation_state_(START_NEGOTIATION), 304 version_negotiation_state_(START_NEGOTIATION),
304 perspective_(perspective), 305 perspective_(perspective),
305 connected_(true), 306 connected_(true),
306 can_truncate_connection_ids_(true), 307 can_truncate_connection_ids_(true),
307 mtu_discovery_target_(0), 308 mtu_discovery_target_(0),
308 mtu_probe_count_(0), 309 mtu_probe_count_(0),
309 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), 310 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase),
310 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), 311 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase),
311 largest_received_packet_size_(0), 312 largest_received_packet_size_(0),
312 goaway_sent_(false), 313 goaway_sent_(false),
313 goaway_received_(false), 314 goaway_received_(false),
314 multipath_enabled_(false) { 315 multipath_enabled_(false) {
315 DVLOG(1) << ENDPOINT 316 DVLOG(1) << ENDPOINT
316 << "Created connection with connection_id: " << connection_id; 317 << "Created connection with connection_id: " << connection_id;
317 framer_.set_visitor(this); 318 framer_.set_visitor(this);
318 framer_.set_received_entropy_calculator(&received_packet_manager_); 319 framer_.set_received_entropy_calculator(&received_packet_manager_);
319 last_stop_waiting_frame_.least_unacked = 0; 320 last_stop_waiting_frame_.least_unacked = 0;
320 stats_.connection_creation_time = clock_->ApproximateNow(); 321 stats_.connection_creation_time = clock_->ApproximateNow();
321 sent_packet_manager_.set_network_change_visitor(this); 322 sent_packet_manager_->SetNetworkChangeVisitor(this);
322 // Allow the packet writer to potentially reduce the packet size to a value 323 // Allow the packet writer to potentially reduce the packet size to a value
323 // even smaller than kDefaultMaxPacketSize. 324 // even smaller than kDefaultMaxPacketSize.
324 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER 325 SetMaxPacketLength(perspective_ == Perspective::IS_SERVER
325 ? kDefaultServerMaxPacketSize 326 ? kDefaultServerMaxPacketSize
326 : kDefaultMaxPacketSize); 327 : kDefaultMaxPacketSize);
327 received_packet_manager_.SetVersion(version()); 328 received_packet_manager_.SetVersion(version());
328 } 329 }
329 330
330 QuicConnection::~QuicConnection() { 331 QuicConnection::~QuicConnection() {
331 if (owns_writer_) { 332 if (owns_writer_) {
(...skipping 24 matching lines...) Expand all
356 ConnectionCloseBehavior::SILENT_CLOSE; 357 ConnectionCloseBehavior::SILENT_CLOSE;
357 } 358 }
358 if (FLAGS_quic_enable_multipath && config.MultipathEnabled()) { 359 if (FLAGS_quic_enable_multipath && config.MultipathEnabled()) {
359 multipath_enabled_ = true; 360 multipath_enabled_ = true;
360 } 361 }
361 } else { 362 } else {
362 SetNetworkTimeouts(config.max_time_before_crypto_handshake(), 363 SetNetworkTimeouts(config.max_time_before_crypto_handshake(),
363 config.max_idle_time_before_crypto_handshake()); 364 config.max_idle_time_before_crypto_handshake());
364 } 365 }
365 366
366 sent_packet_manager_.SetFromConfig(config); 367 sent_packet_manager_->SetFromConfig(config);
367 if (config.HasReceivedBytesForConnectionId() && 368 if (config.HasReceivedBytesForConnectionId() &&
368 can_truncate_connection_ids_) { 369 can_truncate_connection_ids_) {
369 packet_generator_.SetConnectionIdLength( 370 packet_generator_.SetConnectionIdLength(
370 config.ReceivedBytesForConnectionId()); 371 config.ReceivedBytesForConnectionId());
371 } 372 }
372 max_undecryptable_packets_ = config.max_undecryptable_packets(); 373 max_undecryptable_packets_ = config.max_undecryptable_packets();
373 374
374 if (config.HasClientSentConnectionOption(kMTUH, perspective_)) { 375 if (config.HasClientSentConnectionOption(kMTUH, perspective_)) {
375 SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeHigh); 376 SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeHigh);
376 } 377 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 void QuicConnection::OnReceiveConnectionState( 410 void QuicConnection::OnReceiveConnectionState(
410 const CachedNetworkParameters& cached_network_params) { 411 const CachedNetworkParameters& cached_network_params) {
411 if (debug_visitor_ != nullptr) { 412 if (debug_visitor_ != nullptr) {
412 debug_visitor_->OnReceiveConnectionState(cached_network_params); 413 debug_visitor_->OnReceiveConnectionState(cached_network_params);
413 } 414 }
414 } 415 }
415 416
416 void QuicConnection::ResumeConnectionState( 417 void QuicConnection::ResumeConnectionState(
417 const CachedNetworkParameters& cached_network_params, 418 const CachedNetworkParameters& cached_network_params,
418 bool max_bandwidth_resumption) { 419 bool max_bandwidth_resumption) {
419 sent_packet_manager_.ResumeConnectionState(cached_network_params, 420 sent_packet_manager_->ResumeConnectionState(cached_network_params,
420 max_bandwidth_resumption); 421 max_bandwidth_resumption);
421 } 422 }
422 423
423 void QuicConnection::SetMaxPacingRate(QuicBandwidth max_pacing_rate) { 424 void QuicConnection::SetMaxPacingRate(QuicBandwidth max_pacing_rate) {
424 sent_packet_manager_.SetMaxPacingRate(max_pacing_rate); 425 sent_packet_manager_->SetMaxPacingRate(max_pacing_rate);
425 } 426 }
426 427
427 void QuicConnection::SetNumOpenStreams(size_t num_streams) { 428 void QuicConnection::SetNumOpenStreams(size_t num_streams) {
428 sent_packet_manager_.SetNumOpenStreams(num_streams); 429 sent_packet_manager_->SetNumOpenStreams(num_streams);
429 } 430 }
430 431
431 bool QuicConnection::SelectMutualVersion( 432 bool QuicConnection::SelectMutualVersion(
432 const QuicVersionVector& available_versions) { 433 const QuicVersionVector& available_versions) {
433 // Try to find the highest mutual version by iterating over supported 434 // Try to find the highest mutual version by iterating over supported
434 // versions, starting with the highest, and breaking out of the loop once we 435 // versions, starting with the highest, and breaking out of the loop once we
435 // find a matching version in the provided available_versions vector. 436 // find a matching version in the provided available_versions vector.
436 const QuicVersionVector& supported_versions = framer_.supported_versions(); 437 const QuicVersionVector& supported_versions = framer_.supported_versions();
437 for (size_t i = 0; i < supported_versions.size(); ++i) { 438 for (size_t i = 0; i < supported_versions.size(); ++i) {
438 const QuicVersion& version = supported_versions[i]; 439 const QuicVersion& version = supported_versions[i];
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 if (!ProcessValidatedPacket(header)) { 668 if (!ProcessValidatedPacket(header)) {
668 return false; 669 return false;
669 } 670 }
670 671
671 // Only migrate connection to a new peer address if a change is not underway. 672 // Only migrate connection to a new peer address if a change is not underway.
672 PeerAddressChangeType peer_migration_type = 673 PeerAddressChangeType peer_migration_type =
673 QuicUtils::DetermineAddressChangeType(peer_address_, 674 QuicUtils::DetermineAddressChangeType(peer_address_,
674 last_packet_source_address_); 675 last_packet_source_address_);
675 if (active_peer_migration_type_ == NO_CHANGE && 676 if (active_peer_migration_type_ == NO_CHANGE &&
676 peer_migration_type != NO_CHANGE) { 677 peer_migration_type != NO_CHANGE) {
677 StartPeerMigration(peer_migration_type); 678 StartPeerMigration(header.path_id, peer_migration_type);
678 } 679 }
679 680
680 --stats_.packets_dropped; 681 --stats_.packets_dropped;
681 DVLOG(1) << ENDPOINT << "Received packet header: " << header; 682 DVLOG(1) << ENDPOINT << "Received packet header: " << header;
682 last_header_ = header; 683 last_header_ = header;
683 DCHECK(connected_); 684 DCHECK(connected_);
684 return true; 685 return true;
685 } 686 }
686 687
687 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { 688 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 if (incoming_ack.is_truncated) { 743 if (incoming_ack.is_truncated) {
743 should_last_packet_instigate_acks_ = true; 744 should_last_packet_instigate_acks_ = true;
744 } 745 }
745 // If the incoming ack's packets set expresses missing packets: peer is still 746 // If the incoming ack's packets set expresses missing packets: peer is still
746 // waiting for a packet lower than a packet that we are no longer planning to 747 // waiting for a packet lower than a packet that we are no longer planning to
747 // send. 748 // send.
748 // If the incoming ack's packets set expresses received packets: peer is still 749 // If the incoming ack's packets set expresses received packets: peer is still
749 // acking packets which we never care about. 750 // acking packets which we never care about.
750 // Send an ack to raise the high water mark. 751 // Send an ack to raise the high water mark.
751 if (!incoming_ack.packets.Empty() && 752 if (!incoming_ack.packets.Empty() &&
752 GetLeastUnacked() > incoming_ack.packets.Min()) { 753 GetLeastUnacked(incoming_ack.path_id) > incoming_ack.packets.Min()) {
753 ++stop_waiting_count_; 754 ++stop_waiting_count_;
754 } else { 755 } else {
755 stop_waiting_count_ = 0; 756 stop_waiting_count_ = 0;
756 } 757 }
757 758
758 return connected_; 759 return connected_;
759 } 760 }
760 761
761 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { 762 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) {
762 largest_seen_packet_with_ack_ = last_header_.packet_number; 763 largest_seen_packet_with_ack_ = last_header_.packet_number;
763 sent_packet_manager_.OnIncomingAck(incoming_ack, 764 sent_packet_manager_->OnIncomingAck(incoming_ack,
764 time_of_last_received_packet_); 765 time_of_last_received_packet_);
765 if (version() <= QUIC_VERSION_33) { 766 if (version() <= QUIC_VERSION_33) {
766 sent_entropy_manager_.ClearEntropyBefore( 767 sent_entropy_manager_.ClearEntropyBefore(
767 sent_packet_manager_.least_packet_awaited_by_peer() - 1); 768 sent_packet_manager_->GetLeastPacketAwaitedByPeer(
769 incoming_ack.path_id) -
770 1);
768 } 771 }
769 // Always reset the retransmission alarm when an ack comes in, since we now 772 // Always reset the retransmission alarm when an ack comes in, since we now
770 // have a better estimate of the current rtt than when it was set. 773 // have a better estimate of the current rtt than when it was set.
771 SetRetransmissionAlarm(); 774 SetRetransmissionAlarm();
772 } 775 }
773 776
774 void QuicConnection::ProcessStopWaitingFrame( 777 void QuicConnection::ProcessStopWaitingFrame(
775 const QuicStopWaitingFrame& stop_waiting) { 778 const QuicStopWaitingFrame& stop_waiting) {
776 largest_seen_packet_with_stop_waiting_ = last_header_.packet_number; 779 largest_seen_packet_with_stop_waiting_ = last_header_.packet_number;
777 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); 780 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 822
820 const char* QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { 823 const char* QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) {
821 if (incoming_ack.largest_observed > packet_generator_.packet_number()) { 824 if (incoming_ack.largest_observed > packet_generator_.packet_number()) {
822 LOG(WARNING) << ENDPOINT << "Peer's observed unsent packet:" 825 LOG(WARNING) << ENDPOINT << "Peer's observed unsent packet:"
823 << incoming_ack.largest_observed << " vs " 826 << incoming_ack.largest_observed << " vs "
824 << packet_generator_.packet_number(); 827 << packet_generator_.packet_number();
825 // We got an error for data we have not sent. Error out. 828 // We got an error for data we have not sent. Error out.
826 return "Largest observed too high."; 829 return "Largest observed too high.";
827 } 830 }
828 831
829 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { 832 if (incoming_ack.largest_observed <
833 sent_packet_manager_->GetLargestObserved(incoming_ack.path_id)) {
830 LOG(WARNING) << ENDPOINT << "Peer's largest_observed packet decreased:" 834 LOG(WARNING) << ENDPOINT << "Peer's largest_observed packet decreased:"
831 << incoming_ack.largest_observed << " vs " 835 << incoming_ack.largest_observed << " vs "
832 << sent_packet_manager_.largest_observed() 836 << sent_packet_manager_->GetLargestObserved(
837 incoming_ack.path_id)
833 << " packet_number:" << last_header_.packet_number 838 << " packet_number:" << last_header_.packet_number
834 << " largest seen with ack:" << largest_seen_packet_with_ack_ 839 << " largest seen with ack:" << largest_seen_packet_with_ack_
835 << " connection_id: " << connection_id_; 840 << " connection_id: " << connection_id_;
836 // A new ack has a diminished largest_observed value. Error out. 841 // A new ack has a diminished largest_observed value. Error out.
837 // If this was an old packet, we wouldn't even have checked. 842 // If this was an old packet, we wouldn't even have checked.
838 return "Largest observed too low."; 843 return "Largest observed too low.";
839 } 844 }
840 845
841 if (version() <= QUIC_VERSION_33) { 846 if (version() <= QUIC_VERSION_33) {
842 if (!incoming_ack.packets.Empty() && 847 if (!incoming_ack.packets.Empty() &&
843 incoming_ack.packets.Max() > incoming_ack.largest_observed) { 848 incoming_ack.packets.Max() > incoming_ack.largest_observed) {
844 LOG(WARNING) << ENDPOINT 849 LOG(WARNING) << ENDPOINT
845 << "Peer sent missing packet: " << incoming_ack.packets.Max() 850 << "Peer sent missing packet: " << incoming_ack.packets.Max()
846 << " which is greater than largest observed: " 851 << " which is greater than largest observed: "
847 << incoming_ack.largest_observed; 852 << incoming_ack.largest_observed;
848 return "Missing packet higher than largest observed."; 853 return "Missing packet higher than largest observed.";
849 } 854 }
850 855
851 if (!incoming_ack.packets.Empty() && 856 if (!incoming_ack.packets.Empty() &&
852 incoming_ack.packets.Min() < 857 incoming_ack.packets.Min() <
853 sent_packet_manager_.least_packet_awaited_by_peer()) { 858 sent_packet_manager_->GetLeastPacketAwaitedByPeer(
859 incoming_ack.path_id)) {
854 LOG(WARNING) << ENDPOINT 860 LOG(WARNING) << ENDPOINT
855 << "Peer sent missing packet: " << incoming_ack.packets.Min() 861 << "Peer sent missing packet: " << incoming_ack.packets.Min()
856 << " which is smaller than least_packet_awaited_by_peer_: " 862 << " which is smaller than least_packet_awaited_by_peer_: "
857 << sent_packet_manager_.least_packet_awaited_by_peer(); 863 << sent_packet_manager_->GetLeastPacketAwaitedByPeer(
864 incoming_ack.path_id);
858 return "Missing packet smaller than least awaited."; 865 return "Missing packet smaller than least awaited.";
859 } 866 }
860 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed, 867 if (!sent_entropy_manager_.IsValidEntropy(incoming_ack.largest_observed,
861 incoming_ack.packets, 868 incoming_ack.packets,
862 incoming_ack.entropy_hash)) { 869 incoming_ack.entropy_hash)) {
863 LOG(WARNING) << ENDPOINT << "Peer sent invalid entropy." 870 LOG(WARNING) << ENDPOINT << "Peer sent invalid entropy."
864 << " largest_observed:" << incoming_ack.largest_observed 871 << " largest_observed:" << incoming_ack.largest_observed
865 << " last_received:" << last_header_.packet_number; 872 << " last_received:" << last_header_.packet_number;
866 return "Invalid entropy."; 873 return "Invalid entropy.";
867 } 874 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 ++num_retransmittable_packets_received_since_last_ack_sent_; 1051 ++num_retransmittable_packets_received_since_last_ack_sent_;
1045 if (ack_mode_ != TCP_ACKING && 1052 if (ack_mode_ != TCP_ACKING &&
1046 last_header_.packet_number > kMinReceivedBeforeAckDecimation) { 1053 last_header_.packet_number > kMinReceivedBeforeAckDecimation) {
1047 // Ack up to 10 packets at once. 1054 // Ack up to 10 packets at once.
1048 if (num_retransmittable_packets_received_since_last_ack_sent_ >= 1055 if (num_retransmittable_packets_received_since_last_ack_sent_ >=
1049 kMaxRetransmittablePacketsBeforeAck) { 1056 kMaxRetransmittablePacketsBeforeAck) {
1050 ack_queued_ = true; 1057 ack_queued_ = true;
1051 } else if (!ack_alarm_->IsSet()) { 1058 } else if (!ack_alarm_->IsSet()) {
1052 // Wait the minimum of a quarter min_rtt and the delayed ack time. 1059 // Wait the minimum of a quarter min_rtt and the delayed ack time.
1053 QuicTime::Delta ack_delay = QuicTime::Delta::Min( 1060 QuicTime::Delta ack_delay = QuicTime::Delta::Min(
1054 sent_packet_manager_.DelayedAckTime(), 1061 DelayedAckTime(),
1055 sent_packet_manager_.GetRttStats()->min_rtt().Multiply( 1062 sent_packet_manager_->GetRttStats()->min_rtt().Multiply(
1056 ack_decimation_delay_)); 1063 ack_decimation_delay_));
1057 ack_alarm_->Set(clock_->ApproximateNow().Add(ack_delay)); 1064 ack_alarm_->Set(clock_->ApproximateNow().Add(ack_delay));
1058 } 1065 }
1059 } else { 1066 } else {
1060 // Ack with a timer or every 2 packets by default. 1067 // Ack with a timer or every 2 packets by default.
1061 if (num_retransmittable_packets_received_since_last_ack_sent_ >= 1068 if (num_retransmittable_packets_received_since_last_ack_sent_ >=
1062 kDefaultRetransmittablePacketsBeforeAck) { 1069 kDefaultRetransmittablePacketsBeforeAck) {
1063 ack_queued_ = true; 1070 ack_queued_ = true;
1064 } else if (!ack_alarm_->IsSet()) { 1071 } else if (!ack_alarm_->IsSet()) {
1065 ack_alarm_->Set(clock_->ApproximateNow().Add( 1072 ack_alarm_->Set(clock_->ApproximateNow().Add(DelayedAckTime()));
1066 sent_packet_manager_.DelayedAckTime()));
1067 } 1073 }
1068 } 1074 }
1069 1075
1070 // If there are new missing packets to report, send an ack immediately. 1076 // If there are new missing packets to report, send an ack immediately.
1071 if (received_packet_manager_.HasNewMissingPackets()) { 1077 if (received_packet_manager_.HasNewMissingPackets()) {
1072 if (ack_mode_ == ACK_DECIMATION_WITH_REORDERING) { 1078 if (ack_mode_ == ACK_DECIMATION_WITH_REORDERING) {
1073 // Wait the minimum of an eighth min_rtt and the existing ack time. 1079 // Wait the minimum of an eighth min_rtt and the existing ack time.
1074 QuicTime ack_time = clock_->ApproximateNow().Add( 1080 QuicTime ack_time = clock_->ApproximateNow().Add(
1075 sent_packet_manager_.GetRttStats()->min_rtt().Multiply(0.125)); 1081 sent_packet_manager_->GetRttStats()->min_rtt().Multiply(0.125));
1076 if (!ack_alarm_->IsSet() || ack_alarm_->deadline() > ack_time) { 1082 if (!ack_alarm_->IsSet() || ack_alarm_->deadline() > ack_time) {
1077 ack_alarm_->Cancel(); 1083 ack_alarm_->Cancel();
1078 ack_alarm_->Set(ack_time); 1084 ack_alarm_->Set(ack_time);
1079 } 1085 }
1080 } else { 1086 } else {
1081 ack_queued_ = true; 1087 ack_queued_ = true;
1082 } 1088 }
1083 } 1089 }
1084 } 1090 }
1085 1091
1086 if (ack_queued_) { 1092 if (ack_queued_) {
1087 ack_alarm_->Cancel(); 1093 ack_alarm_->Cancel();
1088 } 1094 }
1089 } 1095 }
1090 1096
1091 void QuicConnection::ClearLastFrames() { 1097 void QuicConnection::ClearLastFrames() {
1092 should_last_packet_instigate_acks_ = false; 1098 should_last_packet_instigate_acks_ = false;
1093 last_stop_waiting_frame_.least_unacked = 0; 1099 last_stop_waiting_frame_.least_unacked = 0;
1094 } 1100 }
1095 1101
1096 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() { 1102 void QuicConnection::MaybeCloseIfTooManyOutstandingPackets() {
1097 if (version() > QUIC_VERSION_33) { 1103 if (version() > QUIC_VERSION_33) {
1098 return; 1104 return;
1099 } 1105 }
1100 // This occurs if we don't discard old packets we've sent fast enough. 1106 // This occurs if we don't discard old packets we've sent fast enough.
1101 // It's possible largest observed is less than least unacked. 1107 // It's possible largest observed is less than least unacked.
1102 if (sent_packet_manager_.largest_observed() > 1108 if (sent_packet_manager_->GetLargestObserved(last_header_.path_id) >
1103 (sent_packet_manager_.GetLeastUnacked() + kMaxTrackedPackets)) { 1109 (sent_packet_manager_->GetLeastUnacked(last_header_.path_id) +
1110 kMaxTrackedPackets)) {
1104 CloseConnection( 1111 CloseConnection(
1105 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, 1112 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS,
1106 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets), 1113 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets),
1107 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 1114 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
1108 } 1115 }
1109 // This occurs if there are received packet gaps and the peer does not raise 1116 // This occurs if there are received packet gaps and the peer does not raise
1110 // the least unacked fast enough. 1117 // the least unacked fast enough.
1111 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) { 1118 if (received_packet_manager_.NumTrackedPackets() > kMaxTrackedPackets) {
1112 CloseConnection( 1119 CloseConnection(
1113 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, 1120 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS,
1114 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets), 1121 StringPrintf("More than %" PRIu64 " outstanding.", kMaxTrackedPackets),
1115 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 1122 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
1116 } 1123 }
1117 } 1124 }
1118 1125
1119 const QuicFrame QuicConnection::GetUpdatedAckFrame() { 1126 const QuicFrame QuicConnection::GetUpdatedAckFrame() {
1120 return received_packet_manager_.GetUpdatedAckFrame(clock_->ApproximateNow()); 1127 return received_packet_manager_.GetUpdatedAckFrame(clock_->ApproximateNow());
1121 } 1128 }
1122 1129
1123 void QuicConnection::PopulateStopWaitingFrame( 1130 void QuicConnection::PopulateStopWaitingFrame(
1124 QuicStopWaitingFrame* stop_waiting) { 1131 QuicStopWaitingFrame* stop_waiting) {
1125 stop_waiting->least_unacked = GetLeastUnacked(); 1132 stop_waiting->least_unacked = GetLeastUnacked(stop_waiting->path_id);
1126 if (version() <= QUIC_VERSION_33) { 1133 if (version() <= QUIC_VERSION_33) {
1127 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy( 1134 stop_waiting->entropy_hash = sent_entropy_manager_.GetCumulativeEntropy(
1128 stop_waiting->least_unacked - 1); 1135 stop_waiting->least_unacked - 1);
1129 } 1136 }
1130 } 1137 }
1131 1138
1132 QuicPacketNumber QuicConnection::GetLeastUnacked() const { 1139 QuicPacketNumber QuicConnection::GetLeastUnacked(QuicPathId path_id) const {
1133 return sent_packet_manager_.GetLeastUnacked(); 1140 return sent_packet_manager_->GetLeastUnacked(path_id);
1134 } 1141 }
1135 1142
1136 void QuicConnection::MaybeSendInResponseToPacket() { 1143 void QuicConnection::MaybeSendInResponseToPacket() {
1137 if (!connected_) { 1144 if (!connected_) {
1138 return; 1145 return;
1139 } 1146 }
1140 // Now that we have received an ack, we might be able to send packets which 1147 // Now that we have received an ack, we might be able to send packets which
1141 // are queued locally, or drain streams which are blocked. 1148 // are queued locally, or drain streams which are blocked.
1142 if (defer_send_in_response_to_packets_) { 1149 if (defer_send_in_response_to_packets_) {
1143 send_alarm_->Cancel(); 1150 send_alarm_->Cancel();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); 1221 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING);
1215 packet_generator_.AddControlFrame(QuicFrame(new QuicRstStreamFrame( 1222 packet_generator_.AddControlFrame(QuicFrame(new QuicRstStreamFrame(
1216 id, AdjustErrorForVersion(error, version()), bytes_written))); 1223 id, AdjustErrorForVersion(error, version()), bytes_written)));
1217 1224
1218 if (error == QUIC_STREAM_NO_ERROR && version() > QUIC_VERSION_28) { 1225 if (error == QUIC_STREAM_NO_ERROR && version() > QUIC_VERSION_28) {
1219 // All data for streams which are reset with QUIC_STREAM_NO_ERROR must 1226 // All data for streams which are reset with QUIC_STREAM_NO_ERROR must
1220 // be received by the peer. 1227 // be received by the peer.
1221 return; 1228 return;
1222 } 1229 }
1223 1230
1224 sent_packet_manager_.CancelRetransmissionsForStream(id); 1231 sent_packet_manager_->CancelRetransmissionsForStream(id);
1225 // Remove all queued packets which only contain data for the reset stream. 1232 // Remove all queued packets which only contain data for the reset stream.
1226 QueuedPacketList::iterator packet_iterator = queued_packets_.begin(); 1233 QueuedPacketList::iterator packet_iterator = queued_packets_.begin();
1227 while (packet_iterator != queued_packets_.end()) { 1234 while (packet_iterator != queued_packets_.end()) {
1228 QuicFrames* retransmittable_frames = 1235 QuicFrames* retransmittable_frames =
1229 &packet_iterator->retransmittable_frames; 1236 &packet_iterator->retransmittable_frames;
1230 if (retransmittable_frames->empty()) { 1237 if (retransmittable_frames->empty()) {
1231 ++packet_iterator; 1238 ++packet_iterator;
1232 continue; 1239 continue;
1233 } 1240 }
1234 QuicUtils::RemoveFramesForStream(retransmittable_frames, id); 1241 QuicUtils::RemoveFramesForStream(retransmittable_frames, id);
(...skipping 22 matching lines...) Expand all
1257 } 1264 }
1258 1265
1259 void QuicConnection::SendPathClose(QuicPathId path_id) { 1266 void QuicConnection::SendPathClose(QuicPathId path_id) {
1260 // Opportunistically bundle an ack with this outgoing packet. 1267 // Opportunistically bundle an ack with this outgoing packet.
1261 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING); 1268 ScopedPacketBundler ack_bundler(this, SEND_ACK_IF_PENDING);
1262 packet_generator_.AddControlFrame(QuicFrame(new QuicPathCloseFrame(path_id))); 1269 packet_generator_.AddControlFrame(QuicFrame(new QuicPathCloseFrame(path_id)));
1263 OnPathClosed(path_id); 1270 OnPathClosed(path_id);
1264 } 1271 }
1265 1272
1266 const QuicConnectionStats& QuicConnection::GetStats() { 1273 const QuicConnectionStats& QuicConnection::GetStats() {
1267 const RttStats* rtt_stats = sent_packet_manager_.GetRttStats(); 1274 const RttStats* rtt_stats = sent_packet_manager_->GetRttStats();
1268 1275
1269 // Update rtt and estimated bandwidth. 1276 // Update rtt and estimated bandwidth.
1270 QuicTime::Delta min_rtt = rtt_stats->min_rtt(); 1277 QuicTime::Delta min_rtt = rtt_stats->min_rtt();
1271 if (min_rtt.IsZero()) { 1278 if (min_rtt.IsZero()) {
1272 // If min RTT has not been set, use initial RTT instead. 1279 // If min RTT has not been set, use initial RTT instead.
1273 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); 1280 min_rtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us());
1274 } 1281 }
1275 stats_.min_rtt_us = min_rtt.ToMicroseconds(); 1282 stats_.min_rtt_us = min_rtt.ToMicroseconds();
1276 1283
1277 QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); 1284 QuicTime::Delta srtt = rtt_stats->smoothed_rtt();
1278 if (srtt.IsZero()) { 1285 if (srtt.IsZero()) {
1279 // If SRTT has not been set, use initial RTT instead. 1286 // If SRTT has not been set, use initial RTT instead.
1280 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us()); 1287 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us());
1281 } 1288 }
1282 stats_.srtt_us = srtt.ToMicroseconds(); 1289 stats_.srtt_us = srtt.ToMicroseconds();
1283 1290
1284 stats_.estimated_bandwidth = sent_packet_manager_.BandwidthEstimate(); 1291 stats_.estimated_bandwidth = sent_packet_manager_->BandwidthEstimate();
1285 stats_.max_packet_size = packet_generator_.GetCurrentMaxPacketLength(); 1292 stats_.max_packet_size = packet_generator_.GetCurrentMaxPacketLength();
1286 stats_.max_received_packet_size = largest_received_packet_size_; 1293 stats_.max_received_packet_size = largest_received_packet_size_;
1287 return stats_; 1294 return stats_;
1288 } 1295 }
1289 1296
1290 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, 1297 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
1291 const IPEndPoint& peer_address, 1298 const IPEndPoint& peer_address,
1292 const QuicReceivedPacket& packet) { 1299 const QuicReceivedPacket& packet) {
1293 if (!connected_) { 1300 if (!connected_) {
1294 return; 1301 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 } 1335 }
1329 } 1336 }
1330 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " 1337 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: "
1331 << last_header_.packet_number; 1338 << last_header_.packet_number;
1332 current_packet_data_ = nullptr; 1339 current_packet_data_ = nullptr;
1333 return; 1340 return;
1334 } 1341 }
1335 1342
1336 ++stats_.packets_processed; 1343 ++stats_.packets_processed;
1337 if (active_peer_migration_type_ != NO_CHANGE && 1344 if (active_peer_migration_type_ != NO_CHANGE &&
1338 sent_packet_manager_.largest_observed() > 1345 sent_packet_manager_->GetLargestObserved(last_header_.path_id) >
1339 highest_packet_sent_before_peer_migration_) { 1346 highest_packet_sent_before_peer_migration_) {
1340 OnPeerMigrationValidated(); 1347 OnPeerMigrationValidated(last_header_.path_id);
1341 } 1348 }
1342 MaybeProcessUndecryptablePackets(); 1349 MaybeProcessUndecryptablePackets();
1343 MaybeSendInResponseToPacket(); 1350 MaybeSendInResponseToPacket();
1344 SetPingAlarm(); 1351 SetPingAlarm();
1345 current_packet_data_ = nullptr; 1352 current_packet_data_ = nullptr;
1346 } 1353 }
1347 1354
1348 void QuicConnection::OnCanWrite() { 1355 void QuicConnection::OnCanWrite() {
1349 DCHECK(!writer_->IsWriteBlocked()); 1356 DCHECK(!writer_->IsWriteBlocked());
1350 1357
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 WritePacket(&(*packet_iterator))) { 1487 WritePacket(&(*packet_iterator))) {
1481 delete[] packet_iterator->encrypted_buffer; 1488 delete[] packet_iterator->encrypted_buffer;
1482 QuicUtils::ClearSerializedPacket(&(*packet_iterator)); 1489 QuicUtils::ClearSerializedPacket(&(*packet_iterator));
1483 packet_iterator = queued_packets_.erase(packet_iterator); 1490 packet_iterator = queued_packets_.erase(packet_iterator);
1484 } 1491 }
1485 } 1492 }
1486 1493
1487 void QuicConnection::WritePendingRetransmissions() { 1494 void QuicConnection::WritePendingRetransmissions() {
1488 // Keep writing as long as there's a pending retransmission which can be 1495 // Keep writing as long as there's a pending retransmission which can be
1489 // written. 1496 // written.
1490 while (sent_packet_manager_.HasPendingRetransmissions()) { 1497 while (sent_packet_manager_->HasPendingRetransmissions()) {
1491 const PendingRetransmission pending = 1498 const PendingRetransmission pending =
1492 sent_packet_manager_.NextPendingRetransmission(); 1499 sent_packet_manager_->NextPendingRetransmission();
1493 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) { 1500 if (!CanWrite(HAS_RETRANSMITTABLE_DATA)) {
1494 break; 1501 break;
1495 } 1502 }
1496 1503
1497 // Re-packetize the frames with a new packet number for retransmission. 1504 // Re-packetize the frames with a new packet number for retransmission.
1498 // Retransmitted packets use the same packet number length as the 1505 // Retransmitted packets use the same packet number length as the
1499 // original. 1506 // original.
1500 // Flush the packet generator before making a new packet. 1507 // Flush the packet generator before making a new packet.
1501 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that 1508 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that
1502 // does not require the creator to be flushed. 1509 // does not require the creator to be flushed.
1503 packet_generator_.FlushAllQueuedFrames(); 1510 packet_generator_.FlushAllQueuedFrames();
1504 char buffer[kMaxPacketSize]; 1511 char buffer[kMaxPacketSize];
1505 packet_generator_.ReserializeAllFrames(pending, buffer, kMaxPacketSize); 1512 packet_generator_.ReserializeAllFrames(pending, buffer, kMaxPacketSize);
1506 } 1513 }
1507 } 1514 }
1508 1515
1509 void QuicConnection::RetransmitUnackedPackets( 1516 void QuicConnection::RetransmitUnackedPackets(
1510 TransmissionType retransmission_type) { 1517 TransmissionType retransmission_type) {
1511 sent_packet_manager_.RetransmitUnackedPackets(retransmission_type); 1518 sent_packet_manager_->RetransmitUnackedPackets(retransmission_type);
1512 1519
1513 WriteIfNotBlocked(); 1520 WriteIfNotBlocked();
1514 } 1521 }
1515 1522
1516 void QuicConnection::NeuterUnencryptedPackets() { 1523 void QuicConnection::NeuterUnencryptedPackets() {
1517 sent_packet_manager_.NeuterUnencryptedPackets(); 1524 sent_packet_manager_->NeuterUnencryptedPackets();
1518 // This may have changed the retransmission timer, so re-arm it. 1525 // This may have changed the retransmission timer, so re-arm it.
1519 SetRetransmissionAlarm(); 1526 SetRetransmissionAlarm();
1520 } 1527 }
1521 1528
1522 bool QuicConnection::ShouldGeneratePacket( 1529 bool QuicConnection::ShouldGeneratePacket(
1523 HasRetransmittableData retransmittable, 1530 HasRetransmittableData retransmittable,
1524 IsHandshake handshake) { 1531 IsHandshake handshake) {
1525 // We should serialize handshake packets immediately to ensure that they 1532 // We should serialize handshake packets immediately to ensure that they
1526 // end up sent at the right encryption level. 1533 // end up sent at the right encryption level.
1527 if (handshake == IS_HANDSHAKE) { 1534 if (handshake == IS_HANDSHAKE) {
(...skipping 17 matching lines...) Expand all
1545 // TODO(ianswett): Remove retransmittable from 1552 // TODO(ianswett): Remove retransmittable from
1546 // SendAlgorithmInterface::TimeUntilSend. 1553 // SendAlgorithmInterface::TimeUntilSend.
1547 if (retransmittable == NO_RETRANSMITTABLE_DATA) { 1554 if (retransmittable == NO_RETRANSMITTABLE_DATA) {
1548 return true; 1555 return true;
1549 } 1556 }
1550 // If the send alarm is set, wait for it to fire. 1557 // If the send alarm is set, wait for it to fire.
1551 if (send_alarm_->IsSet()) { 1558 if (send_alarm_->IsSet()) {
1552 return false; 1559 return false;
1553 } 1560 }
1554 1561
1562 // TODO(fayang): If delay is not infinite, the next packet will be created and
1563 // sent on path_id.
1564 QuicPathId path_id = kInvalidPathId;
1555 QuicTime now = clock_->Now(); 1565 QuicTime now = clock_->Now();
1556 QuicTime::Delta delay = 1566 QuicTime::Delta delay =
1557 sent_packet_manager_.TimeUntilSend(now, retransmittable); 1567 sent_packet_manager_->TimeUntilSend(now, retransmittable, &path_id);
1558 if (delay.IsInfinite()) { 1568 if (delay.IsInfinite()) {
1569 DCHECK_EQ(kInvalidPathId, path_id);
1559 send_alarm_->Cancel(); 1570 send_alarm_->Cancel();
1560 return false; 1571 return false;
1561 } 1572 }
1562 1573
1574 DCHECK_NE(kInvalidPathId, path_id);
1563 // If the scheduler requires a delay, then we can not send this packet now. 1575 // If the scheduler requires a delay, then we can not send this packet now.
1564 if (!delay.IsZero()) { 1576 if (!delay.IsZero()) {
1565 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1)); 1577 send_alarm_->Update(now.Add(delay), QuicTime::Delta::FromMilliseconds(1));
1566 DVLOG(1) << ENDPOINT << "Delaying sending " << delay.ToMilliseconds() 1578 DVLOG(1) << ENDPOINT << "Delaying sending " << delay.ToMilliseconds()
1567 << "ms"; 1579 << "ms";
1568 return false; 1580 return false;
1569 } 1581 }
1570 return true; 1582 return true;
1571 } 1583 }
1572 1584
1573 bool QuicConnection::WritePacket(SerializedPacket* packet) { 1585 bool QuicConnection::WritePacket(SerializedPacket* packet) {
1574 if (packet->packet_number < sent_packet_manager_.largest_sent_packet()) { 1586 if (packet->packet_number <
1575 QUIC_BUG << "Attempt to write packet:" << packet->packet_number 1587 sent_packet_manager_->GetLargestSentPacket(packet->path_id)) {
1576 << " after:" << sent_packet_manager_.largest_sent_packet(); 1588 QUIC_BUG << "Attempt to write packet:" << packet->packet_number << " after:"
1589 << sent_packet_manager_->GetLargestSentPacket(packet->path_id);
1577 CloseConnection(QUIC_INTERNAL_ERROR, "Packet written out of order.", 1590 CloseConnection(QUIC_INTERNAL_ERROR, "Packet written out of order.",
1578 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 1591 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
1579 return true; 1592 return true;
1580 } 1593 }
1581 if (ShouldDiscardPacket(*packet)) { 1594 if (ShouldDiscardPacket(*packet)) {
1582 ++stats_.packets_discarded; 1595 ++stats_.packets_discarded;
1583 return true; 1596 return true;
1584 } 1597 }
1585 // Termination packets are encrypted and saved, so don't exit early. 1598 // Termination packets are encrypted and saved, so don't exit early.
1586 const bool is_termination_packet = IsTerminationPacket(*packet); 1599 const bool is_termination_packet = IsTerminationPacket(*packet);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 } 1674 }
1662 SetPingAlarm(); 1675 SetPingAlarm();
1663 MaybeSetMtuAlarm(); 1676 MaybeSetMtuAlarm();
1664 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: " 1677 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: "
1665 << packet_send_time.ToDebuggingValue(); 1678 << packet_send_time.ToDebuggingValue();
1666 1679
1667 // TODO(ianswett): Change the packet number length and other packet creator 1680 // TODO(ianswett): Change the packet number length and other packet creator
1668 // options by a more explicit API than setting a struct value directly, 1681 // options by a more explicit API than setting a struct value directly,
1669 // perhaps via the NetworkChangeVisitor. 1682 // perhaps via the NetworkChangeVisitor.
1670 packet_generator_.UpdateSequenceNumberLength( 1683 packet_generator_.UpdateSequenceNumberLength(
1671 sent_packet_manager_.least_packet_awaited_by_peer(), 1684 sent_packet_manager_->GetLeastPacketAwaitedByPeer(packet->path_id),
1672 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1685 sent_packet_manager_->EstimateMaxPacketsInFlight(max_packet_length()));
1673 1686
1674 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1687 bool reset_retransmission_alarm = sent_packet_manager_->OnPacketSent(
1675 packet, packet->original_path_id, packet->original_packet_number, 1688 packet, packet->original_path_id, packet->original_packet_number,
1676 packet_send_time, packet->transmission_type, IsRetransmittable(*packet)); 1689 packet_send_time, packet->transmission_type, IsRetransmittable(*packet));
1677 1690
1678 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { 1691 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) {
1679 SetRetransmissionAlarm(); 1692 SetRetransmissionAlarm();
1680 } 1693 }
1681 1694
1682 stats_.bytes_sent += result.bytes_written; 1695 stats_.bytes_sent += result.bytes_written;
1683 ++stats_.packets_sent; 1696 ++stats_.packets_sent;
1684 if (packet->transmission_type != NOT_RETRANSMISSION) { 1697 if (packet->transmission_type != NOT_RETRANSMISSION) {
(...skipping 27 matching lines...) Expand all
1712 // Drop packets that are NULL encrypted since the peer won't accept them 1725 // Drop packets that are NULL encrypted since the peer won't accept them
1713 // anymore. 1726 // anymore.
1714 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " << packet_number 1727 DVLOG(1) << ENDPOINT << "Dropping NULL encrypted packet: " << packet_number
1715 << " since the connection is forward secure."; 1728 << " since the connection is forward secure.";
1716 return true; 1729 return true;
1717 } 1730 }
1718 1731
1719 // If a retransmission has been acked before sending, don't send it. 1732 // If a retransmission has been acked before sending, don't send it.
1720 // This occurs if a packet gets serialized, queued, then discarded. 1733 // This occurs if a packet gets serialized, queued, then discarded.
1721 if (packet.transmission_type != NOT_RETRANSMISSION && 1734 if (packet.transmission_type != NOT_RETRANSMISSION &&
1722 (!sent_packet_manager_.IsUnacked(packet.original_packet_number) || 1735 (!sent_packet_manager_->IsUnacked(packet.original_path_id,
1723 !sent_packet_manager_.HasRetransmittableFrames( 1736 packet.original_packet_number) ||
1724 packet.original_packet_number))) { 1737 !sent_packet_manager_->HasRetransmittableFrames(
1738 packet.original_path_id, packet.original_packet_number))) {
1725 DVLOG(1) << ENDPOINT << "Dropping unacked packet: " << packet_number 1739 DVLOG(1) << ENDPOINT << "Dropping unacked packet: " << packet_number
1726 << " A previous transmission was acked while write blocked."; 1740 << " A previous transmission was acked while write blocked.";
1727 return true; 1741 return true;
1728 } 1742 }
1729 1743
1730 return false; 1744 return false;
1731 } 1745 }
1732 1746
1733 void QuicConnection::OnWriteError(int error_code) { 1747 void QuicConnection::OnWriteError(int error_code) {
1734 const string error_details = "Write failed with error: " + 1748 const string error_details = "Write failed with error: " +
(...skipping 27 matching lines...) Expand all
1762 ConnectionCloseSource source) { 1776 ConnectionCloseSource source) {
1763 // The packet creator or generator encountered an unrecoverable error: tear 1777 // The packet creator or generator encountered an unrecoverable error: tear
1764 // down local connection state immediately. 1778 // down local connection state immediately.
1765 TearDownLocalConnectionState(error, error_details, source); 1779 TearDownLocalConnectionState(error, error_details, source);
1766 } 1780 }
1767 1781
1768 void QuicConnection::OnCongestionChange() { 1782 void QuicConnection::OnCongestionChange() {
1769 visitor_->OnCongestionWindowChange(clock_->ApproximateNow()); 1783 visitor_->OnCongestionWindowChange(clock_->ApproximateNow());
1770 1784
1771 // Uses the connection's smoothed RTT. If zero, uses initial_rtt. 1785 // Uses the connection's smoothed RTT. If zero, uses initial_rtt.
1772 QuicTime::Delta rtt = sent_packet_manager_.GetRttStats()->smoothed_rtt(); 1786 QuicTime::Delta rtt = sent_packet_manager_->GetRttStats()->smoothed_rtt();
1773 if (rtt.IsZero()) { 1787 if (rtt.IsZero()) {
1774 rtt = QuicTime::Delta::FromMicroseconds( 1788 rtt = QuicTime::Delta::FromMicroseconds(
1775 sent_packet_manager_.GetRttStats()->initial_rtt_us()); 1789 sent_packet_manager_->GetRttStats()->initial_rtt_us());
1776 } 1790 }
1777 1791
1778 if (debug_visitor_) 1792 if (debug_visitor_)
1779 debug_visitor_->OnRttChanged(rtt); 1793 debug_visitor_->OnRttChanged(rtt);
1780 } 1794 }
1781 1795
1782 void QuicConnection::OnPathDegrading() { 1796 void QuicConnection::OnPathDegrading() {
1783 visitor_->OnPathDegrading(); 1797 visitor_->OnPathDegrading();
1784 } 1798 }
1785 1799
1786 void QuicConnection::OnHandshakeComplete() { 1800 void QuicConnection::OnHandshakeComplete() {
1787 sent_packet_manager_.SetHandshakeConfirmed(); 1801 sent_packet_manager_->SetHandshakeConfirmed();
1788 // The client should immediately ack the SHLO to confirm the handshake is 1802 // The client should immediately ack the SHLO to confirm the handshake is
1789 // complete with the server. 1803 // complete with the server.
1790 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ && 1804 if (perspective_ == Perspective::IS_CLIENT && !ack_queued_ &&
1791 ack_frame_updated()) { 1805 ack_frame_updated()) {
1792 ack_alarm_->Cancel(); 1806 ack_alarm_->Cancel();
1793 ack_alarm_->Set(clock_->ApproximateNow()); 1807 ack_alarm_->Set(clock_->ApproximateNow());
1794 } 1808 }
1795 } 1809 }
1796 1810
1797 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) { 1811 void QuicConnection::SendOrQueuePacket(SerializedPacket* packet) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 ack_queued_ = false; 1856 ack_queued_ = false;
1843 stop_waiting_count_ = 0; 1857 stop_waiting_count_ = 0;
1844 num_retransmittable_packets_received_since_last_ack_sent_ = 0; 1858 num_retransmittable_packets_received_since_last_ack_sent_ = 0;
1845 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets(); 1859 last_ack_had_missing_packets_ = received_packet_manager_.HasMissingPackets();
1846 num_packets_received_since_last_ack_sent_ = 0; 1860 num_packets_received_since_last_ack_sent_ = 0;
1847 1861
1848 packet_generator_.SetShouldSendAck(true); 1862 packet_generator_.SetShouldSendAck(true);
1849 } 1863 }
1850 1864
1851 void QuicConnection::OnRetransmissionTimeout() { 1865 void QuicConnection::OnRetransmissionTimeout() {
1852 DCHECK(sent_packet_manager_.HasUnackedPackets()); 1866 DCHECK(sent_packet_manager_->HasUnackedPackets());
1853 1867
1854 if (close_connection_after_five_rtos_ && 1868 if (close_connection_after_five_rtos_ &&
1855 sent_packet_manager_.consecutive_rto_count() >= 4) { 1869 sent_packet_manager_->GetConsecutiveRtoCount() >= 4) {
1856 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred. 1870 // Close on the 5th consecutive RTO, so after 4 previous RTOs have occurred.
1857 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts", 1871 CloseConnection(QUIC_TOO_MANY_RTOS, "5 consecutive retransmission timeouts",
1858 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 1872 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
1859 return; 1873 return;
1860 } 1874 }
1861 1875
1862 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated. 1876 // Cancel the send alarm to ensure TimeUntilSend is re-evaluated.
1863 if (FLAGS_quic_only_one_sending_alarm) { 1877 if (FLAGS_quic_only_one_sending_alarm) {
1864 send_alarm_->Cancel(); 1878 send_alarm_->Cancel();
1865 } 1879 }
1866 sent_packet_manager_.OnRetransmissionTimeout(); 1880 sent_packet_manager_->OnRetransmissionTimeout();
1867 WriteIfNotBlocked(); 1881 WriteIfNotBlocked();
1868 1882
1869 // A write failure can result in the connection being closed, don't attempt to 1883 // A write failure can result in the connection being closed, don't attempt to
1870 // write further packets, or to set alarms. 1884 // write further packets, or to set alarms.
1871 if (!connected_) { 1885 if (!connected_) {
1872 return; 1886 return;
1873 } 1887 }
1874 1888
1875 // In the TLP case, the SentPacketManager gives the connection the opportunity 1889 // In the TLP case, the SentPacketManager gives the connection the opportunity
1876 // to send new data before retransmitting. 1890 // to send new data before retransmitting.
1877 if (sent_packet_manager_.MaybeRetransmitTailLossProbe()) { 1891 if (sent_packet_manager_->MaybeRetransmitTailLossProbe()) {
1878 // Send the pending retransmission now that it's been queued. 1892 // Send the pending retransmission now that it's been queued.
1879 WriteIfNotBlocked(); 1893 WriteIfNotBlocked();
1880 } 1894 }
1881 1895
1882 // Ensure the retransmission alarm is always set if there are unacked packets 1896 // Ensure the retransmission alarm is always set if there are unacked packets
1883 // and nothing waiting to be sent. 1897 // and nothing waiting to be sent.
1884 // This happens if the loss algorithm invokes a timer based loss, but the 1898 // This happens if the loss algorithm invokes a timer based loss, but the
1885 // packet doesn't need to be retransmitted. 1899 // packet doesn't need to be retransmitted.
1886 if (!HasQueuedData() && !retransmission_alarm_->IsSet()) { 1900 if (!HasQueuedData() && !retransmission_alarm_->IsSet()) {
1887 SetRetransmissionAlarm(); 1901 SetRetransmissionAlarm();
1888 } 1902 }
1889 } 1903 }
1890 1904
1891 void QuicConnection::SetEncrypter(EncryptionLevel level, 1905 void QuicConnection::SetEncrypter(EncryptionLevel level,
1892 QuicEncrypter* encrypter) { 1906 QuicEncrypter* encrypter) {
1893 packet_generator_.SetEncrypter(level, encrypter); 1907 packet_generator_.SetEncrypter(level, encrypter);
1894 if (level == ENCRYPTION_FORWARD_SECURE) { 1908 if (level == ENCRYPTION_FORWARD_SECURE) {
1895 has_forward_secure_encrypter_ = true; 1909 has_forward_secure_encrypter_ = true;
1896 first_required_forward_secure_packet_ = 1910 first_required_forward_secure_packet_ =
1897 packet_number_of_last_sent_packet_ + 1911 packet_number_of_last_sent_packet_ +
1898 // 3 times the current congestion window (in slow start) should cover 1912 // 3 times the current congestion window (in slow start) should cover
1899 // about two full round trips worth of packets, which should be 1913 // about two full round trips worth of packets, which should be
1900 // sufficient. 1914 // sufficient.
1901 3 * 1915 3 *
1902 sent_packet_manager_.EstimateMaxPacketsInFlight( 1916 sent_packet_manager_->EstimateMaxPacketsInFlight(
1903 max_packet_length()); 1917 max_packet_length());
1904 } 1918 }
1905 } 1919 }
1906 1920
1907 void QuicConnection::SetDiversificationNonce(const DiversificationNonce nonce) { 1921 void QuicConnection::SetDiversificationNonce(const DiversificationNonce nonce) {
1908 DCHECK_EQ(Perspective::IS_SERVER, perspective_); 1922 DCHECK_EQ(Perspective::IS_SERVER, perspective_);
1909 packet_generator_.SetDiversificationNonce(nonce); 1923 packet_generator_.SetDiversificationNonce(nonce);
1910 } 1924 }
1911 1925
1912 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) { 1926 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 } 2194 }
2181 2195
2182 void QuicConnection::SetRetransmissionAlarm() { 2196 void QuicConnection::SetRetransmissionAlarm() {
2183 if (delay_setting_retransmission_alarm_) { 2197 if (delay_setting_retransmission_alarm_) {
2184 pending_retransmission_alarm_ = true; 2198 pending_retransmission_alarm_ = true;
2185 return; 2199 return;
2186 } 2200 }
2187 // Once the handshake has been confirmed, the retransmission alarm should 2201 // Once the handshake has been confirmed, the retransmission alarm should
2188 // never fire before the send alarm. 2202 // never fire before the send alarm.
2189 if (FLAGS_quic_only_one_sending_alarm && 2203 if (FLAGS_quic_only_one_sending_alarm &&
2190 sent_packet_manager_.handshake_confirmed() && send_alarm_->IsSet()) { 2204 sent_packet_manager_->IsHandshakeConfirmed() && send_alarm_->IsSet()) {
2191 DCHECK(!sent_packet_manager_.GetRetransmissionTime().IsInitialized() || 2205 DCHECK(!sent_packet_manager_->GetRetransmissionTime().IsInitialized() ||
2192 sent_packet_manager_.GetRetransmissionTime() >= 2206 sent_packet_manager_->GetRetransmissionTime() >=
2193 send_alarm_->deadline()) 2207 send_alarm_->deadline())
2194 << " retransmission_time:" 2208 << " retransmission_time:"
2195 << sent_packet_manager_.GetRetransmissionTime().ToDebuggingValue() 2209 << sent_packet_manager_->GetRetransmissionTime().ToDebuggingValue()
2196 << " send_alarm:" << send_alarm_->deadline().ToDebuggingValue(); 2210 << " send_alarm:" << send_alarm_->deadline().ToDebuggingValue();
2197 retransmission_alarm_->Cancel(); 2211 retransmission_alarm_->Cancel();
2198 return; 2212 return;
2199 } 2213 }
2200 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); 2214 QuicTime retransmission_time = sent_packet_manager_->GetRetransmissionTime();
2201 retransmission_alarm_->Update(retransmission_time, 2215 retransmission_alarm_->Update(retransmission_time,
2202 QuicTime::Delta::FromMilliseconds(1)); 2216 QuicTime::Delta::FromMilliseconds(1));
2203 } 2217 }
2204 2218
2205 void QuicConnection::MaybeSetMtuAlarm() { 2219 void QuicConnection::MaybeSetMtuAlarm() {
2206 // Do not set the alarm if the target size is less than the current size. 2220 // Do not set the alarm if the target size is less than the current size.
2207 // This covers the case when |mtu_discovery_target_| is at its default value, 2221 // This covers the case when |mtu_discovery_target_| is at its default value,
2208 // zero. 2222 // zero.
2209 if (mtu_discovery_target_ <= max_packet_length()) { 2223 if (mtu_discovery_target_ <= max_packet_length()) {
2210 return; 2224 return;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 next_mtu_probe_at_ = 2394 next_mtu_probe_at_ =
2381 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; 2395 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1;
2382 ++mtu_probe_count_; 2396 ++mtu_probe_count_;
2383 2397
2384 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; 2398 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_;
2385 SendMtuDiscoveryPacket(mtu_discovery_target_); 2399 SendMtuDiscoveryPacket(mtu_discovery_target_);
2386 2400
2387 DCHECK(!mtu_discovery_alarm_->IsSet()); 2401 DCHECK(!mtu_discovery_alarm_->IsSet());
2388 } 2402 }
2389 2403
2390 void QuicConnection::OnPeerMigrationValidated() { 2404 void QuicConnection::OnPeerMigrationValidated(QuicPathId path_id) {
2391 if (active_peer_migration_type_ == NO_CHANGE) { 2405 if (active_peer_migration_type_ == NO_CHANGE) {
2392 QUIC_BUG << "No migration underway."; 2406 QUIC_BUG << "No migration underway.";
2393 return; 2407 return;
2394 } 2408 }
2395 highest_packet_sent_before_peer_migration_ = 0; 2409 highest_packet_sent_before_peer_migration_ = 0;
2396 active_peer_migration_type_ = NO_CHANGE; 2410 active_peer_migration_type_ = NO_CHANGE;
2397 } 2411 }
2398 2412
2399 // TODO(jri): Modify method to start migration whenever a new IP address is seen 2413 // TODO(jri): Modify method to start migration whenever a new IP address is seen
2400 // from a packet with sequence number > the one that triggered the previous 2414 // from a packet with sequence number > the one that triggered the previous
2401 // migration. This should happen even if a migration is underway, since the 2415 // migration. This should happen even if a migration is underway, since the
2402 // most recent migration is the one that we should pay attention to. 2416 // most recent migration is the one that we should pay attention to.
2403 void QuicConnection::StartPeerMigration( 2417 void QuicConnection::StartPeerMigration(
2418 QuicPathId path_id,
2404 PeerAddressChangeType peer_migration_type) { 2419 PeerAddressChangeType peer_migration_type) {
2405 // TODO(fayang): Currently, all peer address change type are allowed. Need to 2420 // TODO(fayang): Currently, all peer address change type are allowed. Need to
2406 // add a method ShouldAllowPeerAddressChange(PeerAddressChangeType type) to 2421 // add a method ShouldAllowPeerAddressChange(PeerAddressChangeType type) to
2407 // determine whether |type| is allowed. 2422 // determine whether |type| is allowed.
2408 if (active_peer_migration_type_ != NO_CHANGE || 2423 if (active_peer_migration_type_ != NO_CHANGE ||
2409 peer_migration_type == NO_CHANGE) { 2424 peer_migration_type == NO_CHANGE) {
2410 QUIC_BUG << "Migration underway or no new migration started."; 2425 QUIC_BUG << "Migration underway or no new migration started.";
2411 return; 2426 return;
2412 } 2427 }
2413 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from " 2428 DVLOG(1) << ENDPOINT << "Peer's ip:port changed from "
2414 << peer_address_.ToString() << " to " 2429 << peer_address_.ToString() << " to "
2415 << last_packet_source_address_.ToString() 2430 << last_packet_source_address_.ToString()
2416 << ", migrating connection."; 2431 << ", migrating connection.";
2417 2432
2418 highest_packet_sent_before_peer_migration_ = 2433 highest_packet_sent_before_peer_migration_ =
2419 packet_number_of_last_sent_packet_; 2434 packet_number_of_last_sent_packet_;
2420 peer_address_ = last_packet_source_address_; 2435 peer_address_ = last_packet_source_address_;
2421 active_peer_migration_type_ = peer_migration_type; 2436 active_peer_migration_type_ = peer_migration_type;
2422 2437
2423 // TODO(jri): Move these calls to OnPeerMigrationValidated. Rename 2438 // TODO(jri): Move these calls to OnPeerMigrationValidated. Rename
2424 // OnConnectionMigration methods to OnPeerMigration. 2439 // OnConnectionMigration methods to OnPeerMigration.
2425 visitor_->OnConnectionMigration(peer_migration_type); 2440 visitor_->OnConnectionMigration(peer_migration_type);
2426 sent_packet_manager_.OnConnectionMigration(peer_migration_type); 2441 sent_packet_manager_->OnConnectionMigration(path_id, peer_migration_type);
2427 } 2442 }
2428 2443
2429 void QuicConnection::OnPathClosed(QuicPathId path_id) { 2444 void QuicConnection::OnPathClosed(QuicPathId path_id) {
2430 // Stop receiving packets on this path. 2445 // Stop receiving packets on this path.
2431 framer_.OnPathClosed(path_id); 2446 framer_.OnPathClosed(path_id);
2432 } 2447 }
2433 2448
2434 bool QuicConnection::ack_frame_updated() const { 2449 bool QuicConnection::ack_frame_updated() const {
2435 return received_packet_manager_.ack_frame_updated(); 2450 return received_packet_manager_.ack_frame_updated();
2436 } 2451 }
(...skipping 22 matching lines...) Expand all
2459 if (perspective_ == Perspective::IS_CLIENT && 2474 if (perspective_ == Perspective::IS_CLIENT &&
2460 frame.data_length >= sizeof(kREJ) && 2475 frame.data_length >= sizeof(kREJ) &&
2461 strncmp(frame.data_buffer, reinterpret_cast<const char*>(&kREJ), 2476 strncmp(frame.data_buffer, reinterpret_cast<const char*>(&kREJ),
2462 sizeof(kREJ)) == 0) { 2477 sizeof(kREJ)) == 0) {
2463 return true; 2478 return true;
2464 } 2479 }
2465 2480
2466 return false; 2481 return false;
2467 } 2482 }
2468 2483
2484 // Uses a 25ms delayed ack timer. Also helps with better signaling
2485 // in low-bandwidth (< ~384 kbps), where an ack is sent per packet.
2486 // Ensures that the Delayed Ack timer is always set to a value lesser
2487 // than the retransmission timer's minimum value (MinRTO). We want the
2488 // delayed ack to get back to the QUIC peer before the sender's
2489 // retransmission timer triggers. Since we do not know the
2490 // reverse-path one-way delay, we assume equal delays for forward and
2491 // reverse paths, and ensure that the timer is set to less than half
2492 // of the MinRTO.
2493 // There may be a value in making this delay adaptive with the help of
2494 // the sender and a signaling mechanism -- if the sender uses a
2495 // different MinRTO, we may get spurious retransmissions. May not have
2496 // any benefits, but if the delayed ack becomes a significant source
2497 // of (likely, tail) latency, then consider such a mechanism.
2498 const QuicTime::Delta QuicConnection::DelayedAckTime() {
2499 return QuicTime::Delta::FromMilliseconds(
2500 min(kMaxDelayedAckTimeMs, kMinRetransmissionTimeMs / 2));
2501 }
2502
2469 } // namespace net 2503 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698