Skip to content

Commit

Permalink
More modularity in AckHandlers.cpp [1/n]
Browse files Browse the repository at this point in the history
Summary: `processAckFrame` is very bloated. It may be due for a larger refactor, but as of now, there are some fairly simple things we can do to make it cleaner.

Reviewed By: mjoras

Differential Revision: D61290801

fbshipit-source-id: e13789b82f6ca86f7959c940573aa887abdda818
  • Loading branch information
Aman Sharma authored and facebook-github-bot committed Aug 16, 2024
1 parent a7aafbc commit 3277f23
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
79 changes: 41 additions & 38 deletions quic/state/AckHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,45 +229,8 @@ AckEvent processAckFrame(
// If we hit a packet which has been lost we need to count the spurious
// loss and ignore all other processing.
if (rPacketIt->declaredLost) {
CHECK_GT(conn.outstandings.declaredLostCount, 0);
conn.lossState.totalPacketsSpuriouslyMarkedLost++;
if (conn.transportSettings.useAdaptiveLossReorderingThresholds) {
if (rPacketIt->metadata.lossReorderDistance.has_value() &&
rPacketIt->metadata.lossReorderDistance.value() >
conn.lossState.reorderingThreshold) {
conn.lossState.reorderingThreshold =
rPacketIt->metadata.lossReorderDistance.value();
}
}
if (conn.transportSettings.useAdaptiveLossTimeThresholds) {
if (rPacketIt->metadata.lossTimeoutDividend.has_value() &&
rPacketIt->metadata.lossTimeoutDividend.value() >
conn.transportSettings.timeReorderingThreshDividend) {
conn.transportSettings.timeReorderingThreshDividend =
rPacketIt->metadata.lossTimeoutDividend.value();
}
}
if (conn.transportSettings.removeFromLossBufferOnSpurious) {
for (auto& f : rPacketIt->packet.frames) {
auto streamFrame = f.asWriteStreamFrame();
if (streamFrame) {
auto stream =
conn.streamManager->findStream(streamFrame->streamId);
if (stream) {
stream->removeFromLossBuffer(
streamFrame->offset, streamFrame->len, streamFrame->fin);
stream->updateAckedIntervals(
streamFrame->offset, streamFrame->len, streamFrame->fin);
conn.streamManager->updateWritableStreams(*stream);
}
}
}
}
modifyStateForSpuriousLoss(conn, *rPacketIt);
QUIC_STATS(conn.statsCallback, onPacketSpuriousLoss);
// Decrement the counter, trust that we will erase this as part of
// the bulk erase.
CHECK_GT(conn.outstandings.declaredLostCount, 0);
conn.outstandings.declaredLostCount--;
if (spuriousLossEvent) {
spuriousLossEvent->addSpuriousPacket(
rPacketIt->metadata,
Expand Down Expand Up @@ -794,4 +757,44 @@ void updateEcnCountEchoed(
ackState.ecnCECountEchoed =
std::max(ackState.ecnCECountEchoed, readAckFrame.ecnCECount);
}

void modifyStateForSpuriousLoss(
QuicConnectionStateBase& conn,
OutstandingPacketWrapper& spuriouslyLostPacket) {
CHECK_GT(conn.outstandings.declaredLostCount, 0);
conn.lossState.totalPacketsSpuriouslyMarkedLost++;
if (conn.transportSettings.useAdaptiveLossReorderingThresholds) {
if (spuriouslyLostPacket.metadata.lossReorderDistance.has_value() &&
spuriouslyLostPacket.metadata.lossReorderDistance.value() >
conn.lossState.reorderingThreshold) {
conn.lossState.reorderingThreshold =
spuriouslyLostPacket.metadata.lossReorderDistance.value();
}
}
if (conn.transportSettings.useAdaptiveLossTimeThresholds) {
if (spuriouslyLostPacket.metadata.lossTimeoutDividend.has_value() &&
spuriouslyLostPacket.metadata.lossTimeoutDividend.value() >
conn.transportSettings.timeReorderingThreshDividend) {
conn.transportSettings.timeReorderingThreshDividend =
spuriouslyLostPacket.metadata.lossTimeoutDividend.value();
}
}
if (conn.transportSettings.removeFromLossBufferOnSpurious) {
for (auto& f : spuriouslyLostPacket.packet.frames) {
auto streamFrame = f.asWriteStreamFrame();
if (streamFrame) {
auto stream = conn.streamManager->findStream(streamFrame->streamId);
if (stream) {
stream->removeFromLossBuffer(
streamFrame->offset, streamFrame->len, streamFrame->fin);
stream->updateAckedIntervals(
streamFrame->offset, streamFrame->len, streamFrame->fin);
conn.streamManager->updateWritableStreams(*stream);
}
}
}
}
CHECK_GT(conn.outstandings.declaredLostCount, 0);
conn.outstandings.declaredLostCount--;
}
} // namespace quic
8 changes: 8 additions & 0 deletions quic/state/AckHandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ void updateEcnCountEchoed(
QuicConnectionStateBase& conn,
PacketNumberSpace pnSpace,
const ReadAckFrame& readAckFrame);

/**
* Modifies the state in the QuicConnectionStateBase when a packet that
* was marked as lost is acked.
*/
void modifyStateForSpuriousLoss(
QuicConnectionStateBase& conn,
OutstandingPacketWrapper& spuriouslyLostPacket);
} // namespace quic

0 comments on commit 3277f23

Please sign in to comment.