diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 547eadc7f..b2694cdaf 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -1269,11 +1269,12 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig ASSERT(targetZone); Zone::Ptr localZone = Zone::GetLocalZone(); + auto parentZone (localZone->GetParent()); /* only relay the message to a) the same local zone, b) the parent zone and c) direct child zones. Exception is a global zone. */ if (!targetZone->GetGlobal() && targetZone != localZone && - targetZone != localZone->GetParent() && + targetZone != parentZone && targetZone->GetParent() != localZone) { return true; } @@ -1352,12 +1353,28 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig bool isMaster = (currentZoneMaster == localEndpoint); if (!isMaster && targetEndpoint != currentZoneMaster) { + if (currentTargetZone == parentZone) { + if (m_CurrentParentEndpoint.exchange(currentZoneMaster.get()) != currentZoneMaster.get()) { + Log(LogInformation, "ApiListener") + << "Relaying messages for parent Zone '" << parentZone->GetName() + << "' through Endpoint '" << currentZoneMaster->GetName() << "' of our own Zone"; + } + } + skippedEndpoints.push_back(targetEndpoint); continue; } relayed = true; + if (currentTargetZone == parentZone) { + if (m_CurrentParentEndpoint.exchange(targetEndpoint.get()) != targetEndpoint.get()) { + Log(LogInformation, "ApiListener") + << "Relaying messages for parent Zone '" << parentZone->GetName() + << "' directly to Endpoint '" << targetEndpoint->GetName() << "' of that Zone"; + } + } + SyncSendMessage(targetEndpoint, message); } diff --git a/lib/remote/apilistener.hpp b/lib/remote/apilistener.hpp index f278c2e9b..1af1f660b 100644 --- a/lib/remote/apilistener.hpp +++ b/lib/remote/apilistener.hpp @@ -8,6 +8,7 @@ #include "remote/httpserverconnection.hpp" #include "remote/endpoint.hpp" #include "remote/messageorigin.hpp" +#include "base/atomic.hpp" #include "base/configobject.hpp" #include "base/process.hpp" #include "base/shared.hpp" @@ -187,6 +188,7 @@ private: Timer::Ptr m_RenewOwnCertTimer; Endpoint::Ptr m_LocalEndpoint; + Atomic m_CurrentParentEndpoint {nullptr}; StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup(); static ApiListener::Ptr m_Instance;