From 2e6f7d3cdb8f75f75bb87083058d06916e770eca Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 11 Sep 2013 09:09:04 +0200 Subject: [PATCH] cluster: Fix heartbeat messages. --- components/cluster/clustercomponent.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/components/cluster/clustercomponent.cpp b/components/cluster/clustercomponent.cpp index 80790df0b..9f2332a22 100644 --- a/components/cluster/clustercomponent.cpp +++ b/components/cluster/clustercomponent.cpp @@ -443,9 +443,13 @@ void ClusterComponent::NewClientHandler(const Socket::Ptr& client, TlsRole role) void ClusterComponent::ClusterTimerHandler(void) { /* broadcast a heartbeat message */ + Dictionary::Ptr params = boost::make_shared(); + params->Set("identity", GetIdentity()); + Dictionary::Ptr message = boost::make_shared(); message->Set("jsonrpc", "2.0"); message->Set("method", "cluster::HeartBeat"); + message->Set("params", params); RelayMessage(Endpoint::Ptr(), message, false); @@ -808,17 +812,21 @@ void ClusterComponent::MessageHandler(const Endpoint::Ptr& sender, const Diction RelayMessage(sender, message, true); - if (message->Get("method") == "cluster::HeartBeat") { - sender->SetSeen(Utility::GetTime()); - return; - } - Dictionary::Ptr params = message->Get("params"); if (!params) return; - if (message->Get("method") == "cluster::CheckResult") { + if (message->Get("method") == "cluster::HeartBeat") { + sender->SetSeen(Utility::GetTime()); + + String identity = params->Get("identity"); + + Endpoint::Ptr endpoint = Endpoint::GetByName(identity); + + if (endpoint && endpoint != sender) + endpoint->SetSeen(Utility::GetTime()); + } else if (message->Get("method") == "cluster::CheckResult") { String svc = params->Get("service"); Service::Ptr service = Service::GetByName(svc); -- 2.40.0