From b2333072af5d087c241c2bb0ea82412010f29bfd Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Thu, 17 Jun 2021 17:04:39 +0200 Subject: [PATCH] Fixed updating SRP services (#7714) So far SRP services were updated following remove-readd pattern due to lack of SRP update functionality. This way needs sending two messages per each service update, while in the newest OpenThread version better method is available. That is clearing services locally and readding again that results in sending only one SRP update message. * Added clearing SRP service in case it already exists in the AddSrpService method implementation. * Updated OpenThread submodule. --- .../GenericThreadStackManagerImpl_OpenThread.cpp | 12 +++++++++--- src/platform/OpenThread/MdnsImpl.cpp | 6 ------ third_party/openthread/repo | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index 164196f4538041..2082f5a792118b 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -980,7 +980,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_JoinerStart(voi #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT -static_assert(OPENTHREAD_API_VERSION >= 80, "SRP Client requires a more recent OpenThread version"); +static_assert(OPENTHREAD_API_VERSION >= 120, "SRP Client requires a more recent OpenThread version"); template void GenericThreadStackManagerImpl_OpenThread::OnSrpClientNotification(otError aError, @@ -1092,8 +1092,14 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_AddSrpService(c } else { - VerifyOrExit((strcmp(service.mInstanceName, aInstanceName) != 0) || (strcmp(service.mName, aName) != 0), - error = MapOpenThreadError(OT_ERROR_DUPLICATED)); + if ((strcmp(service.mInstanceName, aInstanceName) == 0) && (strcmp(service.mName, aName) == 0)) + { + VerifyOrExit(MapOpenThreadError(otSrpClientClearService(mOTInst, &(service.mService))) == CHIP_NO_ERROR, + error = MapOpenThreadError(OT_ERROR_FAILED)); + + // Free memory immediately, as OnSrpClientNotification will not be called. + memset(&service, 0, sizeof(service)); + } } } diff --git a/src/platform/OpenThread/MdnsImpl.cpp b/src/platform/OpenThread/MdnsImpl.cpp index 202b27dcebe17a..831da3e2248026 100644 --- a/src/platform/OpenThread/MdnsImpl.cpp +++ b/src/platform/OpenThread/MdnsImpl.cpp @@ -51,12 +51,6 @@ CHIP_ERROR ChipMdnsPublishService(const MdnsService * service) char serviceType[chip::Mdns::kMdnsTypeAndProtocolMaxSize + 1]; snprintf(serviceType, sizeof(serviceType), "%s.%s", service->mType, GetProtocolString(service->mProtocol)); - // Try to remove service before adding it, as SRP doesn't allow to update existing services. - result = ThreadStackMgr().RemoveSrpService(service->mName, serviceType); - - // Service should be successfully removed or not found (not exists). - VerifyOrExit((result == CHIP_NO_ERROR) || (result == Internal::MapOpenThreadError(OT_ERROR_NOT_FOUND)), ); - result = ThreadStackMgr().AddSrpService(service->mName, serviceType, service->mPort, service->mTextEntries, service->mTextEntrySize); diff --git a/third_party/openthread/repo b/third_party/openthread/repo index abcf3ba152cd22..08f7e5011d17b2 160000 --- a/third_party/openthread/repo +++ b/third_party/openthread/repo @@ -1 +1 @@ -Subproject commit abcf3ba152cd226e73e3d60217687b62613de98b +Subproject commit 08f7e5011d17b23d8f84fb8c78fd9522066b03c4