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

Abort BDX transfers as needed on controller shutdown. #35466

Merged
merged 1 commit into from
Sep 7, 2024
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
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
Loading