-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ExchangeMessageDispatch #17521
Conversation
PR #17521: Size comparison from ff32d56 to 1efd09b Increases above 0.2%:
Increases (24 builds for cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, p6)
Decreases (32 builds for cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
Full report (32 builds for cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
|
CHIP_ERROR err = mDispatch.SendMessage(GetExchangeMgr()->GetSessionManager(), mSession.Get(), mExchangeId, IsInitiator(), | ||
GetReliableMessageContext(), reliableTransmissionRequested, protocolId, msgType, | ||
std::move(msgBuf)); | ||
CHIP_ERROR err = ([&] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes an already-large method much larger and quite hard to read/understand, what with the various "return" bits that return out of the lambda, not the overall method. What is the benefit of inlining this instead of having it as a separate function (possibly on ExchangeContext if we don't think it should be on the message dispatch)?
@@ -288,6 +288,12 @@ void ExchangeManager::OnMessageReceived(const PacketHeader & packetHeader, const | |||
} | |||
} | |||
|
|||
if (GetDispatchForDelegate(delegate).IsEncryptionRequired() != session->IsEncrypted()) | |||
{ | |||
ChipLogError(ExchangeManager, "OnMessageReceived failed, err = %s", ErrorStr(CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the error type we used to have here. Why is this the right type?
Also, this check will always fail if delegate
is null, right? As long as we are moving this around, can we skip this check for the !delegate
case where we're just trying to send a standalone ack? Or will something go terribly wrong if the session is not in fact encrypted and we try to send an ack via ApplicationExchangeDispatch?
I incline removing virtual bool MessagePermitted(uint16_t protocol, uint8_t type) = 0;
virtual bool IsEncryptionRequired() const { return true; } Only This approach is more memory efficient, less object to maintain, more robust and readable. @bzbarsky-apple any opinions ? |
Will split this PR into several small PRs |
I don't think it's just CASESession/PASESession that use IsEncryptionRequired... Past that, I don't have any particularly strong views about the way this ends up set up as long as we are doing equivalent checks with equivalent safety guarantees. |
Problem
There are a few TODO left over ExchangeManager and ExchangeContext
Change overview
ExchangeMessageDispatch::SendMessage
andExchangeMessageDispatch::OnMessageReceived
, as they are only used once, and they are non-virtualdispatch.IsEncryptionRequired()
check at exchange creation, do not run the check on every message.Note:
mSession->RequireMRP()
check.ExchangeContext::MatchExchange
is removed because it is inherited by session match.Testing
Passed unit-tests.