|
48 | 48 | #import "MTRServerCluster_Internal.h"
|
49 | 49 | #import "MTRServerEndpoint_Internal.h"
|
50 | 50 | #import "MTRSessionResumptionStorageBridge.h"
|
| 51 | +#import "MTRUnfairLock.h" |
51 | 52 | #import "NSDataSpanConversion.h"
|
52 | 53 |
|
53 | 54 | #import <os/lock.h>
|
54 | 55 |
|
| 56 | +#include <app/server/Dnssd.h> |
55 | 57 | #include <app/util/af.h>
|
56 | 58 | #include <controller/CHIPDeviceControllerFactory.h>
|
57 | 59 | #include <credentials/CHIPCert.h>
|
|
62 | 64 | #include <crypto/RawKeySessionKeystore.h>
|
63 | 65 | #include <lib/support/Pool.h>
|
64 | 66 | #include <lib/support/TestPersistentStorageDelegate.h>
|
| 67 | +#include <messaging/ReliableMessageMgr.h> |
| 68 | +#include <messaging/ReliableMessageProtocolConfig.h> |
65 | 69 | #include <platform/PlatformManager.h>
|
66 | 70 |
|
67 | 71 | #include <cstdlib>
|
@@ -968,6 +972,33 @@ - (MTRDeviceController * _Nullable)maybeInitializeOTAProvider:(MTRDeviceControll
|
968 | 972 | return controller;
|
969 | 973 | }
|
970 | 974 |
|
| 975 | +- (void)resetOperationalAdvertising |
| 976 | +{ |
| 977 | + if (![self checkIsRunning:nil]) { |
| 978 | + // No need to reset anything; we are not running, so not |
| 979 | + // advertising. |
| 980 | + return; |
| 981 | + } |
| 982 | + |
| 983 | + if (!self.advertiseOperational) { |
| 984 | + // No need to reset anything; we are not advertising the things that |
| 985 | + // would need to get reset. |
| 986 | + return; |
| 987 | + } |
| 988 | + |
| 989 | + std::lock_guard lock(_controllersLock); |
| 990 | + if (_controllers.count != 0) { |
| 991 | + // We have a running controller. That means we likely need to reset |
| 992 | + // operational advertising for that controller. |
| 993 | + dispatch_async(_chipWorkQueue, ^{ |
| 994 | + // StartServer() is the only API we have for resetting DNS-SD |
| 995 | + // advertising. It sure would be nice if there were a "restart" |
| 996 | + // that was a no-op if the DNS-SD server was not already |
| 997 | + // running. |
| 998 | + app::DnssdServer::Instance().StartServer(); |
| 999 | + }); |
| 1000 | + } |
| 1001 | +} |
971 | 1002 | @end
|
972 | 1003 |
|
973 | 1004 | @implementation MTRDeviceControllerFactory (InternalMethods)
|
@@ -1449,3 +1480,39 @@ - (void)setCdCerts:(nullable NSArray<NSData *> *)cdCerts
|
1449 | 1480 | }
|
1450 | 1481 |
|
1451 | 1482 | @end
|
| 1483 | + |
| 1484 | +void MTRSetMessageReliabilityParameters(NSNumber * _Nullable idleRetransmitMs, |
| 1485 | + NSNumber * _Nullable activeRetransmitMs, |
| 1486 | + NSNumber * _Nullable activeThresholdMs, |
| 1487 | + NSNumber * _Nullable additionalRetransmitDelayMs) |
| 1488 | +{ |
| 1489 | + bool resetAdvertising = false; |
| 1490 | + if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil) { |
| 1491 | + Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(NullOptional); |
| 1492 | + resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(NullOptional); |
| 1493 | + } else { |
| 1494 | + if (additionalRetransmitDelayMs != nil) { |
| 1495 | + System::Clock::Milliseconds64 additionalBackoff(additionalRetransmitDelayMs.unsignedLongLongValue); |
| 1496 | + Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(MakeOptional(additionalBackoff)); |
| 1497 | + } |
| 1498 | + |
| 1499 | + // Get current MRP parameters, then override the things we were asked to |
| 1500 | + // override. |
| 1501 | + ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig()); |
| 1502 | + if (idleRetransmitMs != nil) { |
| 1503 | + mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32(idleRetransmitMs.unsignedLongValue); |
| 1504 | + } |
| 1505 | + if (activeRetransmitMs != nil) { |
| 1506 | + mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32(activeRetransmitMs.unsignedLongValue); |
| 1507 | + } |
| 1508 | + if (activeThresholdMs != nil) { |
| 1509 | + mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32(activeThresholdMs.unsignedLongValue); |
| 1510 | + } |
| 1511 | + |
| 1512 | + resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(MakeOptional(mrpConfig)); |
| 1513 | + } |
| 1514 | + |
| 1515 | + if (resetAdvertising) { |
| 1516 | + [[MTRDeviceControllerFactory sharedInstance] resetOperationalAdvertising]; |
| 1517 | + } |
| 1518 | +} |
0 commit comments