catchunks: avoid excess window decrease in certain conditions

Refs: #5202
Change-Id: I7eeed18fbdfc3ef7a5a277da34f9de0c7068a61d
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
index 3b3e0cd..891b94e 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
@@ -34,8 +34,6 @@
 
 namespace ndn::chunks {
 
-constexpr double PipelineInterestsAdaptive::MIN_SSTHRESH;
-
 PipelineInterestsAdaptive::PipelineInterestsAdaptive(Face& face,
                                                      RttEstimatorWithStats& rttEstimator,
                                                      const Options& opts)
@@ -83,6 +81,7 @@
     return;
 
   bool hasTimeout = false;
+  uint64_t highTimeoutSeg = 0;
 
   for (auto& entry : m_segmentInfo) {
     SegmentInfo& segInfo = entry.second;
@@ -91,13 +90,14 @@
       if (timeElapsed > segInfo.rto) { // timer expired?
         m_nTimeouts++;
         hasTimeout = true;
+        highTimeoutSeg = std::max(highTimeoutSeg, entry.first);
         enqueueForRetransmission(entry.first);
       }
     }
   }
 
   if (hasTimeout) {
-    recordTimeout();
+    recordTimeout(highTimeoutSeg);
     schedulePackets();
   }
 
@@ -227,9 +227,7 @@
               << ", rto=" << segInfo.rto.count() / 1e6 << "ms\n";
   }
 
-  if (m_highData < recvSegNo) {
-    m_highData = recvSegNo;
-  }
+  m_highData = std::max(m_highData, recvSegNo);
 
   // for segments in retx queue, we must not decrement m_nInFlight
   // because it was already decremented when the segment timed out
@@ -310,7 +308,7 @@
     case lp::NackReason::CONGESTION:
       // treated the same as timeout for now
       enqueueForRetransmission(segNo);
-      recordTimeout();
+      recordTimeout(segNo);
       schedulePackets();
       break;
     default:
@@ -327,16 +325,19 @@
     return;
 
   m_nTimeouts++;
-  enqueueForRetransmission(getSegmentFromPacket(interest));
-  recordTimeout();
+
+  uint64_t segNo = getSegmentFromPacket(interest);
+  enqueueForRetransmission(segNo);
+  recordTimeout(segNo);
   schedulePackets();
 }
 
 void
-PipelineInterestsAdaptive::recordTimeout()
+PipelineInterestsAdaptive::recordTimeout(uint64_t segNo)
 {
-  if (m_options.disableCwa || m_highData > m_recPoint) {
-    // react to only one timeout per RTT (conservative window adaptation)
+  if (m_options.disableCwa || segNo > m_recPoint) {
+    // interests that are still outstanding during a timeout event
+    // should not trigger another window decrease later (bug #5202)
     m_recPoint = m_highInterest;
 
     decreaseWindow();