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

[Group] Move group session check to ExchangeContext #11646

Merged
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
30 changes: 15 additions & 15 deletions src/app/WriteClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,28 +244,28 @@ CHIP_ERROR WriteClient::SendWriteRequest(SessionHandle session, System::Clock::T
// Create a new exchange context.
mpExchangeCtx = mpExchangeMgr->NewContext(session, this);
VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY);
if (session.IsGroupSession())
{
// Exchange will be closed by WriteClientHandle::SendWriteRequest for group messages
err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(packet),
Messaging::SendFlags(Messaging::SendMessageFlags::kNoAutoRequestAck));
}
else
{
mpExchangeCtx->SetResponseTimeout(timeout);

err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(packet),
Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse));
SuccessOrExit(err);
MoveToState(State::AwaitingResponse);
}
mpExchangeCtx->SetResponseTimeout(timeout);

// kExpectResponse is ignored by ExchangeContext in case of groupcast
err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(packet),
Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse));
SuccessOrExit(err);

MoveToState(State::AwaitingResponse);

exit:
if (err != CHIP_NO_ERROR)
{
ClearExistingExchangeContext();
}

if (session.IsGroupSession())
{
// Always shutdown on Group communication
Shutdown();
}

return err;
}

Expand Down Expand Up @@ -361,7 +361,7 @@ CHIP_ERROR WriteClientHandle::SendWriteRequest(SessionHandle session, System::Cl

// Transferring ownership of the underlying WriteClient to the IM layer. IM will manage its lifetime.
// For groupcast writes, there is no transfer of ownership since the interaction is done upon transmission of the action
if (err == CHIP_NO_ERROR && !session.IsGroupSession())
if (err == CHIP_NO_ERROR)
{
// Release the WriteClient without closing it.
mpWriteClient = nullptr;
Expand Down
6 changes: 4 additions & 2 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
const Transport::PeerAddress * peerAddress = GetSessionHandle().GetPeerAddress(mExchangeMgr->GetSessionManager());
// Treat unknown peer address as "not UDP", because we have no idea whether
// it's safe to do MRP there.
bool isUDPTransport = peerAddress && peerAddress->GetTransportType() == Transport::Type::kUdp;
bool isUDPTransport = peerAddress && peerAddress->GetTransportType() == Transport::Type::kUdp;

// this check is ignored by the ExchangeMsgDispatch if !AutoRequestAck()
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved
bool reliableTransmissionRequested = isUDPTransport && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);

// If a response message is expected...
if (sendFlags.Has(SendMessageFlags::kExpectResponse))
if (sendFlags.Has(SendMessageFlags::kExpectResponse) && !IsGroupExchangeContext())
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved
{
// Only one 'response expected' message can be outstanding at a time.
if (IsResponseExpected())
Expand Down
2 changes: 2 additions & 0 deletions src/messaging/ExchangeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, public Referen

bool IsEncryptionRequired() const { return mDispatch->IsEncryptionRequired(); }

bool IsGroupExchangeContext() const { return (mSession.HasValue() && mSession.Value().IsGroupSession()); }

/**
* Send a CHIP message on this exchange.
*
Expand Down