Skip to content

Commit 13ab158

Browse files
Fix handling of non-permitted messages in ExchangeContext. (project-chip#33148) (project-chip#33290)
They should not count as responses, since we don't notify our delegate about them. Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 0bafd3b commit 13ab158

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/messaging/ExchangeContext.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -594,21 +594,26 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload
594594
// Set kFlagReceivedAtLeastOneMessage to true since we have received at least one new application level message
595595
SetHasReceivedAtLeastOneMessage(true);
596596

597-
if (IsResponseExpected())
597+
// Don't send messages on to our delegate if our dispatch does not allow
598+
// those messages. Those messages should also not be treated as responses,
599+
// since if our delegate is expecting a response we will not notify it about
600+
// these messages.
601+
if (mDispatch.MessagePermitted(payloadHeader.GetProtocolID(), payloadHeader.GetMessageType()))
598602
{
599-
// Since we got the response, cancel the response timer.
600-
CancelResponseTimer();
603+
if (IsResponseExpected())
604+
{
605+
// Since we got the response, cancel the response timer.
606+
CancelResponseTimer();
601607

602-
// If the context was expecting a response to a previously sent message, this message
603-
// is implicitly that response.
604-
SetResponseExpected(false);
605-
}
608+
// If the context was expecting a response to a previously sent message, this message
609+
// is implicitly that response.
610+
SetResponseExpected(false);
611+
}
606612

607-
// Don't send messages on to our delegate if our dispatch does not allow
608-
// those messages.
609-
if (mDelegate != nullptr && mDispatch.MessagePermitted(payloadHeader.GetProtocolID(), payloadHeader.GetMessageType()))
610-
{
611-
return mDelegate->OnMessageReceived(this, payloadHeader, std::move(msgBuf));
613+
if (mDelegate != nullptr)
614+
{
615+
return mDelegate->OnMessageReceived(this, payloadHeader, std::move(msgBuf));
616+
}
612617
}
613618

614619
DefaultOnMessageReceived(this, payloadHeader.GetProtocolID(), payloadHeader.GetMessageType(), messageCounter,

0 commit comments

Comments
 (0)