Skip to content
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

Use default application dispatch if an application hasn't provided one #6053

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@ CHIP_ERROR ExchangeContext::SendMessageImpl(Protocols::Id protocolId, uint8_t ms

bool reliableTransmissionRequested = !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);

VerifyOrExit(GetMessageDispatch() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
ExchangeMessageDispatch * dispatch = GetMessageDispatch();
ApplicationExchangeDispatch defaultDispatch;

if (dispatch == nullptr)
{
defaultDispatch.Init(mExchangeMgr->GetReliableMessageMgr(), mExchangeMgr->GetSessionMgr());
dispatch = &defaultDispatch;
}

// If a response message is expected...
if (sendFlags.Has(SendMessageFlags::kExpectResponse))
Expand All @@ -143,8 +150,8 @@ CHIP_ERROR ExchangeContext::SendMessageImpl(Protocols::Id protocolId, uint8_t ms
}
}

err = GetMessageDispatch()->SendMessage(mSecureSession, mExchangeId, IsInitiator(), mReliableMessageContext,
reliableTransmissionRequested, protocolId, msgType, std::move(msgBuf));
err = dispatch->SendMessage(mSecureSession, mExchangeId, IsInitiator(), mReliableMessageContext, reliableTransmissionRequested,
protocolId, msgType, std::move(msgBuf));

exit:
if (err != CHIP_NO_ERROR && IsResponseExpected())
Expand Down Expand Up @@ -361,10 +368,16 @@ CHIP_ERROR ExchangeContext::HandleMessage(const PacketHeader & packetHeader, con
// layer has completed its work on the ExchangeContext.
Retain();

CHIP_ERROR err = CHIP_NO_ERROR;
VerifyOrExit(GetMessageDispatch() != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
ExchangeMessageDispatch * dispatch = GetMessageDispatch();
ApplicationExchangeDispatch defaultDispatch;

if (dispatch == nullptr)
{
defaultDispatch.Init(mExchangeMgr->GetReliableMessageMgr(), mExchangeMgr->GetSessionMgr());
dispatch = &defaultDispatch;
}

err = GetMessageDispatch()->OnMessageReceived(payloadHeader, packetHeader.GetMessageId(), peerAddress, mReliableMessageContext);
CHIP_ERROR err = dispatch->OnMessageReceived(payloadHeader, packetHeader.GetMessageId(), peerAddress, mReliableMessageContext);
SuccessOrExit(err);

// The SecureChannel::StandaloneAck message type is only used for CRMP; do not pass such messages to the application layer.
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/NetworkProvisioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void NetworkProvisioning::OnMessageReceived(Messaging::ExchangeContext * exchang
// Currently, the only mechanism to get this callback is via unsolicited message handler.
// That means that we now own the reference to exchange context. Let's free the reference since we no longer
// need it.
exchangeContext->Release();
exchangeContext->Close();
}

CHIP_ERROR NetworkProvisioning::HandleNetworkProvisioningMessage(uint8_t msgType, const System::PacketBufferHandle & msgBuf)
Expand Down Expand Up @@ -196,7 +196,7 @@ CHIP_ERROR NetworkProvisioning::SendMessageUsingExchange(uint8_t msgType, System
VerifyOrReturnError(exchangeContext != nullptr, CHIP_ERROR_INTERNAL);
CHIP_ERROR err = exchangeContext->SendMessage(Protocols::NetworkProvisioning::Id, msgType, std::move(msgPayload),
Messaging::SendMessageFlags::kNoAutoRequestAck);
exchangeContext->Release();
exchangeContext->Close();
return err;
}

Expand Down