Skip to content

Commit

Permalink
Make sure we only have one connection per satellite
Browse files Browse the repository at this point in the history
refs #11014
  • Loading branch information
gunnarbeutner committed Feb 23, 2016
1 parent 5c23beb commit fbc638e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
28 changes: 25 additions & 3 deletions lib/remote/apilistener.cpp
Expand Up @@ -514,8 +514,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() << "': "
Expand Down Expand Up @@ -580,8 +591,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);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/remote/jsonrpcconnection.cpp
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/remote/jsonrpcconnection.hpp
Expand Up @@ -57,6 +57,7 @@ class I2_REMOTE_API JsonRpcConnection : public Object

void Start(void);

double GetTimestamp(void) const;
String GetIdentity(void) const;
bool IsAuthenticated(void) const;
Endpoint::Ptr GetEndpoint(void) const;
Expand All @@ -76,6 +77,7 @@ class I2_REMOTE_API JsonRpcConnection : public Object
Endpoint::Ptr m_Endpoint;
TlsStream::Ptr m_Stream;
ConnectionRole m_Role;
double m_Timestamp;
double m_Seen;
double m_NextHeartbeat;
double m_HeartbeatTimeout;
Expand Down

0 comments on commit fbc638e

Please sign in to comment.