Skip to content

Commit

Permalink
Fixed updating SRP services (#7714)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kkasperczyk-no authored and pull[bot] committed Sep 15, 2021
1 parent d06fac8 commit b233307
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_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 <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnSrpClientNotification(otError aError,
Expand Down Expand Up @@ -1092,8 +1092,14 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_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));
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/platform/OpenThread/MdnsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b233307

Please sign in to comment.