Skip to content

Commit

Permalink
[Group] Move group session check to ExchangeContext (#11646)
Browse files Browse the repository at this point in the history
* Move group session check to ExchangeContext
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Jan 26, 2022
1 parent 955bd20 commit 5241425
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
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()
bool reliableTransmissionRequested = isUDPTransport && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck);

// If a response message is expected...
if (sendFlags.Has(SendMessageFlags::kExpectResponse))
if (sendFlags.Has(SendMessageFlags::kExpectResponse) && !IsGroupExchangeContext())
{
// 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

0 comments on commit 5241425

Please sign in to comment.