Skip to content

Commit 5e3ef71

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Abort BDX transfers as needed on controller shutdown. (#35466)
If we're acting as a BDX transfer server, we should shut down transfers for a fabric index when the corresponding DeviceController shuts down.
1 parent c29370f commit 5e3ef71

5 files changed

+50
-3
lines changed

src/controller/CHIPDeviceController.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ void DeviceController::Shutdown()
403403
// assume that all sessions for our fabric belong to us here.
404404
mSystemState->CASESessionMgr()->ReleaseSessionsForFabric(mFabricIndex);
405405

406+
// Shut down any bdx transfers we're acting as the server for.
407+
mSystemState->BDXTransferServer()->AbortTransfersForFabric(mFabricIndex);
408+
406409
// TODO: The CASE session manager does not shut down existing CASE
407410
// sessions. It just shuts down any ongoing CASE session establishment
408411
// we're in the middle of as initiator. Maybe it should shut down

src/protocols/bdx/BdxTransferDiagnosticLog.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "BdxTransferDiagnosticLog.h"
2020

21+
#include <protocols/bdx/BdxTransferDiagnosticLogPool.h>
22+
2123
namespace chip {
2224
namespace bdx {
2325

@@ -201,5 +203,23 @@ void BdxTransferDiagnosticLog::OnExchangeClosing(Messaging::ExchangeContext * ec
201203
LogErrorOnFailure(OnTransferSessionEnd(CHIP_ERROR_INTERNAL));
202204
}
203205

206+
bool BdxTransferDiagnosticLog::IsForFabric(FabricIndex fabricIndex) const
207+
{
208+
if (mExchangeCtx == nullptr || !mExchangeCtx->HasSessionHandle())
209+
{
210+
return false;
211+
}
212+
213+
auto session = mExchangeCtx->GetSessionHandle();
214+
return session->GetFabricIndex() == fabricIndex;
215+
}
216+
217+
void BdxTransferDiagnosticLog::AbortTransfer()
218+
{
219+
// No need to mTransfer.AbortTransfer() here, since that just tries to async
220+
// send a StatusReport to the other side, but we are going away here.
221+
Reset();
222+
}
223+
204224
} // namespace bdx
205225
} // namespace chip

src/protocols/bdx/BdxTransferDiagnosticLog.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
#pragma once
2020

21-
#include <protocols/bdx/BdxTransferDiagnosticLogPool.h>
21+
#include <lib/core/DataModelTypes.h>
2222
#include <protocols/bdx/BdxTransferProxyDiagnosticLog.h>
23+
#include <protocols/bdx/BdxTransferServerDelegate.h>
2324
#include <protocols/bdx/TransferFacilitator.h>
2425
#include <system/SystemLayer.h>
2526

2627
namespace chip {
2728
namespace bdx {
2829

30+
class BdxTransferDiagnosticLogPoolDelegate;
31+
2932
class BdxTransferDiagnosticLog : public Responder
3033
{
3134
public:
@@ -45,6 +48,13 @@ class BdxTransferDiagnosticLog : public Responder
4548

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

51+
/**
52+
* Lifetime management, to allow us to abort transfers when a fabric
53+
* identity is being shut down.
54+
*/
55+
bool IsForFabric(FabricIndex fabricIndex) const;
56+
void AbortTransfer();
57+
4858
protected:
4959
/**
5060
* Called when a BDX message is received over the exchange context

src/protocols/bdx/BdxTransferDiagnosticLogPool.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818

1919
#pragma once
2020

21+
#include <lib/core/DataModelTypes.h>
2122
#include <lib/support/Pool.h>
23+
#include <protocols/bdx/BdxTransferDiagnosticLog.h>
2224
#include <protocols/bdx/BdxTransferServerDelegate.h>
2325
#include <system/SystemLayer.h>
2426

2527
namespace chip {
2628
namespace bdx {
2729

28-
class BdxTransferDiagnosticLog;
29-
3030
class BdxTransferDiagnosticLogPoolDelegate
3131
{
3232
public:
@@ -50,6 +50,17 @@ class BdxTransferDiagnosticLogPool : public BdxTransferDiagnosticLogPoolDelegate
5050

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

53+
void AbortTransfersForFabric(FabricIndex fabricIndex)
54+
{
55+
mTransferPool.ForEachActiveObject([fabricIndex](BdxTransferDiagnosticLog * transfer) {
56+
if (transfer->IsForFabric(fabricIndex))
57+
{
58+
transfer->AbortTransfer();
59+
}
60+
return Loop::Continue;
61+
});
62+
}
63+
5364
private:
5465
ObjectPool<BdxTransferDiagnosticLog, N> mTransferPool;
5566
};

src/protocols/bdx/BdxTransferServer.h

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <protocols/bdx/BdxTransferDiagnosticLogPool.h>
2222

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

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

46+
void AbortTransfersForFabric(FabricIndex fabricIndex) { mPoolDelegate.AbortTransfersForFabric(fabricIndex); }
47+
4548
protected:
4649
CHIP_ERROR OnUnsolicitedMessageReceived(const PayloadHeader & payloadHeader,
4750
Messaging::ExchangeDelegate *& newDelegate) override;

0 commit comments

Comments
 (0)