Bugfix: duplicate Welcome messages

This commit is contained in:
Gunnar Beutner 2012-05-08 10:13:15 +02:00
parent 8a5e1423ca
commit 63e318383d
4 changed files with 32 additions and 16 deletions

View File

@ -198,12 +198,12 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
{ {
Endpoint::Ptr endpoint = nrea.Sender; Endpoint::Ptr endpoint = nrea.Sender;
if (endpoint->GetHandshakeCounter() >= 2) if (endpoint->GetReceivedWelcome())
return 0; return 0;
endpoint->IncrementHandshakeCounter(); endpoint->SetReceivedWelcome(true);
if (endpoint->GetHandshakeCounter() >= 2) { if (endpoint->GetSentWelcome()) {
EventArgs ea; EventArgs ea;
ea.Source = shared_from_this(); ea.Source = shared_from_this();
endpoint->OnSessionEstablished(ea); endpoint->OnSessionEstablished(ea);
@ -214,7 +214,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint) void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
{ {
if (endpoint->GetHandshakeCounter() >= 2) if (endpoint->GetSentWelcome())
return; return;
// we assume the other component _always_ wants // we assume the other component _always_ wants
@ -224,6 +224,8 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
request.SetMethod("discovery::Welcome"); request.SetMethod("discovery::Welcome");
GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, endpoint, request); GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, endpoint, request);
endpoint->SetSentWelcome(true);
ComponentDiscoveryInfo::Ptr info; ComponentDiscoveryInfo::Ptr info;
if (GetComponentDiscoveryInfo(endpoint->GetIdentity(), &info)) { if (GetComponentDiscoveryInfo(endpoint->GetIdentity(), &info)) {
@ -235,9 +237,7 @@ void DiscoveryComponent::FinishDiscoverySetup(Endpoint::Ptr endpoint)
endpoint->RegisterMethodSink(*i); endpoint->RegisterMethodSink(*i);
} }
endpoint->IncrementHandshakeCounter(); if (endpoint->GetReceivedWelcome()) {
if (endpoint->GetHandshakeCounter() >= 2) {
EventArgs ea; EventArgs ea;
ea.Source = shared_from_this(); ea.Source = shared_from_this();
endpoint->OnSessionEstablished(ea); endpoint->OnSessionEstablished(ea);
@ -417,6 +417,7 @@ int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea)
/* update LastSeen if we're still connected to this endpoint */ /* update LastSeen if we're still connected to this endpoint */
info->LastSeen = now; info->LastSeen = now;
} else { } else {
/* TODO: figure out whether we actually want to connect to this component (_always_ if IsBroker() == true) */
/* try and reconnect to this component */ /* try and reconnect to this component */
endpointManager->AddConnection(info->Node, info->Service); endpointManager->AddConnection(info->Node, info->Service);
} }

View File

@ -17,6 +17,6 @@
"kekslistener": { "replicate": "0", "service": "8888" } "kekslistener": { "replicate": "0", "service": "8888" }
}, },
"broker": { "broker": {
"icinga-c1": { "replicate": "0", "node": "127.0.0.1", "service": "7777" } "icinga-c1": { "replicate": "0", "node": "10.0.10.3", "service": "7777" }
} }
} }

View File

@ -4,7 +4,8 @@ using namespace icinga;
Endpoint::Endpoint(void) Endpoint::Endpoint(void)
{ {
m_HandshakeCounter = false; m_ReceivedWelcome = false;
m_SentWelcome = false;
} }
string Endpoint::GetIdentity(void) const string Endpoint::GetIdentity(void) const
@ -126,12 +127,22 @@ set<string>::const_iterator Endpoint::EndSources(void) const
return m_MethodSources.end(); 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;
}

View File

@ -17,7 +17,8 @@ private:
string m_Identity; string m_Identity;
set<string> m_MethodSinks; set<string> m_MethodSinks;
set<string> m_MethodSources; set<string> m_MethodSources;
unsigned short m_HandshakeCounter; bool m_ReceivedWelcome;
bool m_SentWelcome;
weak_ptr<EndpointManager> m_EndpointManager; weak_ptr<EndpointManager> m_EndpointManager;
@ -33,8 +34,11 @@ public:
void SetIdentity(string identity); void SetIdentity(string identity);
bool HasIdentity(void) const; bool HasIdentity(void) const;
void IncrementHandshakeCounter(); void SetReceivedWelcome(bool value);
unsigned short GetHandshakeCounter(void) const; bool GetReceivedWelcome(void) const;
void SetSentWelcome(bool value);
bool GetSentWelcome(void) const;
shared_ptr<EndpointManager> GetEndpointManager(void) const; shared_ptr<EndpointManager> GetEndpointManager(void) const;
void SetEndpointManager(weak_ptr<EndpointManager> manager); void SetEndpointManager(weak_ptr<EndpointManager> manager);