Skip to content

Commit ec4878c

Browse files
Revert "Improve our various round-trip timeout computations. (project-chip#33587)"
This reverts commit 3e93ba6.
1 parent 6b83689 commit ec4878c

10 files changed

+25
-128
lines changed

src/app/OperationalSessionSetup.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,6 @@ CHIP_ERROR OperationalSessionSetup::ScheduleSessionSetupReattempt(System::Clock:
792792
// but in practice for old devices BUSY often sends some hardcoded value
793793
// that tells us nothing about when the other side will decide it has
794794
// timed out.
795-
//
796-
// Unfortunately, we do not have the MRP config for the other side here,
797-
// but in practice if the other side is using its local config to
798-
// compute Sigma2 response timeouts, then it's also returning useful
799-
// values with BUSY, so we will wait long enough.
800795
auto additionalTimeout = CASESession::ComputeSigma2ResponseTimeout(GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig()));
801796
actualTimerDelay += additionalTimeout;
802797
}

src/app/ReadClient.cpp

+15-17
Original file line numberDiff line numberDiff line change
@@ -938,26 +938,24 @@ CHIP_ERROR ReadClient::ComputeLivenessCheckTimerTimeout(System::Clock::Timeout *
938938

939939
//
940940
// To calculate the duration we're willing to wait for a report to come to us, we take into account the maximum interval of
941-
// the subscription AND the time it takes for the report to make it to us in the worst case.
941+
// the subscription AND the time it takes for the report to make it to us in the worst case. This latter bit involves
942+
// computing the Ack timeout from the publisher for the ReportData message being sent to us using our IDLE interval as the
943+
// basis for that computation.
942944
//
943-
// We have no way to estimate what the network latency will be, but we do know the other side will time out its ReportData
944-
// after its computed round-trip timeout plus the processing time it gives us (app::kExpectedIMProcessingTime). Once it
945-
// times out, assuming it sent the report at all, there's no point in us thinking we still have a subscription.
945+
// Make sure to use the retransmission computation that includes backoff. For purposes of that computation, treat us as
946+
// active now (since we are right now sending/receiving messages), and use the default "how long are we guaranteed to stay
947+
// active" threshold for now.
946948
//
947-
// We can't use ComputeRoundTripTimeout() on the session for two reasons: we want the roundtrip timeout from the point of
948-
// view of the peer, not us, and we want to start off with the assumption the peer will likely have, which is that we are
949-
// idle, whereas ComputeRoundTripTimeout() uses the current activity state of the peer.
949+
// TODO: We need to find a good home for this logic that will correctly compute this based on transport. For now, this will
950+
// suffice since we don't use TCP as a transport currently and subscriptions over BLE aren't really a thing.
950951
//
951-
// So recompute the round-trip timeout directly. Assume MRP, since in practice that is likely what is happening.
952-
auto & peerMRPConfig = mReadPrepareParams.mSessionHolder->GetRemoteMRPConfig();
953-
// Peer will assume we are idle (hence we pass kZero to GetMessageReceiptTimeout()), but will assume we treat it as active
954-
// for the response, so to match the retransmission timeout computation for the message back to the peeer, we should treat
955-
// it as active.
956-
auto roundTripTimeout = mReadPrepareParams.mSessionHolder->GetMessageReceiptTimeout(System::Clock::kZero) +
957-
kExpectedIMProcessingTime +
958-
GetRetransmissionTimeout(peerMRPConfig.mActiveRetransTimeout, peerMRPConfig.mIdleRetransTimeout,
959-
System::SystemClock().GetMonotonicTimestamp(), peerMRPConfig.mActiveThresholdTime);
960-
*aTimeout = System::Clock::Seconds16(mMaxInterval) + roundTripTimeout;
952+
const auto & localMRPConfig = GetLocalMRPConfig();
953+
const auto & defaultMRPConfig = GetDefaultMRPConfig();
954+
const auto & ourMrpConfig = localMRPConfig.ValueOr(defaultMRPConfig);
955+
auto publisherTransmissionTimeout =
956+
GetRetransmissionTimeout(ourMrpConfig.mActiveRetransTimeout, ourMrpConfig.mIdleRetransTimeout,
957+
System::SystemClock().GetMonotonicTimestamp(), ourMrpConfig.mActiveThresholdTime);
958+
*aTimeout = System::Clock::Seconds16(mMaxInterval) + publisherTransmissionTimeout;
961959
return CHIP_NO_ERROR;
962960
}
963961

src/darwin/Framework/CHIPTests/MTRControllerTests.m

-4
Original file line numberDiff line numberDiff line change
@@ -1557,10 +1557,6 @@ - (void)testSetMRPParameters
15571557
// Can be called before starting the factory
15581558
XCTAssertFalse(MTRDeviceControllerFactory.sharedInstance.running);
15591559
MTRSetMessageReliabilityParameters(@2000, @2000, @2000, @2000);
1560-
1561-
// Now reset back to the default state, so timings in other tests are not
1562-
// affected.
1563-
MTRSetMessageReliabilityParameters(nil, nil, nil, nil);
15641560
}
15651561

15661562
@end

src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m

-4
Original file line numberDiff line numberDiff line change
@@ -2140,10 +2140,6 @@ - (void)testSetMRPParametersWithRunningController
21402140
XCTAssertTrue(controller.running);
21412141
MTRSetMessageReliabilityParameters(@2000, @2000, @2000, @2000);
21422142
[controller shutdown];
2143-
2144-
// Now reset back to the default state, so timings in other tests are not
2145-
// affected.
2146-
MTRSetMessageReliabilityParameters(nil, nil, nil, nil);
21472143
}
21482144

21492145
// TODO: This might also want to go in a separate test file, with some shared setup for commissioning devices per test

src/protocols/secure_channel/CASESession.cpp

+8-23
Original file line numberDiff line numberDiff line change
@@ -2362,36 +2362,21 @@ CHIP_ERROR CASESession::OnMessageReceived(ExchangeContext * ec, const PayloadHea
23622362
return err;
23632363
}
23642364

2365-
namespace {
2366-
System::Clock::Timeout ComputeRoundTripTimeout(ExchangeContext::Timeout serverProcessingTime,
2367-
const ReliableMessageProtocolConfig & remoteMrpConfig)
2365+
System::Clock::Timeout CASESession::ComputeSigma1ResponseTimeout(const ReliableMessageProtocolConfig & remoteMrpConfig)
23682366
{
2369-
// TODO: This is duplicating logic from Session::ComputeRoundTripTimeout. Unfortunately, it's called by
2370-
// consumers who do not have a session.
2371-
const auto & maybeLocalMRPConfig = GetLocalMRPConfig();
2372-
const auto & defaultMRRPConfig = GetDefaultMRPConfig();
2373-
const auto & localMRPConfig = maybeLocalMRPConfig.ValueOr(defaultMRRPConfig);
23742367
return GetRetransmissionTimeout(remoteMrpConfig.mActiveRetransTimeout, remoteMrpConfig.mIdleRetransTimeout,
2375-
// Assume peer is idle, as a worst-case assumption (probably true for
2376-
// Sigma1, since that will be our initial message on the session, but less
2377-
// so for Sigma2).
2368+
// Assume peer is idle, since that's what we
2369+
// will assume for our initial message.
23782370
System::Clock::kZero, remoteMrpConfig.mActiveThresholdTime) +
2379-
serverProcessingTime +
2380-
GetRetransmissionTimeout(localMRPConfig.mActiveRetransTimeout, localMRPConfig.mIdleRetransTimeout,
2381-
// Peer will assume we are active, since it's
2382-
// responding to our message.
2383-
System::SystemClock().GetMonotonicTimestamp(), localMRPConfig.mActiveThresholdTime);
2384-
}
2385-
} // anonymous namespace
2386-
2387-
System::Clock::Timeout CASESession::ComputeSigma1ResponseTimeout(const ReliableMessageProtocolConfig & remoteMrpConfig)
2388-
{
2389-
return ComputeRoundTripTimeout(kExpectedSigma1ProcessingTime, remoteMrpConfig);
2371+
kExpectedSigma1ProcessingTime;
23902372
}
23912373

23922374
System::Clock::Timeout CASESession::ComputeSigma2ResponseTimeout(const ReliableMessageProtocolConfig & remoteMrpConfig)
23932375
{
2394-
return ComputeRoundTripTimeout(kExpectedHighProcessingTime, remoteMrpConfig);
2376+
return GetRetransmissionTimeout(remoteMrpConfig.mActiveRetransTimeout, remoteMrpConfig.mIdleRetransTimeout,
2377+
// Assume peer is idle, as a worst-case assumption.
2378+
System::Clock::kZero, remoteMrpConfig.mActiveThresholdTime) +
2379+
kExpectedHighProcessingTime;
23952380
}
23962381

23972382
bool CASESession::InvokeBackgroundWorkWatchdog()

src/transport/GroupSession.h

-14
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ class IncomingGroupSession : public Session, public ReferenceCounted<IncomingGro
7575
return System::Clock::Timeout();
7676
}
7777

78-
System::Clock::Milliseconds32 GetMessageReceiptTimeout(System::Clock::Timestamp ourLastActivity) const override
79-
{
80-
// There are no timeouts for group sessions.
81-
VerifyOrDie(false);
82-
return System::Clock::Timeout();
83-
}
84-
8578
GroupId GetGroupId() const { return mGroupId; }
8679

8780
private:
@@ -134,13 +127,6 @@ class OutgoingGroupSession : public Session, public ReferenceCounted<OutgoingGro
134127
return System::Clock::Timeout();
135128
}
136129

137-
System::Clock::Milliseconds32 GetMessageReceiptTimeout(System::Clock::Timestamp ourLastActivity) const override
138-
{
139-
// There are no timeouts for group sessions.
140-
VerifyOrDie(false);
141-
return System::Clock::Timeout();
142-
}
143-
144130
GroupId GetGroupId() const { return mGroupId; }
145131

146132
private:

src/transport/SecureSession.h

-21
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,6 @@ class SecureSession : public Session, public ReferenceCounted<SecureSession, Sec
179179
return System::Clock::Timeout();
180180
}
181181

182-
System::Clock::Milliseconds32 GetMessageReceiptTimeout(System::Clock::Timestamp ourLastActivity) const override
183-
{
184-
switch (mPeerAddress.GetTransportType())
185-
{
186-
case Transport::Type::kUdp: {
187-
const auto & maybeLocalMRPConfig = GetLocalMRPConfig();
188-
const auto & defaultMRRPConfig = GetDefaultMRPConfig();
189-
const auto & localMRPConfig = maybeLocalMRPConfig.ValueOr(defaultMRRPConfig);
190-
return GetRetransmissionTimeout(localMRPConfig.mActiveRetransTimeout, localMRPConfig.mIdleRetransTimeout,
191-
ourLastActivity, localMRPConfig.mActiveThresholdTime);
192-
}
193-
case Transport::Type::kTcp:
194-
return System::Clock::Seconds16(30);
195-
case Transport::Type::kBle:
196-
return System::Clock::Milliseconds32(BTP_ACK_TIMEOUT_MS);
197-
default:
198-
break;
199-
}
200-
return System::Clock::Timeout();
201-
}
202-
203182
const PeerAddress & GetPeerAddress() const { return mPeerAddress; }
204183
void SetPeerAddress(const PeerAddress & address) { mPeerAddress = address; }
205184

src/transport/Session.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ System::Clock::Timeout Session::ComputeRoundTripTimeout(System::Clock::Timeout u
7070
{
7171
return System::Clock::kZero;
7272
}
73-
74-
// Treat us as active for purposes of GetMessageReceiptTimeout(), since the
75-
// other side would be responding to our message.
76-
return GetAckTimeout() + upperlayerProcessingTimeout + GetMessageReceiptTimeout(System::SystemClock().GetMonotonicTimestamp());
73+
return GetAckTimeout() + upperlayerProcessingTimeout;
7774
}
7875

7976
uint16_t Session::SessionIdForLogging() const

src/transport/Session.h

+1-15
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,7 @@ class Session
244244
virtual bool AllowsLargePayload() const = 0;
245245
virtual const SessionParameters & GetRemoteSessionParameters() const = 0;
246246
virtual System::Clock::Timestamp GetMRPBaseTimeout() const = 0;
247-
// GetAckTimeout is the estimate for how long it could take for the other
248-
// side to receive our message (accounting for our MRP retransmits if it
249-
// gets lost) and send a response.
250-
virtual System::Clock::Milliseconds32 GetAckTimeout() const = 0;
251-
252-
// GetReceiptTimeout is the estimate for how long it could take for us to
253-
// receive a message after the other side sends it, accounting for the MRP
254-
// retransmits the other side might do if the message gets lost.
255-
//
256-
// The caller is expected to provide an estimate for when the peer would
257-
// last have heard from us. The most likely values to pass are
258-
// System::SystemClock().GetMonotonicTimestamp() (to indicate "peer is
259-
// responding to a message it just received") and System::Clock::kZero (to
260-
// indicate "peer is reaching out to us, not in response to anything").
261-
virtual System::Clock::Milliseconds32 GetMessageReceiptTimeout(System::Clock::Timestamp ourLastActivity) const = 0;
247+
virtual System::Clock::Milliseconds32 GetAckTimeout() const = 0;
262248

263249
const ReliableMessageProtocolConfig & GetRemoteMRPConfig() const { return GetRemoteSessionParameters().GetMRPConfig(); }
264250

src/transport/UnauthenticatedSessionTable.h

-21
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,6 @@ class UnauthenticatedSession : public Session, public ReferenceCounted<Unauthent
107107
return System::Clock::Timeout();
108108
}
109109

110-
System::Clock::Milliseconds32 GetMessageReceiptTimeout(System::Clock::Timestamp ourLastActivity) const override
111-
{
112-
switch (mPeerAddress.GetTransportType())
113-
{
114-
case Transport::Type::kUdp: {
115-
const auto & maybeLocalMRPConfig = GetLocalMRPConfig();
116-
const auto & defaultMRRPConfig = GetDefaultMRPConfig();
117-
const auto & localMRPConfig = maybeLocalMRPConfig.ValueOr(defaultMRRPConfig);
118-
return GetRetransmissionTimeout(localMRPConfig.mActiveRetransTimeout, localMRPConfig.mIdleRetransTimeout,
119-
ourLastActivity, localMRPConfig.mActiveThresholdTime);
120-
}
121-
case Transport::Type::kTcp:
122-
return System::Clock::Seconds16(30);
123-
case Transport::Type::kBle:
124-
return System::Clock::Milliseconds32(BTP_ACK_TIMEOUT_MS);
125-
default:
126-
break;
127-
}
128-
return System::Clock::Timeout();
129-
}
130-
131110
NodeId GetPeerNodeId() const
132111
{
133112
if (mSessionRole == SessionRole::kInitiator)

0 commit comments

Comments
 (0)