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

[Darwin] Find cached controllers when creating existing controller fabric as well #35205

Merged
merged 1 commit into from
Aug 26, 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
10 changes: 5 additions & 5 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ - (BOOL)isRunning
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);

Expand Down
12 changes: 9 additions & 3 deletions src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo
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 *(
Expand Down Expand Up @@ -1133,11 +1139,11 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
}
}

- (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;
Expand All @@ -1153,7 +1159,7 @@ - (nullable MTRDeviceController *)initializeController:(MTRDeviceController *)co
[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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* 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.
Expand Down
Loading