In quic, replace close_connection_after_five_rtos_ and max_consecutive_ptos_ with num_rtos_for_blackhole_detection_. refactoring only, not protected.

PiperOrigin-RevId: 314563551
Change-Id: I94912fe45de41259bceb683267aa7ab288e3a31d
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index a2c4245..d918730 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -260,7 +260,7 @@
       send_version_negotiation_packet_with_prefixed_lengths_(false),
       idle_timeout_connection_close_behavior_(
           ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET),
-      close_connection_after_five_rtos_(false),
+      num_rtos_for_blackhole_detection_(0),
       uber_received_packet_manager_(&stats_),
       stop_waiting_count_(0),
       pending_retransmission_alarm_(false),
@@ -327,7 +327,6 @@
       supports_release_time_(false),
       release_time_into_future_(QuicTime::Delta::Zero()),
       drop_incoming_retry_packets_(false),
-      max_consecutive_ptos_(0),
       bytes_received_before_address_validation_(0),
       bytes_sent_before_address_validation_(0),
       address_validated_(false),
@@ -572,18 +571,13 @@
   }
   uber_received_packet_manager_.SetFromConfig(config, perspective_);
   if (config.HasClientSentConnectionOption(k5RTO, perspective_)) {
-    close_connection_after_five_rtos_ = true;
+    num_rtos_for_blackhole_detection_ = 5;
   }
   if (sent_packet_manager_.pto_enabled()) {
-    if (config.HasClientSentConnectionOption(k6PTO, perspective_)) {
-      max_consecutive_ptos_ = 5;
-      QUIC_CODE_COUNT(quic_close_connection_6pto);
-    }
-    if (config.HasClientSentConnectionOption(k7PTO, perspective_)) {
-      max_consecutive_ptos_ = 6;
-    }
-    if (config.HasClientSentConnectionOption(k8PTO, perspective_)) {
-      max_consecutive_ptos_ = 7;
+    if (config.HasClientSentConnectionOption(k6PTO, perspective_) ||
+        config.HasClientSentConnectionOption(k7PTO, perspective_) ||
+        config.HasClientSentConnectionOption(k8PTO, perspective_)) {
+      num_rtos_for_blackhole_detection_ = 5;
     }
   }
   if (config.HasClientSentConnectionOption(kNSTP, perspective_)) {
@@ -4510,8 +4504,10 @@
   if (!ShouldDetectBlackhole()) {
     return QuicTime::Zero();
   }
+  DCHECK_LT(0u, num_rtos_for_blackhole_detection_);
   return clock_->ApproximateNow() +
-         sent_packet_manager_.GetNetworkBlackholeDelay();
+         sent_packet_manager_.GetNetworkBlackholeDelay(
+             num_rtos_for_blackhole_detection_);
 }
 
 bool QuicConnection::ShouldDetectBlackhole() const {
@@ -4522,8 +4518,7 @@
   if (!GetHandshakeTimeout().IsInfinite()) {
     return false;
   }
-  return close_connection_after_five_rtos_ ||
-         (sent_packet_manager_.pto_enabled() && max_consecutive_ptos_ > 0);
+  return num_rtos_for_blackhole_detection_ > 0;
 }
 
 QuicTime::Delta QuicConnection::GetHandshakeTimeout() const {
diff --git a/quic/core/quic_connection.h b/quic/core/quic_connection.h
index 6782e06..969da12 100644
--- a/quic/core/quic_connection.h
+++ b/quic/core/quic_connection.h
@@ -1420,9 +1420,8 @@
   // a connection close packet is sent, but not after.
   ConnectionCloseBehavior idle_timeout_connection_close_behavior_;
 
-  // When true, close the QUIC connection after 5 RTOs.  Due to the min rto of
-  // 200ms, this is over 5 seconds.
-  bool close_connection_after_five_rtos_;
+  // When > 0, close the QUIC connection after this number of RTOs.
+  size_t num_rtos_for_blackhole_detection_;
 
   UberReceivedPacketManager uber_received_packet_manager_;
 
@@ -1640,10 +1639,6 @@
   // Indicates whether received RETRY packets should be dropped.
   bool drop_incoming_retry_packets_;
 
-  // If max_consecutive_ptos_ > 0, close connection if consecutive PTOs is
-  // greater than max_consecutive_ptos.
-  size_t max_consecutive_ptos_;
-
   // Bytes received before address validation. Only used when
   // EnforceAntiAmplificationLimit returns true.
   size_t bytes_received_before_address_validation_;
diff --git a/quic/core/quic_sent_packet_manager.cc b/quic/core/quic_sent_packet_manager.cc
index ed0e691..31ac454 100644
--- a/quic/core/quic_sent_packet_manager.cc
+++ b/quic/core/quic_sent_packet_manager.cc
@@ -32,9 +32,6 @@
 // The path degrading delay is the sum of this number of consecutive RTO delays.
 const size_t kNumRetransmissionDelaysForPathDegradingDelay = 2;
 
-// The blachkhole delay is the sum of this number of consecutive RTO delays.
-const size_t kNumRetransmissionDelaysForBlackholeDelay = 5;
-
 // Ensure the handshake timer isnt't faster than 10ms.
 // This limits the tenth retransmitted packet to 10s after the initial CHLO.
 static const int64_t kMinHandshakeTimeoutMs = 10;
@@ -1140,9 +1137,10 @@
       max_tail_loss_probes_ + kNumRetransmissionDelaysForPathDegradingDelay);
 }
 
-const QuicTime::Delta QuicSentPacketManager::GetNetworkBlackholeDelay() const {
+const QuicTime::Delta QuicSentPacketManager::GetNetworkBlackholeDelay(
+    int8_t num_rtos_for_blackhole_detection) const {
   return GetNConsecutiveRetransmissionTimeoutDelay(
-      max_tail_loss_probes_ + kNumRetransmissionDelaysForBlackholeDelay);
+      max_tail_loss_probes_ + num_rtos_for_blackhole_detection);
 }
 
 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay()
diff --git a/quic/core/quic_sent_packet_manager.h b/quic/core/quic_sent_packet_manager.h
index 2513b82..ce8353d 100644
--- a/quic/core/quic_sent_packet_manager.h
+++ b/quic/core/quic_sent_packet_manager.h
@@ -212,7 +212,8 @@
   const QuicTime::Delta GetPathDegradingDelay() const;
 
   // Returns the current delay for detecting network blackhole.
-  const QuicTime::Delta GetNetworkBlackholeDelay() const;
+  const QuicTime::Delta GetNetworkBlackholeDelay(
+      int8_t num_rtos_for_blackhole_detection) const;
 
   const RttStats* GetRttStats() const { return &rtt_stats_; }