Skip to content

Commit

Permalink
Abort BDX transfers as needed on controller shutdown. (project-chip#3…
Browse files Browse the repository at this point in the history
…5466)

If we're acting as a BDX transfer server, we should shut down transfers
for a fabric index when the corresponding DeviceController shuts down.
  • Loading branch information
bzbarsky-apple authored Sep 7, 2024
1 parent 33fec50 commit 3e5b149
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ void DeviceController::Shutdown()
// assume that all sessions for our fabric belong to us here.
mSystemState->CASESessionMgr()->ReleaseSessionsForFabric(mFabricIndex);

// Shut down any bdx transfers we're acting as the server for.
mSystemState->BDXTransferServer()->AbortTransfersForFabric(mFabricIndex);

// TODO: The CASE session manager does not shut down existing CASE
// sessions. It just shuts down any ongoing CASE session establishment
// we're in the middle of as initiator. Maybe it should shut down
Expand Down
20 changes: 20 additions & 0 deletions src/protocols/bdx/BdxTransferDiagnosticLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "BdxTransferDiagnosticLog.h"

#include <protocols/bdx/BdxTransferDiagnosticLogPool.h>

namespace chip {
namespace bdx {

Expand Down Expand Up @@ -201,5 +203,23 @@ void BdxTransferDiagnosticLog::OnExchangeClosing(Messaging::ExchangeContext * ec
LogErrorOnFailure(OnTransferSessionEnd(CHIP_ERROR_INTERNAL));
}

bool BdxTransferDiagnosticLog::IsForFabric(FabricIndex fabricIndex) const
{
if (mExchangeCtx == nullptr || !mExchangeCtx->HasSessionHandle())
{
return false;
}

auto session = mExchangeCtx->GetSessionHandle();
return session->GetFabricIndex() == fabricIndex;
}

void BdxTransferDiagnosticLog::AbortTransfer()
{
// No need to mTransfer.AbortTransfer() here, since that just tries to async
// send a StatusReport to the other side, but we are going away here.
Reset();
}

} // namespace bdx
} // namespace chip
12 changes: 11 additions & 1 deletion src/protocols/bdx/BdxTransferDiagnosticLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

#pragma once

#include <protocols/bdx/BdxTransferDiagnosticLogPool.h>
#include <lib/core/DataModelTypes.h>
#include <protocols/bdx/BdxTransferProxyDiagnosticLog.h>
#include <protocols/bdx/BdxTransferServerDelegate.h>
#include <protocols/bdx/TransferFacilitator.h>
#include <system/SystemLayer.h>

namespace chip {
namespace bdx {

class BdxTransferDiagnosticLogPoolDelegate;

class BdxTransferDiagnosticLog : public Responder
{
public:
Expand All @@ -45,6 +48,13 @@ class BdxTransferDiagnosticLog : public Responder

void OnExchangeClosing(Messaging::ExchangeContext * ec) override;

/**
* Lifetime management, to allow us to abort transfers when a fabric
* identity is being shut down.
*/
bool IsForFabric(FabricIndex fabricIndex) const;
void AbortTransfer();

protected:
/**
* Called when a BDX message is received over the exchange context
Expand Down
15 changes: 13 additions & 2 deletions src/protocols/bdx/BdxTransferDiagnosticLogPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

#pragma once

#include <lib/core/DataModelTypes.h>
#include <lib/support/Pool.h>
#include <protocols/bdx/BdxTransferDiagnosticLog.h>
#include <protocols/bdx/BdxTransferServerDelegate.h>
#include <system/SystemLayer.h>

namespace chip {
namespace bdx {

class BdxTransferDiagnosticLog;

class BdxTransferDiagnosticLogPoolDelegate
{
public:
Expand All @@ -50,6 +50,17 @@ class BdxTransferDiagnosticLogPool : public BdxTransferDiagnosticLogPoolDelegate

void Release(BdxTransferDiagnosticLog * transfer) override { mTransferPool.ReleaseObject(transfer); }

void AbortTransfersForFabric(FabricIndex fabricIndex)
{
mTransferPool.ForEachActiveObject([fabricIndex](BdxTransferDiagnosticLog * transfer) {
if (transfer->IsForFabric(fabricIndex))
{
transfer->AbortTransfer();
}
return Loop::Continue;
});
}

private:
ObjectPool<BdxTransferDiagnosticLog, N> mTransferPool;
};
Expand Down
3 changes: 3 additions & 0 deletions src/protocols/bdx/BdxTransferServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <protocols/bdx/BdxTransferDiagnosticLogPool.h>

#include <lib/core/DataModelTypes.h>
#include <messaging/ExchangeDelegate.h>
#include <messaging/ExchangeMgr.h>
#include <protocols/bdx/BdxTransferDiagnosticLog.h>
Expand All @@ -42,6 +43,8 @@ class BDXTransferServer : public Messaging::UnsolicitedMessageHandler

void SetDelegate(BDXTransferServerDelegate * delegate) { mDelegate = delegate; }

void AbortTransfersForFabric(FabricIndex fabricIndex) { mPoolDelegate.AbortTransfersForFabric(fabricIndex); }

protected:
CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader,
Messaging::ExchangeDelegate *& newDelegate) override;
Expand Down

0 comments on commit 3e5b149

Please sign in to comment.