]> granicus.if.org Git - icinga2/commitdiff
Close old connection when duplicate endpoints are found.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 27 Apr 2012 11:44:53 +0000 (13:44 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 27 Apr 2012 11:44:53 +0000 (13:44 +0200)
base/socket.cpp
icinga-app/icinga.conf
icinga/discoverycomponent.cpp
icinga/endpoint.h
icinga/jsonrpcendpoint.cpp
icinga/jsonrpcendpoint.h
icinga/virtualendpoint.cpp
icinga/virtualendpoint.h

index 2d0656ac931c5d19eec100cbf7ae65e18493f16a..7be38071a1f549a50d4f0c26bc55c79669955e07 100644 (file)
@@ -50,21 +50,21 @@ void Socket::Close(void)
 
 void Socket::CloseInternal(bool from_dtor)
 {
-       if (m_FD != INVALID_SOCKET) {
-               closesocket(m_FD);
-               m_FD = INVALID_SOCKET;
-
-               /* nobody can possibly have a valid event subscription when the
-                  destructor has been called */
-               if (!from_dtor) {
-                       EventArgs ea;
-                       ea.Source = shared_from_this();
-                       OnClosed(ea);
-               }
-       }
+       if (m_FD == INVALID_SOCKET)
+               return;
+
+       closesocket(m_FD);
+       m_FD = INVALID_SOCKET;
 
-       if (!from_dtor)
+       /* nobody can possibly have a valid event subscription when the
+               destructor has been called */
+       if (!from_dtor) {
                Stop();
+
+               EventArgs ea;
+               ea.Source = shared_from_this();
+               OnClosed(ea);
+       }
 }
 
 void Socket::HandleSocketError(void)
index 04916d95f276b1f902bbd24159e19cf404e0f10e..eeb6fc1c55e4091c30ce14a83a5d018da4603e86 100644 (file)
@@ -10,9 +10,6 @@
                "configrpc": { "replicate": "0", "configSource": "1" },
                "demo": { "replicate": "0" }
        },
-       "rpcconnection": {
-               "kekslistener": { "replicate": "0", "hostname": "::1", "port": "7777" }
-       },
        "rpclistener": {
                "kekslistener": { "replicate": "0", "port": "7777" }
        },
index a4682c2c7d7357b61f79df2a5716605f913a51e2..e1ecc8b7757ef70dc0e56b32ef5c6733a7eb39bf 100644 (file)
@@ -33,11 +33,14 @@ int DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewE
        if (endpoint == neea.Endpoint)
                return 0;
 
+       if (!neea.Endpoint->IsConnected())
+               return 0;
+
        if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
-               Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting endpoint.");
+               Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
 
-               endpoint->Stop();
-               GetEndpointManager()->UnregisterEndpoint(endpoint);
+               neea.Endpoint->Stop();
+               GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
        }
 
        return 0;
@@ -61,6 +64,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& neea)
        GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, neea.Sender, request);
 
        /* TODO: send information about this client to all other clients */
+       /* TODO: send stored events for this client */
 
        return 0;
 }
index 785a24bee9cf63acd1cbe52667079d94c1e19fe7..661dc5ddfe775cd246306b5cd2a5af19a316590a 100644 (file)
@@ -49,6 +49,7 @@ public:
        virtual bool IsAllowedMethodSource(string method) const = 0;
 
        virtual bool IsLocal(void) const = 0;
+       virtual bool IsConnected(void) const = 0;
 
        virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message) = 0;
        virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message) = 0;
index 16030548236f7f55d283a3497fe7265b4ef34ba8..c0f57990c15cf385a51b5c7917968c2017ef4c36 100644 (file)
@@ -201,8 +201,6 @@ int JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs&
 
 void JsonRpcEndpoint::Stop(void)
 {
-       if (m_Client) {
+       if (m_Client)
                m_Client->Close();
-               m_Client = JsonRpcClient::Ptr();
-       }
 }
index b04cb78f3d0e3a49b4648895f74f6fde1532e75c..cd43446da7db1a8a7ee5e68322c830c19ddf820d 100644 (file)
@@ -18,8 +18,6 @@ private:
        string m_PeerHostname;
        unsigned short m_PeerPort;
 
-       bool IsConnected(void) const;
-       
        int NewMessageHandler(const NewMessageEventArgs& nmea);
        int ClientClosedHandler(const EventArgs& ea);
        int ClientErrorHandler(const SocketErrorEventArgs& ea);
@@ -47,6 +45,7 @@ public:
        virtual bool IsAllowedMethodSource(string method) const;
 
        virtual bool IsLocal(void) const;
+       virtual bool IsConnected(void) const;
 
        virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
        virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
index fd43080d2b76c896e4a28128a7b5f958cc0985d2..1d0b164da02692117d9275c4d262470526387b30 100644 (file)
@@ -14,6 +14,11 @@ bool VirtualEndpoint::IsLocal(void) const
        return true;
 }
 
+bool VirtualEndpoint::IsConnected(void) const
+{
+       return true;
+}
+
 void VirtualEndpoint::RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
 {
        m_MethodHandlers[method] += callback;
index 7c7cfbe71ecfa75c72719b8fab334bf24372a08a..815e9323e970a7002d113d84329772e2029940dc 100644 (file)
@@ -35,6 +35,7 @@ public:
        virtual string GetAddress(void) const;
 
        virtual bool IsLocal(void) const;
+       virtual bool IsConnected(void) const;
 
        virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
        virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);