]> granicus.if.org Git - icinga2/commitdiff
Bugfix: duplicate Welcome messages
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 8 May 2012 08:13:15 +0000 (10:13 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 8 May 2012 08:17:45 +0000 (10:17 +0200)
components/discovery/discoverycomponent.cpp
icinga-app/icinga2.conf
icinga/endpoint.cpp
icinga/endpoint.h

index cc128c2509b69195c0c46ecbc10faf23383d6657..7fccda4e611e9a8a2c9aa8715b9d4f987c9b3d42 100644 (file)
@@ -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);
                }
index 54953b7a9a5d208325ab48bcd1b16e401db86e4c..64faf3fd43831184472a27cad57c2ca02ae5e1f8 100644 (file)
@@ -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
index 9e419279f3e9ccf64d9490d8659302665918222a..76d11dbbb37e8be0c911134b4ce3b33069af7265 100644 (file)
@@ -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<string>::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
index 94d661b2384b0edd26126306e1a502a06106ea45..07b40f3e2ecc6494863f19a0869123cbc2bc178b 100644 (file)
@@ -17,7 +17,8 @@ private:
        string m_Identity;
        set<string> m_MethodSinks;
        set<string> m_MethodSources;
-       unsigned short m_HandshakeCounter;
+       bool m_ReceivedWelcome;
+       bool m_SentWelcome;
 
        weak_ptr<EndpointManager> 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<EndpointManager> GetEndpointManager(void) const;
        void SetEndpointManager(weak_ptr<EndpointManager> manager);