diff options
author | Simon Lin <simonlin@google.com> | 2021-09-11 03:31:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 12:31:26 -0700 |
commit | 685a1e0f483febc26127c8c2f2bd8f922b682a06 (patch) | |
tree | 48e3d56f3230df44d28244896ba821e6f808e008 /src/agent | |
parent | 6444e8354958c63093fed55a60910d4061e27364 (diff) | |
download | ot-br-posix-685a1e0f483febc26127c8c2f2bd8f922b682a06.tar.gz |
[advertising-proxy] handle duplicate hosts/services in SRP updates (#1008)
This commit fixes a bug that Advertising Proxy failed to handle
duplicate hosts and services in multiple outstanding SRP updates.
Diffstat (limited to 'src/agent')
-rw-r--r-- | src/agent/advertising_proxy.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/agent/advertising_proxy.cpp b/src/agent/advertising_proxy.cpp index bd87e642..0d710fb7 100644 --- a/src/agent/advertising_proxy.cpp +++ b/src/agent/advertising_proxy.cpp @@ -161,13 +161,15 @@ void AdvertisingProxy::PublishServiceHandler(const char *aName, const char *aTyp void AdvertisingProxy::PublishServiceHandler(const char *aName, const char *aType, otbrError aError) { - otbrError error = OTBR_ERROR_NONE; + std::vector<OutstandingUpdate>::iterator next; otbrLogInfo("Handle publish service '%s.%s' result: %d", aName, aType, aError); - // TODO: there may be same names between two SRP updates. - for (auto update = mOutstandingUpdates.begin(); update != mOutstandingUpdates.end(); ++update) + // Note: There may be same service names in multiple SRP updates. + for (auto update = mOutstandingUpdates.begin(); update != mOutstandingUpdates.end(); update = next) { + next = update + 1; + for (const auto &nameAndType : update->mServiceNames) { if (aName != nameAndType.first || !Mdns::Publisher::IsServiceTypeEqual(aType, nameAndType.second.c_str())) @@ -182,22 +184,16 @@ void AdvertisingProxy::PublishServiceHandler(const char *aName, const char *aTyp // Erase before notifying OpenThread, because there are chances that new // elements may be added to `otSrpServerHandleServiceUpdateResult` and // the iterator will be invalidated. - mOutstandingUpdates.erase(update); + next = mOutstandingUpdates.erase(update); otSrpServerHandleServiceUpdateResult(GetInstance(), updateId, OtbrErrorToOtError(aError)); } else { --update->mCallbackCount; } - ExitNow(); + break; } } - -exit: - if (error != OTBR_ERROR_NONE) - { - otbrLogWarning("Failed to handle result of service %s", aName); - } } void AdvertisingProxy::PublishHostHandler(const char *aName, otbrError aError, void *aContext) @@ -207,12 +203,15 @@ void AdvertisingProxy::PublishHostHandler(const char *aName, otbrError aError, v void AdvertisingProxy::PublishHostHandler(const char *aName, otbrError aError) { - otbrError error = OTBR_ERROR_NONE; + std::vector<OutstandingUpdate>::iterator next; otbrLogInfo("Handle publish host '%s' result: %d", aName, aError); - for (auto update = mOutstandingUpdates.begin(); update != mOutstandingUpdates.end(); ++update) + // Note: There may be same host names in multiple SRP updates. + for (auto update = mOutstandingUpdates.begin(); update != mOutstandingUpdates.end(); update = next) { + next = update + 1; + if (aName != update->mHostName) { continue; @@ -225,20 +224,13 @@ void AdvertisingProxy::PublishHostHandler(const char *aName, otbrError aError) // Erase before notifying OpenThread, because there are chances that new // elements may be added to `otSrpServerHandleServiceUpdateResult` and // the iterator will be invalidated. - mOutstandingUpdates.erase(update); + next = mOutstandingUpdates.erase(update); otSrpServerHandleServiceUpdateResult(GetInstance(), updateId, OtbrErrorToOtError(aError)); } else { --update->mCallbackCount; } - ExitNow(); - } - -exit: - if (error != OTBR_ERROR_NONE) - { - otbrLogWarning("Failed to handle result of host %s", aName); } } |