|
58 | 58 |
|
59 | 59 | static NSString * const sLastInitialSubscribeLatencyKey = @"lastInitialSubscribeLatency";
|
60 | 60 |
|
| 61 | +static NSString * const sDeviceMayBeReachableReason = @"SPI client indicated the device may now be reachable"; |
| 62 | + |
61 | 63 | // Not static, because these are public API.
|
62 | 64 | NSString * const MTRPreviousDataKey = @"previousData";
|
63 | 65 | NSString * const MTRDataVersionKey = @"dataVersion";
|
@@ -306,6 +308,7 @@ @interface MTRDevice_Concrete ()
|
306 | 308 | // Actively receiving priming report
|
307 | 309 |
|
308 | 310 | @property (nonatomic) MTRInternalDeviceState internalDeviceState;
|
| 311 | +@property (nonatomic) BOOL doingCASEAttemptForDeviceMayBeReachable; |
309 | 312 |
|
310 | 313 | #define MTRDEVICE_SUBSCRIPTION_ATTEMPT_MIN_WAIT_SECONDS (1)
|
311 | 314 | #define MTRDEVICE_SUBSCRIPTION_ATTEMPT_MAX_WAIT_SECONDS (3600)
|
@@ -470,6 +473,7 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle
|
470 | 473 | _state = MTRDeviceStateUnknown;
|
471 | 474 | _internalDeviceState = MTRInternalDeviceStateUnsubscribed;
|
472 | 475 | _internalDeviceStateForDescription = MTRInternalDeviceStateUnsubscribed;
|
| 476 | + _doingCASEAttemptForDeviceMayBeReachable = NO; |
473 | 477 | if (controller.controllerDataStore) {
|
474 | 478 | _persistedClusterData = [[NSCache alloc] init];
|
475 | 479 | } else {
|
@@ -1049,7 +1053,7 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
|
1049 | 1053 | subscriptionCallback->ResetResubscriptionBackoff();
|
1050 | 1054 | }
|
1051 | 1055 | readClientToResubscribe->TriggerResubscribeIfScheduled(reason.UTF8String);
|
1052 |
| - } else if (((_internalDeviceState == MTRInternalDeviceStateSubscribing) || shouldReattemptSubscription) && nodeLikelyReachable) { |
| 1056 | + } else if (((_internalDeviceState == MTRInternalDeviceStateSubscribing && !self.doingCASEAttemptForDeviceMayBeReachable) || shouldReattemptSubscription) && nodeLikelyReachable) { |
1053 | 1057 | // If we have reason to suspect that the node is now reachable and we haven't established a
|
1054 | 1058 | // CASE session yet, let's consider it to be stalled and invalidate the pairing session.
|
1055 | 1059 |
|
@@ -2745,6 +2749,9 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
|
2745 | 2749 | [self _changeInternalState:MTRInternalDeviceStateSubscribing];
|
2746 | 2750 |
|
2747 | 2751 | MTR_LOG("%@ setting up subscription with reason: %@", self, reason);
|
| 2752 | + if ([reason hasPrefix:sDeviceMayBeReachableReason]) { |
| 2753 | + self.doingCASEAttemptForDeviceMayBeReachable = YES; |
| 2754 | + } |
2748 | 2755 |
|
2749 | 2756 | __block bool markUnreachableAfterWait = true;
|
2750 | 2757 | #ifdef DEBUG
|
@@ -2784,6 +2791,8 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
|
2784 | 2791 | mtr_strongify(self);
|
2785 | 2792 | VerifyOrReturn(self, MTR_LOG_DEBUG("_setupSubscriptionWithReason directlyGetSessionForNode called back with nil MTRDevice"));
|
2786 | 2793 |
|
| 2794 | + self.doingCASEAttemptForDeviceMayBeReachable = NO; |
| 2795 | + |
2787 | 2796 | if (error != nil) {
|
2788 | 2797 | MTR_LOG_ERROR("%@ getSessionForNode error %@", self, error);
|
2789 | 2798 | [self->_deviceController asyncDispatchToMatterQueue:^{
|
@@ -4844,7 +4853,7 @@ - (void)_deviceMayBeReachable
|
4844 | 4853 | std::lock_guard lock(self->_lock);
|
4845 | 4854 | // Use _ensureSubscriptionForExistingDelegates so that the subscriptions
|
4846 | 4855 | // will go through the pool as needed, not necessarily happen immediately.
|
4847 |
| - [self _ensureSubscriptionForExistingDelegates:@"SPI client indicated the device may now be reachable"]; |
| 4856 | + [self _ensureSubscriptionForExistingDelegates:sDeviceMayBeReachableReason]; |
4848 | 4857 | } errorHandler:nil];
|
4849 | 4858 | }
|
4850 | 4859 |
|
|
0 commit comments