Skip to content

Commit

Permalink
Use AbortAllOtherCommunicationOnFabric in RemoveFabric. (#19910)
Browse files Browse the repository at this point in the history
This prevents establishment of new sessions for the fabric, and shuts down other
communication on the sessions that do exist, which our old setup did not use to
do.

Fixes #9642
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 7, 2023
1 parent ebf338f commit 3902648
Showing 1 changed file with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,28 +476,6 @@ void MatterOperationalCredentialsPluginServerInitCallback(void)
DeviceLayer::PlatformMgrImpl().AddEventHandler(OnPlatformEventHandler);
}

namespace {
class FabricCleanupExchangeDelegate : public chip::Messaging::ExchangeDelegate
{
public:
CHIP_ERROR OnMessageReceived(chip::Messaging::ExchangeContext * ec, const PayloadHeader & payloadHeader,
System::PacketBufferHandle && payload) override
{
return CHIP_NO_ERROR;
}
void OnResponseTimeout(chip::Messaging::ExchangeContext * ec) override {}
void OnExchangeClosing(chip::Messaging::ExchangeContext * ec) override
{
SessionManager * sessionManager = ec->GetExchangeMgr()->GetSessionManager();
FabricIndex currentFabricIndex = ec->GetSessionHandle()->GetFabricIndex();
CleanupSessionsForFabric(*sessionManager, currentFabricIndex);
}
};

FabricCleanupExchangeDelegate gFabricCleanupExchangeDelegate;

} // namespace

bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandler * commandObj,
const app::ConcreteCommandPath & commandPath,
const Commands::RemoveFabric::DecodableType & commandData)
Expand Down Expand Up @@ -543,15 +521,7 @@ bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandle
FabricIndex currentFabricIndex = commandObj->GetAccessingFabricIndex();
if (currentFabricIndex == fabricBeingRemoved)
{
// If the current fabric is being removed, don't expire the secure sessions immediately as they are
// still needed to send a pending message generated by emberAfSendImmediateDefaultResponse().
// Hijack the exchange delegate here (as no more messages should be received on this exchange),
// and wait for it to close, before expiring the secure sessions for the fabric. Also, suppress MRP
// usage since the MRP engine still holds an exchange even after it's closed, and the engine references
// the associated session object.
// TODO: https://github.com/project-chip/connectedhomeip/issues/9642
ec->SetAutoRequestAck(false);
ec->SetDelegate(&gFabricCleanupExchangeDelegate);
ec->AbortAllOtherCommunicationOnFabric();
}
else
{
Expand Down

0 comments on commit 3902648

Please sign in to comment.