[Darwin] Find cached controllers when creating existing controller on fabric as well (#35205)
- Missed another call site in #35148
diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm
index 4630ff7..650aba4 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm
@@ -331,14 +331,14 @@
return _cppCommissioner != nullptr;
}
-- (BOOL)matchesPendingShutdownWithParams:(MTRDeviceControllerParameters *)parameters
+- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
{
- if (!parameters.operationalCertificate || !parameters.rootCertificate) {
+ if (!operationalCertificate || !rootCertificate) {
return FALSE;
}
- NSNumber * nodeID = [MTRDeviceControllerParameters nodeIDFromNOC:parameters.operationalCertificate];
- NSNumber * fabricID = [MTRDeviceControllerParameters fabricIDFromNOC:parameters.operationalCertificate];
- NSData * publicKey = [MTRDeviceControllerParameters publicKeyFromCertificate:parameters.rootCertificate];
+ NSNumber * nodeID = [MTRDeviceControllerParameters nodeIDFromNOC:operationalCertificate];
+ NSNumber * fabricID = [MTRDeviceControllerParameters fabricIDFromNOC:operationalCertificate];
+ NSData * publicKey = [MTRDeviceControllerParameters publicKeyFromCertificate:rootCertificate];
std::lock_guard lock(_assertionLock);
diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
index bd0b904..00b59f5 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
@@ -660,6 +660,12 @@
return nil;
}
+ // If there is a controller already running with matching parameters that is conceptually shut down from the API consumer's viewpoint, re-use it.
+ MTRDeviceController * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:startupParams.operationalCertificate andRootCertificate:startupParams.rootCertificate];
+ if (existingController) {
+ return existingController;
+ }
+
return [self _startDeviceController:[MTRDeviceController alloc]
startupParams:startupParams
fabricChecker:^MTRDeviceControllerStartupParamsInternal *(
@@ -1133,11 +1139,11 @@
}
}
-- (nullable MTRDeviceController *)_findControllerWithPendingShutdownMatchingParams:(MTRDeviceControllerParameters *)parameters
+- (nullable MTRDeviceController *)_findPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate
{
std::lock_guard lock(_controllersLock);
for (MTRDeviceController * controller in _controllers) {
- if ([controller matchesPendingShutdownWithParams:parameters]) {
+ if ([controller matchesPendingShutdownControllerWithOperationalCertificate:operationalCertificate andRootCertificate:rootCertificate]) {
MTR_LOG("%@ Found existing controller %@ that is pending shutdown and matching parameters, re-using it", self, controller);
[controller clearPendingShutdown];
return controller;
@@ -1153,7 +1159,7 @@
[self _assertCurrentQueueIsNotMatterQueue];
// If there is a controller already running with matching parameters that is conceptually shut down from the API consumer's viewpoint, re-use it.
- MTRDeviceController * existingController = [self _findControllerWithPendingShutdownMatchingParams:parameters];
+ MTRDeviceController * existingController = [self _findPendingShutdownControllerWithOperationalCertificate:parameters.operationalCertificate andRootCertificate:parameters.rootCertificate];
if (existingController) {
return existingController;
}
diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h b/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
index e625d13..f37d6fb 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
+++ b/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
@@ -322,7 +322,7 @@
/**
* This method returns TRUE if this controller matches the fabric reference and node ID as listed in the parameters.
*/
-- (BOOL)matchesPendingShutdownWithParams:(MTRDeviceControllerParameters *)parameters;
+- (BOOL)matchesPendingShutdownControllerWithOperationalCertificate:(nullable MTRCertificateDERBytes)operationalCertificate andRootCertificate:(nullable MTRCertificateDERBytes)rootCertificate;
/**
* Clear any pending shutdown request.