mirror of https://github.com/Icinga/icinga2.git
Close old connection when duplicate endpoints are found.
This commit is contained in:
parent
d55965c070
commit
415f1d39aa
|
@ -50,23 +50,23 @@ void Socket::Close(void)
|
||||||
|
|
||||||
void Socket::CloseInternal(bool from_dtor)
|
void Socket::CloseInternal(bool from_dtor)
|
||||||
{
|
{
|
||||||
if (m_FD != INVALID_SOCKET) {
|
if (m_FD == INVALID_SOCKET)
|
||||||
|
return;
|
||||||
|
|
||||||
closesocket(m_FD);
|
closesocket(m_FD);
|
||||||
m_FD = INVALID_SOCKET;
|
m_FD = INVALID_SOCKET;
|
||||||
|
|
||||||
/* nobody can possibly have a valid event subscription when the
|
/* nobody can possibly have a valid event subscription when the
|
||||||
destructor has been called */
|
destructor has been called */
|
||||||
if (!from_dtor) {
|
if (!from_dtor) {
|
||||||
|
Stop();
|
||||||
|
|
||||||
EventArgs ea;
|
EventArgs ea;
|
||||||
ea.Source = shared_from_this();
|
ea.Source = shared_from_this();
|
||||||
OnClosed(ea);
|
OnClosed(ea);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!from_dtor)
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Socket::HandleSocketError(void)
|
void Socket::HandleSocketError(void)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
|
@ -10,9 +10,6 @@
|
||||||
"configrpc": { "replicate": "0", "configSource": "1" },
|
"configrpc": { "replicate": "0", "configSource": "1" },
|
||||||
"demo": { "replicate": "0" }
|
"demo": { "replicate": "0" }
|
||||||
},
|
},
|
||||||
"rpcconnection": {
|
|
||||||
"kekslistener": { "replicate": "0", "hostname": "::1", "port": "7777" }
|
|
||||||
},
|
|
||||||
"rpclistener": {
|
"rpclistener": {
|
||||||
"kekslistener": { "replicate": "0", "port": "7777" }
|
"kekslistener": { "replicate": "0", "port": "7777" }
|
||||||
},
|
},
|
||||||
|
|
|
@ -33,11 +33,14 @@ int DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewE
|
||||||
if (endpoint == neea.Endpoint)
|
if (endpoint == neea.Endpoint)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
if (!neea.Endpoint->IsConnected())
|
||||||
Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting endpoint.");
|
return 0;
|
||||||
|
|
||||||
endpoint->Stop();
|
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
||||||
GetEndpointManager()->UnregisterEndpoint(endpoint);
|
Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
|
||||||
|
|
||||||
|
neea.Endpoint->Stop();
|
||||||
|
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -61,6 +64,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& neea)
|
||||||
GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, neea.Sender, request);
|
GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, neea.Sender, request);
|
||||||
|
|
||||||
/* TODO: send information about this client to all other clients */
|
/* TODO: send information about this client to all other clients */
|
||||||
|
/* TODO: send stored events for this client */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
virtual bool IsAllowedMethodSource(string method) const = 0;
|
virtual bool IsAllowedMethodSource(string method) const = 0;
|
||||||
|
|
||||||
virtual bool IsLocal(void) 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 ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message) = 0;
|
||||||
virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message) = 0;
|
virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message) = 0;
|
||||||
|
|
|
@ -201,8 +201,6 @@ int JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs&
|
||||||
|
|
||||||
void JsonRpcEndpoint::Stop(void)
|
void JsonRpcEndpoint::Stop(void)
|
||||||
{
|
{
|
||||||
if (m_Client) {
|
if (m_Client)
|
||||||
m_Client->Close();
|
m_Client->Close();
|
||||||
m_Client = JsonRpcClient::Ptr();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@ private:
|
||||||
string m_PeerHostname;
|
string m_PeerHostname;
|
||||||
unsigned short m_PeerPort;
|
unsigned short m_PeerPort;
|
||||||
|
|
||||||
bool IsConnected(void) const;
|
|
||||||
|
|
||||||
int NewMessageHandler(const NewMessageEventArgs& nmea);
|
int NewMessageHandler(const NewMessageEventArgs& nmea);
|
||||||
int ClientClosedHandler(const EventArgs& ea);
|
int ClientClosedHandler(const EventArgs& ea);
|
||||||
int ClientErrorHandler(const SocketErrorEventArgs& ea);
|
int ClientErrorHandler(const SocketErrorEventArgs& ea);
|
||||||
|
@ -47,6 +45,7 @@ public:
|
||||||
virtual bool IsAllowedMethodSource(string method) const;
|
virtual bool IsAllowedMethodSource(string method) const;
|
||||||
|
|
||||||
virtual bool IsLocal(void) const;
|
virtual bool IsLocal(void) const;
|
||||||
|
virtual bool IsConnected(void) const;
|
||||||
|
|
||||||
virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
|
virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
|
||||||
virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
|
virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
|
||||||
|
|
|
@ -14,6 +14,11 @@ bool VirtualEndpoint::IsLocal(void) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VirtualEndpoint::IsConnected(void) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void VirtualEndpoint::RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
|
void VirtualEndpoint::RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
|
||||||
{
|
{
|
||||||
m_MethodHandlers[method] += callback;
|
m_MethodHandlers[method] += callback;
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
virtual string GetAddress(void) const;
|
virtual string GetAddress(void) const;
|
||||||
|
|
||||||
virtual bool IsLocal(void) const;
|
virtual bool IsLocal(void) const;
|
||||||
|
virtual bool IsConnected(void) const;
|
||||||
|
|
||||||
virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
|
virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message);
|
||||||
virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
|
virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);
|
||||||
|
|
Loading…
Reference in New Issue