Skip to content

Commit 9346627

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Remove unused per-controller storage delegate (#17258)
* Remove unused DoesDevicePairingExist function. * Remove write-only mPairedDevicesUpdated field * Remove write-only mPairedDevices from DeviceController. The comment about initializing the commissionee device pool was out of date; the code being removed does not touch that pool. * Remove use of no-longer-existing storage keys from disabled chip-tool code. * Remove unused storage delegate from ControllerDeviceInitParams. * Remove write-only storage delegate field from ControllerInitParams. * Remove write-only storage delegate field from Controller::SetupParams.
1 parent 3aa0841 commit 9346627

13 files changed

+9
-131
lines changed

examples/chip-tool/commands/common/CHIPCommand.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ CHIP_ERROR CHIPCommand::InitializeCommissioner(std::string key, chip::FabricId f
334334
commissionerParams.controllerNOC = nocSpan;
335335
}
336336

337-
commissionerParams.storageDelegate = &mCommissionerStorage;
338337
// TODO: Initialize IPK epoch key in ExampleOperationalCredentials issuer rather than relying on DefaultIpkValue
339338
commissionerParams.operationalCredentialsDelegate = mCredIssuerCmds->GetCredentialIssuer();
340339
commissionerParams.controllerVendorId = chip::VendorId::TestVendor1;

examples/chip-tool/commands/pairing/CommissionedListCommand.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ CHIP_ERROR CommissionedListCommand::PrintInformation()
3535
uint16_t pairedNodesIdsSize = sizeof(pairedNodesIds);
3636
memset(pairedNodesIds, 0, pairedNodesIdsSize);
3737

38-
PERSISTENT_KEY_OP(static_cast<uint64_t>(0), chip::kPairedDeviceListKeyPrefix, key,
39-
ReturnLogErrorOnFailure(mStorage.SyncGetKeyValue(key, pairedNodesIds, pairedNodesIdsSize)));
40-
41-
chip::SerializableU64Set<chip::Controller::kNumMaxPairedDevices> devices;
42-
devices.Deserialize(chip::ByteSpan((uint8_t *) pairedNodesIds, pairedNodesIdsSize));
43-
38+
// TODO: Get the list of paired node IDs. chip-tool needs to store that as
39+
// devices get paired.
4440
uint16_t pairedDevicesCount = 0;
4541
while (pairedNodesIds[pairedDevicesCount] != 0x0 && pairedDevicesCount < chip::Controller::kNumMaxPairedDevices)
4642
{
@@ -69,13 +65,12 @@ CHIP_ERROR CommissionedListCommand::PrintInformation()
6965

7066
CHIP_ERROR CommissionedListCommand::PrintDeviceInformation(chip::NodeId deviceId)
7167
{
68+
// TODO: Controller::SerializedDevice and Controller::SerializableDevice are
69+
// gone. Need to figure out what chip-tool should actually store/retrieve
70+
// here.
7271
chip::Controller::SerializedDevice deviceInfo;
7372
uint16_t size = sizeof(deviceInfo.inner);
7473

75-
PERSISTENT_KEY_OP(deviceId, chip::kPairedDeviceKeyPrefix, key,
76-
ReturnLogErrorOnFailure(mStorage.SyncGetKeyValue(key, deviceInfo.inner, size)));
77-
VerifyOrReturnError(size <= sizeof(deviceInfo.inner), CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR);
78-
7974
chip::Controller::SerializableDevice serializable;
8075
constexpr size_t maxlen = BASE64_ENCODED_LEN(sizeof(serializable));
8176
const size_t len = strnlen(chip::Uint8::to_const_char(&deviceInfo.inner[0]), maxlen);

examples/platform/linux/AppMain.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ CHIP_ERROR InitCommissioner()
456456
ReturnErrorOnFailure(gGroupDataProvider.Init());
457457
factoryParams.groupDataProvider = &gGroupDataProvider;
458458

459-
params.storageDelegate = &gServerStorage;
460459
params.operationalCredentialsDelegate = &gOpCredsIssuer;
461460

462461
ReturnErrorOnFailure(gOpCredsIssuer.Initialize(gServerStorage));

src/controller/CHIPDeviceController.cpp

+1-83
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ constexpr uint32_t kSessionEstablishmentTimeout = 40 * kMillisecondsPerSecond;
105105

106106
DeviceController::DeviceController()
107107
{
108-
mState = State::NotInitialized;
109-
mStorageDelegate = nullptr;
110-
mPairedDevicesInitialized = false;
108+
mState = State::NotInitialized;
111109
}
112110

113111
CHIP_ERROR DeviceController::Init(ControllerInitParams params)
@@ -118,7 +116,6 @@ CHIP_ERROR DeviceController::Init(ControllerInitParams params)
118116
VerifyOrReturnError(params.systemState->SystemLayer() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
119117
VerifyOrReturnError(params.systemState->UDPEndPointManager() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
120118

121-
mStorageDelegate = params.storageDelegate;
122119
#if CONFIG_NETWORK_LAYER_BLE
123120
VerifyOrReturnError(params.systemState->BleLayer() != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
124121
#endif
@@ -231,8 +228,6 @@ CHIP_ERROR DeviceController::Shutdown()
231228
mSystemState->SessionMgr()->ExpireAllPairingsForFabric(mFabricInfo->GetFabricIndex());
232229
}
233230

234-
mStorageDelegate = nullptr;
235-
236231
if (mFabricInfo != nullptr)
237232
{
238233
mFabricInfo->Reset();
@@ -246,16 +241,6 @@ CHIP_ERROR DeviceController::Shutdown()
246241
return CHIP_NO_ERROR;
247242
}
248243

249-
bool DeviceController::DoesDevicePairingExist(const PeerId & deviceId)
250-
{
251-
if (InitializePairedDeviceList() == CHIP_NO_ERROR)
252-
{
253-
return mPairedDevices.Contains(deviceId.GetNodeId());
254-
}
255-
256-
return false;
257-
}
258-
259244
void DeviceController::ReleaseOperationalDevice(NodeId remoteDeviceId)
260245
{
261246
VerifyOrReturn(mState == State::Initialized && mFabricInfo != nullptr,
@@ -329,64 +314,6 @@ void DeviceController::OnFirstMessageDeliveryFailed(const SessionHandle & sessio
329314
}
330315
}
331316

332-
CHIP_ERROR DeviceController::InitializePairedDeviceList()
333-
{
334-
CHIP_ERROR err = CHIP_NO_ERROR;
335-
uint8_t * buffer = nullptr;
336-
337-
VerifyOrExit(mStorageDelegate != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
338-
339-
if (!mPairedDevicesInitialized)
340-
{
341-
constexpr uint16_t max_size = sizeof(uint64_t) * kNumMaxPairedDevices;
342-
buffer = static_cast<uint8_t *>(chip::Platform::MemoryCalloc(max_size, 1));
343-
uint16_t size = max_size;
344-
345-
VerifyOrExit(buffer != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
346-
347-
CHIP_ERROR lookupError = CHIP_NO_ERROR;
348-
PERSISTENT_KEY_OP(static_cast<uint64_t>(0), kPairedDeviceListKeyPrefix, key,
349-
lookupError = mStorageDelegate->SyncGetKeyValue(key, buffer, size));
350-
351-
// It's ok to not have an entry for the Paired Device list. We treat it the same as having an empty list.
352-
if (lookupError != CHIP_ERROR_KEY_NOT_FOUND)
353-
{
354-
VerifyOrExit(size <= max_size, err = CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR);
355-
err = SetPairedDeviceList(ByteSpan(buffer, size));
356-
SuccessOrExit(err);
357-
}
358-
}
359-
360-
exit:
361-
if (buffer != nullptr)
362-
{
363-
chip::Platform::MemoryFree(buffer);
364-
}
365-
if (err != CHIP_NO_ERROR)
366-
{
367-
ChipLogError(Controller, "Failed to initialize the device list with error: %" CHIP_ERROR_FORMAT, err.Format());
368-
}
369-
370-
return err;
371-
}
372-
373-
CHIP_ERROR DeviceController::SetPairedDeviceList(ByteSpan serialized)
374-
{
375-
CHIP_ERROR err = mPairedDevices.Deserialize(serialized);
376-
377-
if (err != CHIP_NO_ERROR)
378-
{
379-
ChipLogError(Controller, "Failed to recreate the device list with buffer %.*s\n", static_cast<int>(serialized.size()),
380-
serialized.data());
381-
}
382-
else
383-
{
384-
mPairedDevicesInitialized = true;
385-
}
386-
387-
return err;
388-
}
389-
390317
CHIP_ERROR DeviceController::GetPeerAddressAndPort(PeerId peerId, Inet::IPAddress & addr, uint16_t & port)
391318
{
392319
VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE);
@@ -412,7 +339,6 @@ ControllerDeviceInitParams DeviceController::GetControllerDeviceInitParams()
412339
.sessionManager = mSystemState->SessionMgr(),
413340
.exchangeMgr = mSystemState->ExchangeMgr(),
414341
.udpEndPointManager = mSystemState->UDPEndPointManager(),
415-
.storageDelegate = mStorageDelegate,
416342
.fabricsTable = mSystemState->Fabrics(),
417343
};
418344
}
@@ -423,7 +349,6 @@ DeviceCommissioner::DeviceCommissioner() :
423349
mDeviceNOCChainCallback(OnDeviceNOCChainGeneration, this), mSetUpCodePairer(this)
424350
{
425351
mPairingDelegate = nullptr;
426-
mPairedDevicesUpdated = false;
427352
mDeviceBeingCommissioned = nullptr;
428353
mDeviceInPASEEstablishment = nullptr;
429354
}
@@ -632,10 +557,6 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
632557
VerifyOrExit(mState == State::Initialized, err = CHIP_ERROR_INCORRECT_STATE);
633558
VerifyOrExit(mDeviceInPASEEstablishment == nullptr, err = CHIP_ERROR_INCORRECT_STATE);
634559

635-
// This will initialize the commissionee device pool if it has not already been initialized.
636-
err = InitializePairedDeviceList();
637-
SuccessOrExit(err);
638-
639560
// TODO(#13940): We need to specify the peer address for BLE transport in bindings.
640561
if (params.GetPeerAddress().GetTransportType() == Transport::Type::kBle ||
641562
params.GetPeerAddress().GetTransportType() == Transport::Type::kUndefined)
@@ -1380,9 +1301,6 @@ CHIP_ERROR DeviceCommissioner::OnOperationalCredentialsProvisioningCompletion(De
13801301

13811302
mSystemState->SystemLayer()->CancelTimer(OnSessionEstablishmentTimeoutCallback, this);
13821303

1383-
mPairedDevices.Insert(device->GetDeviceId());
1384-
mPairedDevicesUpdated = true;
1385-
13861304
if (mPairingDelegate != nullptr)
13871305
{
13881306
mPairingDelegate->OnStatusUpdate(DevicePairingDelegate::SecurePairingSuccess);

src/controller/CHIPDeviceController.h

-19
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,12 @@ namespace Controller {
8181
using namespace chip::Protocols::UserDirectedCommissioning;
8282

8383
constexpr uint16_t kNumMaxActiveDevices = CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES;
84-
constexpr uint16_t kNumMaxPairedDevices = 128;
8584

8685
// Raw functions for cluster callbacks
8786
void OnBasicFailure(void * context, CHIP_ERROR err);
8887

8988
struct ControllerInitParams
9089
{
91-
PersistentStorageDelegate * storageDelegate = nullptr;
9290
DeviceControllerSystemState * systemState = nullptr;
9391
DeviceDiscoveryDelegate * deviceDiscoveryDelegate = nullptr;
9492
OperationalCredentialsDelegate * operationalCredentialsDelegate = nullptr;
@@ -148,12 +146,6 @@ class DLL_EXPORT DeviceController : public SessionRecoveryDelegate, public Abstr
148146

149147
CHIP_ERROR GetPeerAddressAndPort(PeerId peerId, Inet::IPAddress & addr, uint16_t & port);
150148

151-
/**
152-
* This function returns true if the device corresponding to `deviceId` has previously been commissioned
153-
* on the fabric.
154-
*/
155-
bool DoesDevicePairingExist(const PeerId & deviceId);
156-
157149
/**
158150
* This function finds the device corresponding to deviceId, and establishes a secure connection with it.
159151
* Once the connection is successfully establishes (or if it's already connected), it calls `onConnectedDevice`
@@ -247,21 +239,15 @@ class DLL_EXPORT DeviceController : public SessionRecoveryDelegate, public Abstr
247239

248240
State mState;
249241

250-
SerializableU64Set<kNumMaxPairedDevices> mPairedDevices;
251-
bool mPairedDevicesInitialized;
252-
253242
PeerId mLocalId = PeerId();
254243
FabricId mFabricId = kUndefinedFabricId;
255244
FabricInfo * mFabricInfo = nullptr;
256245

257-
PersistentStorageDelegate * mStorageDelegate = nullptr;
258246
// TODO(cecille): Make this configuarable.
259247
static constexpr int kMaxCommissionableNodes = 10;
260248
Dnssd::DiscoveredNodeData mCommissionableNodes[kMaxCommissionableNodes];
261249
DeviceControllerSystemState * mSystemState = nullptr;
262250

263-
CHIP_ERROR InitializePairedDeviceList();
264-
CHIP_ERROR SetPairedDeviceList(ByteSpan pairedDeviceSerializedSet);
265251
ControllerDeviceInitParams GetControllerDeviceInitParams();
266252

267253
OperationalCredentialsDelegate * mOperationalCredentialsDelegate;
@@ -575,11 +561,6 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
575561
DeviceProxy * mDeviceBeingCommissioned = nullptr;
576562
CommissioneeDeviceProxy * mDeviceInPASEEstablishment = nullptr;
577563

578-
/* This field is true when device pairing information changes, e.g. a new device is paired, or
579-
the pairing for a device is removed. The DeviceCommissioner uses this to decide when to
580-
persist the device list */
581-
bool mPairedDevicesUpdated;
582-
583564
CommissioningStage mCommissioningStage = CommissioningStage::kSecurePairing;
584565
bool mRunCommissioningAfterConnection = false;
585566

src/controller/CHIPDeviceControllerFactory.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ void DeviceControllerFactory::PopulateInitParams(ControllerInitParams & controll
253253
controllerParams.controllerNOC = params.controllerNOC;
254254
controllerParams.controllerICAC = params.controllerICAC;
255255
controllerParams.controllerRCAC = params.controllerRCAC;
256-
controllerParams.storageDelegate = params.storageDelegate;
257256

258257
controllerParams.systemState = mSystemState;
259258
controllerParams.controllerVendorId = params.controllerVendorId;

src/controller/CHIPDeviceControllerFactory.h

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ struct SetupParams
4242
{
4343
OperationalCredentialsDelegate * operationalCredentialsDelegate = nullptr;
4444

45-
PersistentStorageDelegate * storageDelegate = nullptr;
46-
4745
/* The following keypair must correspond to the public key used for generating
4846
controllerNOC. It's used by controller to establish CASE sessions with devices */
4947
Crypto::P256Keypair * operationalKeypair = nullptr;

src/controller/CommissioneeDeviceProxy.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct ControllerDeviceInitParams
6767
SessionManager * sessionManager = nullptr;
6868
Messaging::ExchangeManager * exchangeMgr = nullptr;
6969
Inet::EndPointManager<Inet::UDPEndPoint> * udpEndPointManager = nullptr;
70-
PersistentStorageDelegate * storageDelegate = nullptr;
7170
#if CONFIG_NETWORK_LAYER_BLE
7271
Ble::BleLayer * bleLayer = nullptr;
7372
#endif
@@ -168,8 +167,6 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegat
168167
* Update data of the device.
169168
*
170169
* This function will set new IP address, port and MRP retransmission intervals of the device.
171-
* Since the device settings might have been moved from RAM to the persistent storage, the function
172-
* will load the device settings first, before making the changes.
173170
*
174171
* @param[in] addr Address of the device to be set.
175172
* @param[in] config MRP parameters
@@ -190,7 +187,7 @@ class CommissioneeDeviceProxy : public DeviceProxy, public SessionReleaseDelegat
190187
* @brief
191188
* Called to indicate this proxy has been paired successfully.
192189
*
193-
* This causes the secure session parameters to be loaded and stores the session details in the session manager.
190+
* This stores the session details in the session manager.
194191
*/
195192
CHIP_ERROR SetConnected();
196193

src/controller/java/AndroidDeviceControllerWrapper.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ AndroidDeviceControllerWrapper::AllocateNew(JavaVM * vm, jobject deviceControlle
125125
initParams.bleLayer = DeviceLayer::ConnectivityMgr().GetBleLayer();
126126
#endif
127127
initParams.listenPort = CHIP_PORT + 1;
128-
setupParams.storageDelegate = wrapper.get();
129128
setupParams.pairingDelegate = wrapper.get();
130129
setupParams.operationalCredentialsDelegate = opCredsIssuer;
131-
initParams.fabricIndependentStorage = setupParams.storageDelegate;
130+
initParams.fabricIndependentStorage = wrapper.get();
132131

133-
wrapper->mGroupDataProvider.SetStorageDelegate(setupParams.storageDelegate);
132+
wrapper->mGroupDataProvider.SetStorageDelegate(wrapper.get());
134133

135134
CHIP_ERROR err = wrapper->mGroupDataProvider.Init();
136135
if (err != CHIP_NO_ERROR)

src/controller/python/OpCredsBinding.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class OperationalCredentialsAdapter : public OperationalCredentialsDelegate
9898
} // namespace chip
9999

100100
extern chip::Controller::Python::StorageAdapter * pychip_Storage_GetStorageAdapter();
101-
extern chip::Controller::Python::StorageAdapter * sStorageAdapter;
102101
extern chip::Credentials::GroupDataProviderImpl sGroupDataProvider;
103102
extern chip::Controller::ScriptDevicePairingDelegate sPairingDelegate;
104103

@@ -362,7 +361,6 @@ ChipError::StorageType pychip_OpCreds_AllocateController(OpCredsContext * contex
362361
VerifyOrReturnError(err == CHIP_NO_ERROR, err.AsInteger());
363362

364363
Controller::SetupParams initParams;
365-
initParams.storageDelegate = sStorageAdapter;
366364
initParams.pairingDelegate = &sPairingDelegate;
367365
initParams.operationalCredentialsDelegate = context->mAdapter.get();
368366
initParams.operationalKeypair = &ephemeralKey;

src/controller/python/chip/internal/CommissionerImpl.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ extern "C" chip::Controller::DeviceCommissioner * pychip_internal_Commissioner_N
137137
factoryParams.groupDataProvider = &gGroupDataProvider;
138138

139139
commissionerParams.pairingDelegate = &gPairingDelegate;
140-
commissionerParams.storageDelegate = &gServerStorage;
141140

142141
err = ephemeralKey.Initialize();
143142
SuccessOrExit(err);

src/darwin/Framework/CHIP/CHIPDeviceController.mm

-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ - (BOOL)startup:(_Nullable id<CHIPPersistentStorageDelegate>)storageDelegate
265265

266266
params.groupDataProvider = _groupDataProvider;
267267
params.fabricIndependentStorage = _persistentStorageDelegateBridge;
268-
commissionerParams.storageDelegate = _persistentStorageDelegateBridge;
269268
commissionerParams.pairingDelegate = _pairingDelegateBridge;
270269

271270
commissionerParams.operationalCredentialsDelegate = _operationalCredentialsDelegate;

src/lib/support/PersistentStorageMacros.h

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727

2828
namespace chip {
2929

30-
constexpr const char kPairedDeviceListKeyPrefix[] = "ListPairedDevices";
31-
constexpr const char kPairedDeviceKeyPrefix[] = "PairedDevice";
32-
3330
// This macro generates a key for storage using a node ID and a key prefix, and performs the given action
3431
// on that key.
3532
#define PERSISTENT_KEY_OP(node, keyPrefix, key, action) \

0 commit comments

Comments
 (0)