Skip to content

Commit

Permalink
Fix handling of non-permitted messages in ExchangeContext. (#33148) (#…
Browse files Browse the repository at this point in the history
…33292)

They should not count as responses, since we don't notify our delegate about
them.

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
andy31415 and bzbarsky-apple authored May 3, 2024
1 parent 798deb7 commit 3c808ab
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,21 +595,26 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload
return CHIP_ERROR_INCORRECT_STATE;
}

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

// If the context was expecting a response to a previously sent message, this message
// is implicitly that response.
SetResponseExpected(false);
}
// If the context was expecting a response to a previously sent message, this message
// is implicitly that response.
SetResponseExpected(false);
}

// Don't send messages on to our delegate if our dispatch does not allow
// those messages.
if (mDelegate != nullptr && mDispatch.MessagePermitted(payloadHeader.GetProtocolID(), payloadHeader.GetMessageType()))
{
return mDelegate->OnMessageReceived(this, payloadHeader, std::move(msgBuf));
if (mDelegate != nullptr)
{
return mDelegate->OnMessageReceived(this, payloadHeader, std::move(msgBuf));
}
}

DefaultOnMessageReceived(this, payloadHeader.GetProtocolID(), payloadHeader.GetMessageType(), messageCounter,
Expand Down

0 comments on commit 3c808ab

Please sign in to comment.