Skip to content

Commit fd6a9a9

Browse files
committed
ApiListener#RelayMessageOne(): log to which Endpoint messages are relayed
if they're for our parent Zone.
1 parent 9abf482 commit fd6a9a9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/remote/apilistener.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,20 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar
12041204
}
12051205
}
12061206

1207+
/**
1208+
* Log the endpoint currently used to relay messages to our parent zone if it (the endpoint) has changed.
1209+
*
1210+
* @param zone The parent zone
1211+
* @param endpoint The new endpoint
1212+
*/
1213+
void ApiListener::LogCurrentParentEndpoint(const Zone::Ptr& zone, const Endpoint::Ptr& endpoint)
1214+
{
1215+
if (m_CurrentParentEndpoint.exchange(endpoint.get()) != endpoint.get()) {
1216+
Log(LogInformation, "ApiListener") << "Relaying messages for parent Zone '"
1217+
<< zone->GetName() << "' to Endpoint '" << endpoint->GetName() << "'";
1218+
}
1219+
}
1220+
12071221
/**
12081222
* Relay a message to a directly connected zone or to a global zone.
12091223
* If some other zone is passed as the target zone, it is not relayed.
@@ -1220,11 +1234,12 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
12201234
ASSERT(targetZone);
12211235

12221236
Zone::Ptr localZone = Zone::GetLocalZone();
1237+
auto parentZone (localZone->GetParent());
12231238

12241239
/* only relay the message to a) the same local zone, b) the parent zone and c) direct child zones. Exception is a global zone. */
12251240
if (!targetZone->GetGlobal() &&
12261241
targetZone != localZone &&
1227-
targetZone != localZone->GetParent() &&
1242+
targetZone != parentZone &&
12281243
targetZone->GetParent() != localZone) {
12291244
return true;
12301245
}
@@ -1303,12 +1318,20 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
13031318
bool isMaster = (currentZoneMaster == localEndpoint);
13041319

13051320
if (!isMaster && targetEndpoint != currentZoneMaster) {
1321+
if (currentTargetZone == parentZone) {
1322+
LogCurrentParentEndpoint(parentZone, currentZoneMaster);
1323+
}
1324+
13061325
skippedEndpoints.push_back(targetEndpoint);
13071326
continue;
13081327
}
13091328

13101329
relayed = true;
13111330

1331+
if (currentTargetZone == parentZone) {
1332+
LogCurrentParentEndpoint(parentZone, targetEndpoint);
1333+
}
1334+
13121335
SyncSendMessage(targetEndpoint, message);
13131336
}
13141337

lib/remote/apilistener.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "remote/httpserverconnection.hpp"
99
#include "remote/endpoint.hpp"
1010
#include "remote/messageorigin.hpp"
11+
#include "base/atomic.hpp"
1112
#include "base/configobject.hpp"
1213
#include "base/process.hpp"
1314
#include "base/shared.hpp"
@@ -177,6 +178,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
177178
Timer::Ptr m_RenewOwnCertTimer;
178179

179180
Endpoint::Ptr m_LocalEndpoint;
181+
Atomic<Endpoint*> m_CurrentParentEndpoint {nullptr};
180182

181183
static ApiListener::Ptr m_Instance;
182184
static std::atomic<bool> m_UpdatedObjectAuthority;
@@ -206,6 +208,8 @@ class ApiListener final : public ObjectImpl<ApiListener>
206208
Stream::Ptr m_LogFile;
207209
size_t m_LogMessageCount{0};
208210

211+
void LogCurrentParentEndpoint(const Zone::Ptr& zone, const Endpoint::Ptr& endpoint);
212+
209213
bool RelayMessageOne(const Zone::Ptr& zone, const MessageOrigin::Ptr& origin, const Dictionary::Ptr& message, const Endpoint::Ptr& currentZoneMaster);
210214
void SyncRelayMessage(const MessageOrigin::Ptr& origin, const ConfigObject::Ptr& secobj, const Dictionary::Ptr& message, bool log);
211215
void PersistMessage(const Dictionary::Ptr& message, const ConfigObject::Ptr& secobj);

0 commit comments

Comments
 (0)