From 63e318383dde218a05a2f0fb58b6e86b8f9c3318 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 8 May 2012 10:13:15 +0200 Subject: [PATCH] Bugfix: duplicate Welcome messages --- components/discovery/discoverycomponent.cpp | 15 ++++++++------- icinga-app/icinga2.conf | 2 +- icinga/endpoint.cpp | 21 ++++++++++++++++----- icinga/endpoint.h | 10 +++++++--- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/components/discovery/discoverycomponent.cpp b/components/discovery/discoverycomponent.cpp index cc128c250..7fccda4e6 100644 --- a/components/discovery/discoverycomponent.cpp +++ b/components/discovery/discoverycomponent.cpp @@ -198,12 +198,12 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea) { Endpoint::Ptr endpoint = nrea.Sender; - if (endpoint->GetHandshakeCounter() >= 2) + if (endpoint->GetReceivedWelcome()) return 0; - endpoint->IncrementHandshakeCounter(); + endpoint->SetReceivedWelcome(true); - if (endpoint->GetHandshakeCounter() >= 2) { + if (endpoint->GetSentWelcome()) { EventArgs ea; ea.Source = shared_from_this(); endpoint->OnSessionEstablished(ea); @@ -214,7 +214,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea) void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint) { - if (endpoint->GetHandshakeCounter() >= 2) + if (endpoint->GetSentWelcome()) return; // we assume the other component _always_ wants @@ -224,6 +224,8 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint) request.SetMethod("discovery::Welcome"); GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, endpoint, request); + endpoint->SetSentWelcome(true); + ComponentDiscoveryInfo::Ptr info; if (GetComponentDiscoveryInfo(endpoint->GetIdentity(), &info)) { @@ -235,9 +237,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint) endpoint->RegisterMethodSink(*i); } - endpoint->IncrementHandshakeCounter(); - - if (endpoint->GetHandshakeCounter() >= 2) { + if (endpoint->GetReceivedWelcome()) { EventArgs ea; ea.Source = shared_from_this(); endpoint->OnSessionEstablished(ea); @@ -417,6 +417,7 @@ int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea) /* update LastSeen if we're still connected to this endpoint */ info->LastSeen = now; } else { + /* TODO: figure out whether we actually want to connect to this component (_always_ if IsBroker() == true) */ /* try and reconnect to this component */ endpointManager->AddConnection(info->Node, info->Service); } diff --git a/icinga-app/icinga2.conf b/icinga-app/icinga2.conf index 54953b7a9..64faf3fd4 100644 --- a/icinga-app/icinga2.conf +++ b/icinga-app/icinga2.conf @@ -17,6 +17,6 @@ "kekslistener": { "replicate": "0", "service": "8888" } }, "broker": { - "icinga-c1": { "replicate": "0", "node": "127.0.0.1", "service": "7777" } + "icinga-c1": { "replicate": "0", "node": "10.0.10.3", "service": "7777" } } } \ No newline at end of file diff --git a/icinga/endpoint.cpp b/icinga/endpoint.cpp index 9e419279f..76d11dbbb 100644 --- a/icinga/endpoint.cpp +++ b/icinga/endpoint.cpp @@ -4,7 +4,8 @@ using namespace icinga; Endpoint::Endpoint(void) { - m_HandshakeCounter = false; + m_ReceivedWelcome = false; + m_SentWelcome = false; } string Endpoint::GetIdentity(void) const @@ -126,12 +127,22 @@ set::const_iterator Endpoint::EndSources(void) const return m_MethodSources.end(); } -void Endpoint::IncrementHandshakeCounter(void) +void Endpoint::SetReceivedWelcome(bool value) { - m_HandshakeCounter++; + m_ReceivedWelcome = value; } -unsigned short Endpoint::GetHandshakeCounter(void) const +bool Endpoint::GetReceivedWelcome(void) const { - return m_HandshakeCounter; + return m_ReceivedWelcome; } + +void Endpoint::SetSentWelcome(bool value) +{ + m_SentWelcome = value; +} + +bool Endpoint::GetSentWelcome(void) const +{ + return m_SentWelcome; +} \ No newline at end of file diff --git a/icinga/endpoint.h b/icinga/endpoint.h index 94d661b23..07b40f3e2 100644 --- a/icinga/endpoint.h +++ b/icinga/endpoint.h @@ -17,7 +17,8 @@ private: string m_Identity; set m_MethodSinks; set m_MethodSources; - unsigned short m_HandshakeCounter; + bool m_ReceivedWelcome; + bool m_SentWelcome; weak_ptr m_EndpointManager; @@ -33,8 +34,11 @@ public: void SetIdentity(string identity); bool HasIdentity(void) const; - void IncrementHandshakeCounter(); - unsigned short GetHandshakeCounter(void) const; + void SetReceivedWelcome(bool value); + bool GetReceivedWelcome(void) const; + + void SetSentWelcome(bool value); + bool GetSentWelcome(void) const; shared_ptr GetEndpointManager(void) const; void SetEndpointManager(weak_ptr manager); -- 2.40.0