]> granicus.if.org Git - icinga2/commitdiff
Make sure we only have one connection per satellite
authorGunnar Beutner <gunnar@beutner.name>
Mon, 25 Jan 2016 09:57:06 +0000 (10:57 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 25 Jan 2016 09:57:06 +0000 (10:57 +0100)
refs #11014

lib/remote/apilistener.cpp
lib/remote/jsonrpcconnection.cpp
lib/remote/jsonrpcconnection.hpp

index 747f709b7a47958d9b3f9dd3db13cb064762d0c7..5f5961d12e9cd50521ae71e6fff69ec7790c30c5 100644 (file)
@@ -520,8 +520,19 @@ void ApiListener::ApiTimerHandler(void)
                lmessage->Set("method", "log::SetLogPosition");
                lmessage->Set("params", lparams);
 
-               BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients())
-                       client->SendMessage(lmessage);
+               double maxTs = 0;
+
+               BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) {
+                       if (client->GetTimestamp() > maxTs)
+                               maxTs = client->GetTimestamp();
+               }
+
+               BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) {
+                       if (client->GetTimestamp() != maxTs)
+                               client->Disconnect();
+                       else
+                               client->SendMessage(lmessage);
+               }
 
                Log(LogNotice, "ApiListener")
                    << "Setting log position for identity '" << endpoint->GetName() << "': "
@@ -586,8 +597,19 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar
                Log(LogNotice, "ApiListener")
                    << "Sending message to '" << endpoint->GetName() << "'";
 
-               BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients())
+               double maxTs = 0;
+
+               BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) {
+                       if (client->GetTimestamp() > maxTs)
+                               maxTs = client->GetTimestamp();
+               }
+
+               BOOST_FOREACH(const JsonRpcConnection::Ptr& client, endpoint->GetClients()) {
+                       if (client->GetTimestamp() != maxTs)
+                               continue;
+
                        client->SendMessage(message);
+               }
        }
 }
 
index ae514dfabc50eb3aebcc7bc9239a0d31f4dd0d5f..49191f93850d5310cf11ad9c265a4d8e362ac2db 100644 (file)
@@ -41,7 +41,7 @@ static Timer::Ptr l_JsonRpcConnectionTimeoutTimer;
 JsonRpcConnection::JsonRpcConnection(const String& identity, bool authenticated,
     const TlsStream::Ptr& stream, ConnectionRole role)
        : m_Identity(identity), m_Authenticated(authenticated), m_Stream(stream),
-         m_Role(role), m_Seen(Utility::GetTime()),
+         m_Role(role), m_Timestamp(Utility::GetTime()), m_Seen(Utility::GetTime()),
          m_NextHeartbeat(0), m_HeartbeatTimeout(0)
 {
        boost::call_once(l_JsonRpcConnectionOnceFlag, &JsonRpcConnection::StaticInitialize);
@@ -66,6 +66,11 @@ void JsonRpcConnection::Start(void)
                DataAvailableHandler();
 }
 
+double JsonRpcConnection::GetTimestamp(void) const
+{
+       return m_Timestamp;
+}
+
 String JsonRpcConnection::GetIdentity(void) const
 {
        return m_Identity;
index 083b1d17753b99b5fb0140f877e243e0b2a3937d..1e514e8b499189c4676d09d3a7cb9905f6203762 100644 (file)
@@ -57,6 +57,7 @@ public:
 
        void Start(void);
 
+       double GetTimestamp(void) const;
        String GetIdentity(void) const;
        bool IsAuthenticated(void) const;
        Endpoint::Ptr GetEndpoint(void) const;
@@ -76,6 +77,7 @@ private:
        Endpoint::Ptr m_Endpoint;
        TlsStream::Ptr m_Stream;
        ConnectionRole m_Role;
+       double m_Timestamp;
        double m_Seen;
        double m_NextHeartbeat;
        double m_HeartbeatTimeout;