From f49bb3d1503e7d75327270b091d78509034ef0bd Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 27 Aug 2013 12:21:41 +0200 Subject: [PATCH] Refactor JSON-RPC library and implement check-result messages. --- components/Makefile.am | 1 + components/checker/Makefile.am | 1 - components/checker/checkercomponent.h | 1 - components/cluster/.gitignore | 1 + .../cluster}/Makefile.am | 32 +- .../cluster/cluster-type.conf | 22 +- .../cluster/cluster.vcxproj | 135 +++--- components/cluster/cluster.vcxproj.filters | 32 ++ components/cluster/clustercomponent.cpp | 316 ++++++++++++++ .../cluster/clustercomponent.h | 81 ++-- .../cluster}/endpoint.cpp | 11 +- .../cluster}/endpoint.h | 5 +- .../cluster}/jsonrpc.cpp | 2 +- .../remoting => components/cluster}/jsonrpc.h | 5 +- components/compat/Makefile.am | 1 - components/compat/checkresultreader.h | 1 - components/compat/compatlog.h | 1 - components/demo/Makefile.am | 1 - components/demo/democomponent.cpp | 1 - components/demo/democomponent.h | 2 +- components/ido_mysql/Makefile.am | 1 - components/livestatus/Makefile.am | 1 - components/notification/Makefile.am | 1 - configure.ac | 2 +- contrib/config/osmc2012/icinga-c1.pem | 14 +- contrib/config/osmc2012/icinga-c2.pem | 12 +- contrib/config/osmc2012/icinga-c3.pem | 27 +- contrib/gdb/icingadbg.py | 23 +- lib/Makefile.am | 1 - lib/base/array.cpp | 44 -- lib/base/array.h | 6 - lib/base/bufferedstream.cpp | 20 +- lib/base/bufferedstream.h | 5 +- lib/base/dictionary.cpp | 41 -- lib/base/dictionary.h | 6 - lib/base/dynamicobject.cpp | 2 +- lib/base/fifo.cpp | 5 + lib/base/fifo.h | 1 + lib/base/networkstream.cpp | 14 +- lib/base/networkstream.h | 3 + lib/base/stdiostream.cpp | 5 + lib/base/stdiostream.h | 2 + lib/base/stream.h | 7 + lib/base/stream_bio.cpp | 2 +- lib/base/tlsstream.cpp | 5 + lib/base/tlsstream.h | 2 + lib/config/configitem.cpp | 2 - lib/icinga/Makefile.am | 3 +- lib/icinga/icinga-type.conf | 4 - lib/icinga/icingaapplication.cpp | 64 +-- lib/icinga/icingaapplication.h | 12 - lib/icinga/notification.cpp | 1 - lib/icinga/service-check.cpp | 3 - lib/ido/Makefile.am | 1 - lib/python/Makefile.am | 3 +- lib/remoting/.gitignore | 1 - lib/remoting/endpointmanager.cpp | 411 ------------------ lib/remoting/i2-remoting.h | 38 -- lib/remoting/remoting.vcxproj.filters | 58 --- 59 files changed, 604 insertions(+), 901 deletions(-) create mode 100644 components/cluster/.gitignore rename {lib/remoting => components/cluster}/Makefile.am (52%) rename lib/remoting/remoting-type.conf => components/cluster/cluster-type.conf (82%) rename lib/remoting/remoting.vcxproj => components/cluster/cluster.vcxproj (76%) create mode 100644 components/cluster/cluster.vcxproj.filters create mode 100644 components/cluster/clustercomponent.cpp rename lib/remoting/endpointmanager.h => components/cluster/clustercomponent.h (66%) rename {lib/remoting => components/cluster}/endpoint.cpp (95%) rename {lib/remoting => components/cluster}/endpoint.h (95%) rename {lib/remoting => components/cluster}/jsonrpc.cpp (98%) rename {lib/remoting => components/cluster}/jsonrpc.h (95%) delete mode 100644 lib/remoting/.gitignore delete mode 100644 lib/remoting/endpointmanager.cpp delete mode 100644 lib/remoting/i2-remoting.h delete mode 100644 lib/remoting/remoting.vcxproj.filters diff --git a/components/Makefile.am b/components/Makefile.am index 6b78c486f..4564ae736 100644 --- a/components/Makefile.am +++ b/components/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = \ checker \ + cluster \ compat \ demo \ ido_mysql \ diff --git a/components/checker/Makefile.am b/components/checker/Makefile.am index 566d18b00..514ab5a3b 100644 --- a/components/checker/Makefile.am +++ b/components/checker/Makefile.am @@ -33,5 +33,4 @@ libchecker_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index d7fb22de6..c16f18508 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -21,7 +21,6 @@ #define CHECKERCOMPONENT_H #include "icinga/service.h" -#include "remoting/endpoint.h" #include "base/dynamicobject.h" #include "base/timer.h" #include diff --git a/components/cluster/.gitignore b/components/cluster/.gitignore new file mode 100644 index 000000000..f180b9c43 --- /dev/null +++ b/components/cluster/.gitignore @@ -0,0 +1 @@ +cluster-type.cpp diff --git a/lib/remoting/Makefile.am b/components/cluster/Makefile.am similarity index 52% rename from lib/remoting/Makefile.am rename to components/cluster/Makefile.am index dc15e18d7..90406efb8 100644 --- a/lib/remoting/Makefile.am +++ b/components/cluster/Makefile.am @@ -1,36 +1,40 @@ ## Process this file with automake to produce Makefile.in - pkglib_LTLIBRARIES = \ - libremoting.la + libcluster.la + +EXTRA_DIST = \ + cluster-type.conf .conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig.c $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@ -libremoting_la_SOURCES = \ +libcluster_la_SOURCES = \ + clustercomponent.cpp \ + clustercomponent.h \ + cluster-type.cpp \ endpoint.cpp \ endpoint.h \ - endpointmanager.cpp \ - endpointmanager.h \ - i2-remoting.h \ jsonrpc.cpp \ - jsonrpc.h \ - remoting-type.cpp + jsonrpc.h -libremoting_la_CPPFLAGS = \ - -DI2_REMOTING_BUILD \ +libcluster_la_CPPFLAGS = \ $(LTDLINCL) \ $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib + -I${top_srcdir}/lib \ + -I${top_srcdir}/components -libremoting_la_LDFLAGS = \ +libcluster_la_LDFLAGS = \ $(BOOST_LDFLAGS) \ + -module \ -no-undefined \ @RELEASE_INFO@ \ @VERSION_INFO@ -libremoting_la_LIBADD = \ +libcluster_la_LIBADD = \ + $(BOOST_SIGNALS_LIB) \ $(BOOST_THREAD_LIB) \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ - ${top_builddir}/lib/config/libconfig.la + ${top_builddir}/lib/config/libconfig.la \ + ${top_builddir}/lib/icinga/libicinga.la diff --git a/lib/remoting/remoting-type.conf b/components/cluster/cluster-type.conf similarity index 82% rename from lib/remoting/remoting-type.conf rename to components/cluster/cluster-type.conf index 5eab4660c..dfb9dd7bf 100644 --- a/lib/remoting/remoting-type.conf +++ b/components/cluster/cluster-type.conf @@ -17,8 +17,22 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -type Endpoint { - %attribute string "node", - %attribute string "service", - %attribute number "local" +type ClusterComponent { + %attribute string "cert_path", + %require "cert_path", + + %attribute string "ca_path", + %require "ca_path", + + %attribute string "bind_host", + %attribute string "bind_port", + + %attribute array "peers" { + %attribute string "*" + } +} + +type Endpoint { + %attribute string "host", + %attribute string "port" } diff --git a/lib/remoting/remoting.vcxproj b/components/cluster/cluster.vcxproj similarity index 76% rename from lib/remoting/remoting.vcxproj rename to components/cluster/cluster.vcxproj index f3dba42f3..fcf55e5d2 100644 --- a/lib/remoting/remoting.vcxproj +++ b/components/cluster/cluster.vcxproj @@ -18,54 +18,10 @@ x64 - - - - - - - - - - - - - - - NotUsing - NotUsing - NotUsing - NotUsing - - - - - - - - Document - "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" - Preparing config fragment for embedding - "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" - Preparing config fragment for embedding - "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" - Preparing config fragment for embedding - "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" - Preparing config fragment for embedding - %(Filename).cpp;%(Outputs) - %(Filename).cpp;%(Outputs) - %(Filename).cpp;%(Outputs) - %(Filename).cpp;%(Outputs) - $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c - $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c - $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c - $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c - - - {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} + {2E6C1133-730F-4875-A72C-B455B1DD4C5C} Win32Proj - icinga + demo @@ -107,119 +63,130 @@ - $(SolutionDir)\lib;$(IncludePath) + true + $(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath) $(SolutionDir)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ - $(SolutionDir)\lib;$(IncludePath) + true + $(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath) $(SolutionDir)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ - $(SolutionDir)\lib;$(IncludePath) + false + $(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath) $(SolutionDir)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ - $(SolutionDir)\lib;$(IncludePath) + false + $(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath) $(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath) $(SolutionDir)$(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ - NotUsing Disabled - _DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;I2_REMOTING_BUILD;%(PreprocessorDefinitions) + _DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Level3 false - i2-remoting.h true + NotUsing Windows true - base.lib;config.lib;%(AdditionalDependencies) + base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies) - - - - - NotUsing Disabled - _DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;I2_REMOTING_BUILD;%(PreprocessorDefinitions) + _DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions) Level3 false - i2-remoting.h true + NotUsing Windows true - base.lib;config.lib;%(AdditionalDependencies) + base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies) - - - - - NotUsing MaxSpeed true true - NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;I2_REMOTING_BUILD;%(PreprocessorDefinitions) - Speed + NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Level3 false - i2-remoting.h true + NotUsing Windows true true true - base.lib;config.lib;%(AdditionalDependencies) + base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies) - - - - - NotUsing MaxSpeed true true - NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;I2_REMOTING_BUILD;%(PreprocessorDefinitions) - Speed + NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Level3 false - i2-remoting.h true + NotUsing Windows true true true - base.lib;config.lib;%(AdditionalDependencies) + base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies) - - - - + + + + + + + + + + + Document + "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" + Preparing config fragment for embedding + "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" + Preparing config fragment for embedding + "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" + Preparing config fragment for embedding + "$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp" + Preparing config fragment for embedding + %(Filename).cpp;%(Outputs) + %(Filename).cpp;%(Outputs) + %(Filename).cpp;%(Outputs) + %(Filename).cpp;%(Outputs) + $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c + $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c + $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c + $(SolutionDir)\tools\mkembedconfig\mkembedconfig.c + + diff --git a/components/cluster/cluster.vcxproj.filters b/components/cluster/cluster.vcxproj.filters new file mode 100644 index 000000000..922435a52 --- /dev/null +++ b/components/cluster/cluster.vcxproj.filters @@ -0,0 +1,32 @@ + + + + + Headerdateien + + + Headerdateien + + + + + {11a495bf-a705-4766-b3d3-9b5db266a6ef} + + + {1fb6337f-a17f-46ea-9316-2d800a94b53d} + + + + + Quelldateien + + + Quelldateien + + + + + Quelldateien + + + \ No newline at end of file diff --git a/components/cluster/clustercomponent.cpp b/components/cluster/clustercomponent.cpp new file mode 100644 index 000000000..2bd7d298d --- /dev/null +++ b/components/cluster/clustercomponent.cpp @@ -0,0 +1,316 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#include "cluster/clustercomponent.h" +#include "cluster/endpoint.h" +#include "base/dynamictype.h" +#include "base/logger_fwd.h" +#include "base/objectlock.h" +#include "base/networkstream.h" +#include + +using namespace icinga; + +REGISTER_TYPE(ClusterComponent); + +/** + * Starts the component. + */ +void ClusterComponent::Start(void) +{ + DynamicObject::Start(); + + /* set up SSL context */ + shared_ptr cert = GetX509Certificate(GetCertificateFile()); + m_Identity = GetCertificateCN(cert); + Log(LogInformation, "cluster", "My identity: " + m_Identity); + + m_SSLContext = MakeSSLContext(GetCertificateFile(), GetCertificateFile(), GetCAFile()); + + /* create the primary JSON-RPC listener */ + if (!GetBindPort().IsEmpty()) + AddListener(GetBindPort()); + + m_ReconnectTimer = boost::make_shared(); + m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&ClusterComponent::ReconnectTimerHandler, this)); + m_ReconnectTimer->SetInterval(5); + m_ReconnectTimer->Start(); + + Service::OnNewCheckResult.connect(bind(&ClusterComponent::CheckResultHandler, this, _1, _2)); + Endpoint::OnMessageReceived.connect(bind(&ClusterComponent::MessageHandler, this, _1, _2)); +} + +/** + * Stops the component. + */ +void ClusterComponent::Stop(void) +{ + /* Nothing to do here. */ +} + +String ClusterComponent::GetCertificateFile(void) const +{ + ObjectLock olock(this); + + return m_CertPath; +} + +String ClusterComponent::GetCAFile(void) const +{ + ObjectLock olock(this); + + return m_CAPath; +} + +String ClusterComponent::GetBindHost(void) const +{ + ObjectLock olock(this); + + return m_BindHost; +} + +String ClusterComponent::GetBindPort(void) const +{ + ObjectLock olock(this); + + return m_BindPort; +} + +Array::Ptr ClusterComponent::GetPeers(void) const +{ + ObjectLock olock(this); + + return m_Peers; +} + +shared_ptr ClusterComponent::GetSSLContext(void) const +{ + ObjectLock olock(this); + + return m_SSLContext; +} + +String ClusterComponent::GetIdentity(void) const +{ + ObjectLock olock(this); + + return m_Identity; +} + +/** + * Creates a new JSON-RPC listener on the specified port. + * + * @param service The port to listen on. + */ +void ClusterComponent::AddListener(const String& service) +{ + ObjectLock olock(this); + + shared_ptr sslContext = m_SSLContext; + + if (!sslContext) + BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddListener()")); + + std::ostringstream s; + s << "Adding new listener: port " << service; + Log(LogInformation, "cluster", s.str()); + + TcpSocket::Ptr server = boost::make_shared(); + server->Bind(service, AF_INET6); + + boost::thread thread(boost::bind(&ClusterComponent::ListenerThreadProc, this, server)); + thread.detach(); + + m_Servers.insert(server); +} + +void ClusterComponent::ListenerThreadProc(const Socket::Ptr& server) +{ + server->Listen(); + + for (;;) { + Socket::Ptr client = server->Accept(); + + try { + NewClientHandler(client, TlsRoleServer); + } catch (const std::exception& ex) { + std::stringstream message; + message << "Error for new JSON-RPC socket: " << boost::diagnostic_information(ex); + Log(LogInformation, "cluster", message.str()); + } + } +} + +/** + * Creates a new JSON-RPC client and connects to the specified host and port. + * + * @param node The remote host. + * @param service The remote port. + */ +void ClusterComponent::AddConnection(const String& node, const String& service) { + { + ObjectLock olock(this); + + shared_ptr sslContext = m_SSLContext; + + if (!sslContext) + BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddConnection()")); + } + + TcpSocket::Ptr client = boost::make_shared(); + + try { + client->Connect(node, service); + NewClientHandler(client, TlsRoleClient); + } catch (const std::exception& ex) { + Log(LogInformation, "cluster", "Could not connect to " + node + ":" + service + ": " + ex.what()); + } +} + +/** + * Processes a new client connection. + * + * @param client The new client. + */ +void ClusterComponent::NewClientHandler(const Socket::Ptr& client, TlsRole role) +{ + NetworkStream::Ptr netStream = boost::make_shared(client); + + TlsStream::Ptr tlsStream = boost::make_shared(netStream, role, m_SSLContext); + tlsStream->Handshake(); + + shared_ptr cert = tlsStream->GetPeerCertificate(); + String identity = GetCertificateCN(cert); + + Log(LogInformation, "cluster", "New client connection for identity '" + identity + "'"); + + Endpoint::Ptr endpoint = Endpoint::GetByName(identity); + + if (!endpoint) { + Log(LogInformation, "cluster", "Closing endpoint '" + identity + "': No configuration available."); + tlsStream->Close(); + return; + } + + endpoint->SetClient(tlsStream); +} + +void ClusterComponent::ReconnectTimerHandler(void) +{ + Array::Ptr peers = GetPeers(); + + if (!peers) + return; + + ObjectLock olock(peers); + BOOST_FOREACH(const String& peer, peers) { + Endpoint::Ptr endpoint = Endpoint::GetByName(peer); + + if (!endpoint) + continue; + + if (endpoint->IsConnected()) + continue; + + String host, port; + host = endpoint->GetHost(); + port = endpoint->GetPort(); + + if (host.IsEmpty() || port.IsEmpty()) { + Log(LogWarning, "cluster", "Can't reconnect " + "to endpoint '" + endpoint->GetName() + "': No " + "host/port information."); + continue; + } + + Log(LogInformation, "cluster", "Attempting to reconnect to cluster endpoint '" + endpoint->GetName() + "' via '" + host + ":" + port + "'."); + AddConnection(host, port); + } +} + +void ClusterComponent::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr) +{ + if (cr->Contains("source") && cr->Get("source") != GetIdentity()) + return; + + cr->Set("source", GetIdentity()); + + Dictionary::Ptr params = boost::make_shared(); + params->Set("service", service->GetName()); + params->Set("check_result", cr); + + Dictionary::Ptr message = boost::make_shared(); + message->Set("jsonrpc", "2.0"); + message->Set("method", "cluster::CheckResult"); + message->Set("params", params); + + BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { + endpoint->SendMessage(message); + } +} + +void ClusterComponent::MessageHandler(const Endpoint::Ptr& endpoint, const Dictionary::Ptr& message) +{ + if (message->Get("method") == "cluster::CheckResult") { + Dictionary::Ptr params = message->Get("params"); + + if (!params) + return; + + Dictionary::Ptr cr = params->Get("check_result"); + + if (!cr) + return; + + String svc = params->Get("service"); + + Service::Ptr service = Service::GetByName(svc); + + if (!service) + return; + + service->ProcessCheckResult(cr); + } +} + +void ClusterComponent::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const +{ + DynamicObject::InternalSerialize(bag, attributeTypes); + + if (attributeTypes & Attribute_Config) { + bag->Set("cert_path", m_CertPath); + bag->Set("ca_path", m_CAPath); + bag->Set("bind_host", m_BindHost); + bag->Set("bind_port", m_BindPort); + bag->Set("peers", m_Peers); + } +} + +void ClusterComponent::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) +{ + DynamicObject::InternalDeserialize(bag, attributeTypes); + + if (attributeTypes & Attribute_Config) { + m_CertPath = bag->Get("cert_path"); + m_CAPath = bag->Get("ca_path"); + m_BindHost = bag->Get("bind_host"); + m_BindPort = bag->Get("bind_port"); + m_Peers = bag->Get("peers"); + } +} diff --git a/lib/remoting/endpointmanager.h b/components/cluster/clustercomponent.h similarity index 66% rename from lib/remoting/endpointmanager.h rename to components/cluster/clustercomponent.h index 7fa5d6653..06b752c97 100644 --- a/lib/remoting/endpointmanager.h +++ b/components/cluster/clustercomponent.h @@ -17,68 +17,73 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef ENDPOINTMANAGER_H -#define ENDPOINTMANAGER_H +#ifndef CLUSTERCOMPONENT_H +#define CLUSTERCOMPONENT_H -#include "remoting/i2-remoting.h" -#include "remoting/endpoint.h" +#include "base/dynamicobject.h" +#include "base/timer.h" +#include "base/array.h" #include "base/tcpsocket.h" #include "base/tlsstream.h" -#include "base/timer.h" #include "base/utility.h" -#include +#include "base/tlsutility.h" +#include "icinga/service.h" +#include "cluster/endpoint.h" namespace icinga { /** - * Forwards messages between endpoints. - * - * @ingroup remoting + * @ingroup demo */ -class I2_REMOTING_API EndpointManager : public Object +class ClusterComponent : public DynamicObject { public: - DECLARE_PTR_TYPEDEFS(EndpointManager); + DECLARE_PTR_TYPEDEFS(ClusterComponent); + DECLARE_TYPENAME(ClusterComponent); - EndpointManager(void); + virtual void Start(void); + virtual void Stop(void); - static EndpointManager *GetInstance(void); + String GetCertificateFile(void) const; + String GetCAFile(void) const; + String GetBindHost(void) const; + String GetBindPort(void) const; + Array::Ptr GetPeers(void) const; - void SetIdentity(const String& identity); + shared_ptr GetSSLContext(void) const; String GetIdentity(void) const; - void SetSSLContext(const shared_ptr& sslContext); - shared_ptr GetSSLContext(void) const; +protected: + virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const; + virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); + +private: + String m_CertPath; + String m_CAPath; + String m_BindHost; + String m_BindPort; + Array::Ptr m_Peers; + + shared_ptr m_SSLContext; + String m_Identity; + + Timer::Ptr m_ReconnectTimer; + void ReconnectTimerHandler(void); + + std::set m_Servers; void AddListener(const String& service); void AddConnection(const String& node, const String& service); - //void SendUnicastMessage(const Endpoint::Ptr& recipient, const Dictionary::Ptr& message); - //void SendUnicastMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, const MessagePart& message); - //void SendAnycastMessage(const Endpoint::Ptr& sender, const RequestMessage& message); - //void SendMulticastMessage(const RequestMessage& message); - //void SendMulticastMessage(const Endpoint::Ptr& sender, const RequestMessage& message); - - boost::signals2::signal OnNewEndpoint; - -private: - String m_Identity; - Endpoint::Ptr m_Endpoint; - - shared_ptr m_SSLContext; - - Timer::Ptr m_ReconnectTimer; - - std::set m_Servers; - - void ReconnectTimerHandler(void); - void NewClientHandler(const Socket::Ptr& client, TlsRole role); - void ListenerThreadProc(const Socket::Ptr& server); + + void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr); + void MessageHandler(const Endpoint::Ptr& endpoint, const Dictionary::Ptr& message); + }; } -#endif /* ENDPOINTMANAGER_H */ +#endif /* CLUSTERCOMPONENT_H */ diff --git a/lib/remoting/endpoint.cpp b/components/cluster/endpoint.cpp similarity index 95% rename from lib/remoting/endpoint.cpp rename to components/cluster/endpoint.cpp index c6d5c1f5c..5194837e2 100644 --- a/lib/remoting/endpoint.cpp +++ b/components/cluster/endpoint.cpp @@ -17,9 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "remoting/endpoint.h" -#include "remoting/endpointmanager.h" -#include "remoting/jsonrpc.h" +#include "cluster/endpoint.h" +#include "cluster/jsonrpc.h" #include "base/application.h" #include "base/dynamictype.h" #include "base/objectlock.h" @@ -78,7 +77,7 @@ void Endpoint::SendMessage(const Dictionary::Ptr& message) } catch (const std::exception& ex) { std::ostringstream msgbuf; msgbuf << "Error while sending JSON-RPC message for endpoint '" << GetName() << "': " << boost::diagnostic_information(ex); - Log(LogWarning, "remoting", msgbuf.str()); + Log(LogWarning, "cluster", msgbuf.str()); m_Client.reset(); } @@ -92,9 +91,11 @@ void Endpoint::MessageThreadProc(const Stream::Ptr& stream) try { message = JsonRpc::ReadMessage(stream); } catch (const std::exception& ex) { - Log(LogWarning, "jsonrpc", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + boost::diagnostic_information(ex)); + Log(LogWarning, "cluster", "Error while reading JSON-RPC message for endpoint '" + GetName() + "': " + boost::diagnostic_information(ex)); m_Client.reset(); + + return; } Utility::QueueAsyncCallback(bind(boost::ref(Endpoint::OnMessageReceived), GetSelf(), message)); diff --git a/lib/remoting/endpoint.h b/components/cluster/endpoint.h similarity index 95% rename from lib/remoting/endpoint.h rename to components/cluster/endpoint.h index 22899ed35..834ae0b59 100644 --- a/lib/remoting/endpoint.h +++ b/components/cluster/endpoint.h @@ -20,7 +20,6 @@ #ifndef ENDPOINT_H #define ENDPOINT_H -#include "remoting/i2-remoting.h" #include "base/dynamicobject.h" #include "base/stream.h" #include @@ -33,9 +32,9 @@ class EndpointManager; /** * An endpoint that can be used to send and receive messages. * - * @ingroup remoting + * @ingroup cluster */ -class I2_REMOTING_API Endpoint : public DynamicObject +class Endpoint : public DynamicObject { public: DECLARE_PTR_TYPEDEFS(Endpoint); diff --git a/lib/remoting/jsonrpc.cpp b/components/cluster/jsonrpc.cpp similarity index 98% rename from lib/remoting/jsonrpc.cpp rename to components/cluster/jsonrpc.cpp index 73e9f1003..2cc19f828 100644 --- a/lib/remoting/jsonrpc.cpp +++ b/components/cluster/jsonrpc.cpp @@ -17,7 +17,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#include "remoting/jsonrpc.h" +#include "cluster/jsonrpc.h" #include "base/netstring.h" #include "base/objectlock.h" #include "base/logger_fwd.h" diff --git a/lib/remoting/jsonrpc.h b/components/cluster/jsonrpc.h similarity index 95% rename from lib/remoting/jsonrpc.h rename to components/cluster/jsonrpc.h index ece2c096a..e849c94f2 100644 --- a/lib/remoting/jsonrpc.h +++ b/components/cluster/jsonrpc.h @@ -20,7 +20,6 @@ #ifndef JSONRPC_H #define JSONRPC_H -#include "remoting/i2-remoting.h" #include "base/stream.h" #include "base/dictionary.h" @@ -30,9 +29,9 @@ namespace icinga /** * A JSON-RPC connection. * - * @ingroup remoting + * @ingroup cluster */ -class I2_REMOTING_API JsonRpc +class JsonRpc { public: static void SendMessage(const Stream::Ptr& stream, const Dictionary::Ptr& message); diff --git a/components/compat/Makefile.am b/components/compat/Makefile.am index 02d40d333..590da329a 100644 --- a/components/compat/Makefile.am +++ b/components/compat/Makefile.am @@ -37,5 +37,4 @@ libcompat_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la diff --git a/components/compat/checkresultreader.h b/components/compat/checkresultreader.h index a46b98868..7c818d0d5 100644 --- a/components/compat/checkresultreader.h +++ b/components/compat/checkresultreader.h @@ -20,7 +20,6 @@ #ifndef CHECKRESULTREADER_H #define CHECKRESULTREADER_H -#include "remoting/endpoint.h" #include "base/dynamicobject.h" #include "base/timer.h" #include diff --git a/components/compat/compatlog.h b/components/compat/compatlog.h index d3f73a678..67adebac6 100644 --- a/components/compat/compatlog.h +++ b/components/compat/compatlog.h @@ -21,7 +21,6 @@ #define COMPATLOG_H #include "icinga/service.h" -#include "remoting/endpoint.h" #include "base/dynamicobject.h" #include "base/timer.h" #include diff --git a/components/demo/Makefile.am b/components/demo/Makefile.am index 30fd414f2..7a1f5363f 100644 --- a/components/demo/Makefile.am +++ b/components/demo/Makefile.am @@ -33,5 +33,4 @@ libdemo_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp index d0bab2580..af592fa2a 100644 --- a/components/demo/democomponent.cpp +++ b/components/demo/democomponent.cpp @@ -18,7 +18,6 @@ ******************************************************************************/ #include "demo/democomponent.h" -#include "remoting/endpointmanager.h" #include "base/dynamictype.h" #include "base/logger_fwd.h" #include diff --git a/components/demo/democomponent.h b/components/demo/democomponent.h index ea78933c6..f4990f1e4 100644 --- a/components/demo/democomponent.h +++ b/components/demo/democomponent.h @@ -20,7 +20,6 @@ #ifndef DEMOCOMPONENT_H #define DEMOCOMPONENT_H -#include "remoting/endpoint.h" #include "base/dynamicobject.h" #include "base/timer.h" @@ -34,6 +33,7 @@ class DemoComponent : public DynamicObject { public: DECLARE_PTR_TYPEDEFS(DemoComponent); + DECLARE_TYPENAME(DemoComponent); virtual void Start(void); virtual void Stop(void); diff --git a/components/ido_mysql/Makefile.am b/components/ido_mysql/Makefile.am index 65ee462f1..058909d1f 100644 --- a/components/ido_mysql/Makefile.am +++ b/components/ido_mysql/Makefile.am @@ -36,7 +36,6 @@ libido_mysql_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la \ ${top_builddir}/lib/ido/libido.la diff --git a/components/livestatus/Makefile.am b/components/livestatus/Makefile.am index 4fdd7939c..8af321a16 100644 --- a/components/livestatus/Makefile.am +++ b/components/livestatus/Makefile.am @@ -93,5 +93,4 @@ liblivestatus_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la diff --git a/components/notification/Makefile.am b/components/notification/Makefile.am index a9bfbad5d..4c525af9b 100644 --- a/components/notification/Makefile.am +++ b/components/notification/Makefile.am @@ -33,5 +33,4 @@ libnotification_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la diff --git a/configure.ac b/configure.ac index 6df0855f5..26c39a9b9 100644 --- a/configure.ac +++ b/configure.ac @@ -123,6 +123,7 @@ AC_CONFIG_FILES([ Makefile components/Makefile components/checker/Makefile +components/cluster/Makefile components/compat/Makefile components/demo/Makefile components/ido_mysql/Makefile @@ -141,7 +142,6 @@ lib/config/Makefile lib/icinga/Makefile lib/ido/Makefile lib/python/Makefile -lib/remoting/Makefile test/Makefile third-party/Makefile third-party/cJSON/Makefile diff --git a/contrib/config/osmc2012/icinga-c1.pem b/contrib/config/osmc2012/icinga-c1.pem index 0a2ac331f..4e16a5d37 100644 --- a/contrib/config/osmc2012/icinga-c1.pem +++ b/contrib/config/osmc2012/icinga-c1.pem @@ -1,8 +1,8 @@ -----BEGIN CERTIFICATE----- MIICtzCCAiCgAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJERTEQ MA4GA1UECAwHQmF2YXJpYTESMBAGA1UEBwwJTnVyZW1iZXJnMRUwEwYDVQQKDAxO -RVRXQVlTIEdtYkgxHDAaBgNVBAMME0ljaW5nYSBTbmFrZSBPaWwgQ0EwHhcNMTIw -NDI0MTE0NzQ2WhcNMTMwNDI0MTE0NzQ2WjBeMQswCQYDVQQGEwJERTEQMA4GA1UE +RVRXQVlTIEdtYkgxHDAaBgNVBAMME0ljaW5nYSBTbmFrZSBPaWwgQ0EwHhcNMTMw +ODI3MDcyNTE0WhcNMjMwODI1MDcyNTE0WjBeMQswCQYDVQQGEwJERTEQMA4GA1UE CAwHQmF2YXJpYTESMBAGA1UEBwwJTnVyZW1iZXJnMRUwEwYDVQQKDAxORVRXQVlT IEdtYkgxEjAQBgNVBAMMCWljaW5nYS1jMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAw gYkCgYEAysHrzHs9WfQR4cEUx2hFZQmbM+Ssi5L63yqnzxEvVQ3GlM+uIceK1Kvx @@ -10,10 +10,10 @@ gYkCgYEAysHrzHs9WfQR4cEUx2hFZQmbM+Ssi5L63yqnzxEvVQ3GlM+uIceK1Kvx CP3s5yC7ZZ6bDiPMhRi/TRvY6+uQf+yew5daA3p87jocgRjhRicCAwEAAaN7MHkw CQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2Vy dGlmaWNhdGUwHQYDVR0OBBYEFPzsYbQZdbq+pcFJWoenWREW6WhMMB8GA1UdIwQY -MBaAFNVJHVPJNwqEcG51lpqZJWVPaysFMA0GCSqGSIb3DQEBBQUAA4GBAMLP1GJf -0hFdrEpGq+NvxTVx7wD30enAot5x2HLx4HuFohQJz/VZ45v+srrA+HEXbBFXPOd4 -nB2XtcDDidFKTt5E03HBwDGGZvnB3f1KXYi7B50imKrwVVzgp5nGBM4hSzWGovEX -EYofmhk0fQg9qiKQrjwNib/4/b0srwEswfdj +MBaAFNVJHVPJNwqEcG51lpqZJWVPaysFMA0GCSqGSIb3DQEBBQUAA4GBAKYB6Cds +jJh20DMXKXklftqNPiGcPjnwpka5u/ys//rkgzjYnLiE9jkP5d32JtQbEqUY9gqN +Ngu2HeHE4hGrbgvCj0aPepzJY3RvxIJwvX7nuKHjSitKwOsQYsOkTjTfOyhI8kSN +nOGsDr4xpMX/iJL3Q1O9MwVRseKF8s9U+zjV -----END CERTIFICATE----- -----BEGIN PRIVATE KEY----- MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMrB68x7PVn0EeHB @@ -30,4 +30,4 @@ WLEQa8UZ5enQeOcKCTudgn7fWIUxAkEAmXWfXP6YZXVzvR+xt08225aEvTItEbKM krFJNlLe4aNb1Hp6lO5ALnk6vDq8wSKZqGIFHBtq6vHNZFiix+xO8QJAIZ3pB/Bz Il8NjZMg8t/1sJdn32Xe9D0lZRtZTKC8zF/78NDFEo9qqE4Sr1CUfqlx18HXOxCO Vg4lv6+jUj+LmA== ------END PRIVATE KEY----- \ No newline at end of file +-----END PRIVATE KEY----- diff --git a/contrib/config/osmc2012/icinga-c2.pem b/contrib/config/osmc2012/icinga-c2.pem index c7a50fe5a..ea7a8913d 100644 --- a/contrib/config/osmc2012/icinga-c2.pem +++ b/contrib/config/osmc2012/icinga-c2.pem @@ -1,8 +1,8 @@ -----BEGIN CERTIFICATE----- MIICtzCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJERTEQ MA4GA1UECAwHQmF2YXJpYTESMBAGA1UEBwwJTnVyZW1iZXJnMRUwEwYDVQQKDAxO -RVRXQVlTIEdtYkgxHDAaBgNVBAMME0ljaW5nYSBTbmFrZSBPaWwgQ0EwHhcNMTIw -NDI0MTE0NzU1WhcNMTMwNDI0MTE0NzU1WjBeMQswCQYDVQQGEwJERTEQMA4GA1UE +RVRXQVlTIEdtYkgxHDAaBgNVBAMME0ljaW5nYSBTbmFrZSBPaWwgQ0EwHhcNMTMw +ODI3MDcyNTQwWhcNMjMwODI1MDcyNTQwWjBeMQswCQYDVQQGEwJERTEQMA4GA1UE CAwHQmF2YXJpYTESMBAGA1UEBwwJTnVyZW1iZXJnMRUwEwYDVQQKDAxORVRXQVlT IEdtYkgxEjAQBgNVBAMMCWljaW5nYS1jMjCBnzANBgkqhkiG9w0BAQEFAAOBjQAw gYkCgYEArOcVui1AWojbPuK/7We9uwIBLaOLfBxQRI3+k6PzzjdtaXT4ijT/DSav @@ -10,10 +10,10 @@ Q5U4wGOLYh0yuSyqS88QX/DsqDGLXnSVs8mT37bioMOw2XinqaNQ6xK4vyi0FYxS ewI6YOkYi7135NEaSUgd82hk4wFtiIb67T7hkHRc7Aui6FmT/SkCAwEAAaN7MHkw CQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2Vy dGlmaWNhdGUwHQYDVR0OBBYEFGvpolD5na6L70kNFO1tYGYIwDhqMB8GA1UdIwQY -MBaAFNVJHVPJNwqEcG51lpqZJWVPaysFMA0GCSqGSIb3DQEBBQUAA4GBAIhhjKWw -5JKirNidgG9PuD8x47VsRTkESLlq/pS7KjkE1nWCG9JpR5oVSzx2WXomiaAZ4q2C -WS1z4HD9HF4NbhY+xVBi0Fj/kotuXCCweRo5EVp7Q4fabm1maJemFwMTHGhBLu7a -v4dquYyOk9Dhkwcjajyn+KWceCoUTdI3LB2t +MBaAFNVJHVPJNwqEcG51lpqZJWVPaysFMA0GCSqGSIb3DQEBBQUAA4GBAFLLI1Il +q6SRYcsFGHw+mAA2Uw1ySAlpDQUS6GFcWjMKTaIMgzBDBVJixo8TsuajURXUlDsh +mKqpHdOsl5zU/KZHufn5sI1QrDTrUPMt8PqCqwmEoykgbbbxl/913HJ5XKDyzL/p +Pq8b9sMlI601pOQGFI939WueGgfOc4WRdlMS -----END CERTIFICATE----- -----BEGIN PRIVATE KEY----- MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKznFbotQFqI2z7i diff --git a/contrib/config/osmc2012/icinga-c3.pem b/contrib/config/osmc2012/icinga-c3.pem index dfa78a92c..350879daa 100644 --- a/contrib/config/osmc2012/icinga-c3.pem +++ b/contrib/config/osmc2012/icinga-c3.pem @@ -1,16 +1,19 @@ -----BEGIN CERTIFICATE----- -MIICNTCCAZ4CAQQwDQYJKoZIhvcNAQEFBQAwaDELMAkGA1UEBhMCREUxEDAOBgNV -BAgMB0JhdmFyaWExEjAQBgNVBAcMCU51cmVtYmVyZzEVMBMGA1UECgwMTkVUV0FZ -UyBHbWJIMRwwGgYDVQQDDBNJY2luZ2EgU25ha2UgT2lsIENBMB4XDTEyMDUwODA3 -MzkxOVoXDTIyMDUwNjA3MzkxOVowXjELMAkGA1UEBhMCREUxEDAOBgNVBAgMB0Jh -dmFyaWExEjAQBgNVBAcMCU51cmVtYmVyZzEVMBMGA1UECgwMTkVUV0FZUyBHbWJI -MRIwEAYDVQQDDAlpY2luZ2EtYzMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB -AKFf+UkCgbNtEP0OoeF+K02L5SRlqkkkp6eaieh0IN7NNAxeELcGpZmycv4sHp30 -qv0zDtKU1HYrpm8TEBsz2AoT+J36QT9IysfcWdM9o3WZGMDUVqYBUscurkxBQJCK -cFwXijTJ8Djn82xVgNUm/E44AdbrIwUlx23yllErx8hfAgMBAAEwDQYJKoZIhvcN -AQEFBQADgYEAsZOKZQ2+ksPiNTCJrY+uiUZs6lFSbcJ9BHHaAt0ytQPiblufz3xl -AR5Hza5fHt+lN9aGxM7TWMhjZHhmoctSRz8AW1KZTdbxJhRdbqmBjl95c2wBiDxs -ERpyU9m9Rp42IjTyU4Vr/yO7DgMcG2k4KYzNquA5O8rqqtPRAp3H6n0= +MIICtzCCAiCgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJERTEQ +MA4GA1UECAwHQmF2YXJpYTESMBAGA1UEBwwJTnVyZW1iZXJnMRUwEwYDVQQKDAxO +RVRXQVlTIEdtYkgxHDAaBgNVBAMME0ljaW5nYSBTbmFrZSBPaWwgQ0EwHhcNMTMw +ODI3MDcyNTQ1WhcNMjMwODI1MDcyNTQ1WjBeMQswCQYDVQQGEwJERTEQMA4GA1UE +CAwHQmF2YXJpYTESMBAGA1UEBwwJTnVyZW1iZXJnMRUwEwYDVQQKDAxORVRXQVlT +IEdtYkgxEjAQBgNVBAMMCWljaW5nYS1jMzCBnzANBgkqhkiG9w0BAQEFAAOBjQAw +gYkCgYEAoV/5SQKBs20Q/Q6h4X4rTYvlJGWqSSSnp5qJ6HQg3s00DF4QtwalmbJy +/iwenfSq/TMO0pTUdiumbxMQGzPYChP4nfpBP0jKx9xZ0z2jdZkYwNRWpgFSxy6u +TEFAkIpwXBeKNMnwOOfzbFWA1Sb8TjgB1usjBSXHbfKWUSvHyF8CAwEAAaN7MHkw +CQYDVR0TBAIwADAsBglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2Vy +dGlmaWNhdGUwHQYDVR0OBBYEFEwxDpbbnj9CAJRPErpolPAjAi1bMB8GA1UdIwQY +MBaAFNVJHVPJNwqEcG51lpqZJWVPaysFMA0GCSqGSIb3DQEBBQUAA4GBAJMvQyvv +aXxu87au/X6+k6ghUImwGW/xqtrouyVZ3yX4zq9R/sZ1yA5jRq7e+IDjb04qraY7 +ZwMCWqjUYFUzV4ViEx6m7bnm/Qv+pubmM7v8B4Obm1HJniVcJUMOzoGgKGQxjOCt +97EsiVQZGnss4PYjjxlW7T/QvqkZb4tbyyeE -----END CERTIFICATE----- -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQChX/lJAoGzbRD9DqHhfitNi+UkZapJJKenmonodCDezTQMXhC3 diff --git a/contrib/gdb/icingadbg.py b/contrib/gdb/icingadbg.py index cfef4d186..e71ddba60 100644 --- a/contrib/gdb/icingadbg.py +++ b/contrib/gdb/icingadbg.py @@ -26,13 +26,6 @@ class IcingaValuePrinter: else: return '' -class IcingaAttributePrinter: - def __init__(self, val): - self.val = val - - def to_string(self): - return self.val['m_Value'] - class IcingaSignalPrinter: def __init__(self, val): self.val = val @@ -40,16 +33,28 @@ class IcingaSignalPrinter: def to_string(self): return '' +class IcingaMutexPrinter: + def __init__(self, val): + self.val = val + + def to_string(self): + owner = self.val['__data']['__owner'] + + if owner == 0: + return '' + else: + return '' + def lookup_icinga_type(val): t = val.type.unqualified() if str(t) == 'icinga::String': return IcingaStringPrinter(val) elif str(t) == 'icinga::Value': return IcingaValuePrinter(val) - elif str(t) == 'icinga::AttributeBase' or re.match('^icinga::Attribute<.*>$', str(t)): - return IcingaAttributePrinter(val) elif re.match('^boost::signals2::signal.*<.*>$', str(t)): return IcingaSignalPrinter(val) + elif str(t) == 'pthread_mutex_t': + return IcingaMutexPrinter(val) return None diff --git a/lib/Makefile.am b/lib/Makefile.am index 4a5ece41c..d8e8945f6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,7 +4,6 @@ SUBDIRS = \ base \ config \ - remoting \ icinga \ ido \ python diff --git a/lib/base/array.cpp b/lib/base/array.cpp index 575c10c2e..043f89ba1 100644 --- a/lib/base/array.cpp +++ b/lib/base/array.cpp @@ -26,13 +26,6 @@ using namespace icinga; -/** - * Constructor for the Array class. - */ -Array::Array(void) - : m_Sealed(false) -{ } - /** * Restrieves a value from an array. * @@ -58,9 +51,6 @@ void Array::Set(unsigned int index, const Value& value) ASSERT(!OwnsLock()); ObjectLock olock(this); - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be sealed.")); - m_Data.at(index) = value; } @@ -74,9 +64,6 @@ void Array::Add(const Value& value) ASSERT(!OwnsLock()); ObjectLock olock(this); - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be sealed.")); - m_Data.push_back(value); } @@ -131,9 +118,6 @@ void Array::Remove(unsigned int index) ASSERT(!OwnsLock()); ObjectLock olock(this); - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be sealed.")); - m_Data.erase(m_Data.begin() + index); } @@ -146,37 +130,9 @@ void Array::Remove(Array::Iterator it) { ASSERT(OwnsLock()); - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Array must not be sealed.")); - m_Data.erase(it); } -/** - * Marks the array as read-only. Attempting to modify a sealed - * array is an error. - */ -void Array::Seal(void) -{ - ASSERT(!OwnsLock()); - ObjectLock olock(this); - - m_Sealed = true; -} - -/** - * Checks whether the array is sealed. - * - * @returns true if the array is sealed, false otherwise. - */ -bool Array::IsSealed(void) const -{ - ASSERT(!OwnsLock()); - ObjectLock olock(this); - - return m_Sealed; -} - /** * Makes a shallow copy of an array. * diff --git a/lib/base/array.h b/lib/base/array.h index fe9609300..cd1656033 100644 --- a/lib/base/array.h +++ b/lib/base/array.h @@ -42,15 +42,10 @@ public: */ typedef std::vector::iterator Iterator; - Array(void); - Value Get(unsigned int index) const; void Set(unsigned int index, const Value& value); void Add(const Value& value); - void Seal(void); - bool IsSealed(void) const; - Iterator Begin(void); Iterator End(void); @@ -66,7 +61,6 @@ public: private: std::vector m_Data; /**< The data for the array. */ - bool m_Sealed; /**< Whether the array is read-only. */ }; inline Array::Iterator range_begin(Array::Ptr x) diff --git a/lib/base/bufferedstream.cpp b/lib/base/bufferedstream.cpp index b9346279e..2f35a57f3 100644 --- a/lib/base/bufferedstream.cpp +++ b/lib/base/bufferedstream.cpp @@ -27,7 +27,7 @@ using namespace icinga; BufferedStream::BufferedStream(const Stream::Ptr& innerStream) - : m_InnerStream(innerStream), m_Stopped(false), + : m_InnerStream(innerStream), m_Stopped(false), m_Eof(false), m_RecvQ(boost::make_shared()), m_SendQ(boost::make_shared()), m_Blocking(true), m_Exception() { @@ -64,8 +64,15 @@ void BufferedStream::ReadThreadProc(void) for (;;) { size_t rc = m_InnerStream->Read(buffer, sizeof(buffer)); - if (rc == 0) + if (rc == 0) { + boost::mutex::scoped_lock lock(m_Mutex); + m_Eof = true; + m_Stopped = true; + m_ReadCV.notify_all(); + m_WriteCV.notify_all(); + break; + } boost::mutex::scoped_lock lock(m_Mutex); m_RecvQ->Write(buffer, rc); @@ -173,7 +180,7 @@ void BufferedStream::WaitReadable(size_t count) void BufferedStream::InternalWaitReadable(size_t count, boost::mutex::scoped_lock& lock) { - while (m_RecvQ->GetAvailableBytes() < count && !m_Exception) + while (m_RecvQ->GetAvailableBytes() < count && !m_Exception && !m_Stopped) m_ReadCV.wait(lock); } @@ -186,3 +193,10 @@ void BufferedStream::MakeNonBlocking(void) m_Blocking = false; } + +bool BufferedStream::IsEof(void) const +{ + boost::mutex::scoped_lock lock(m_Mutex); + + return m_Eof; +} \ No newline at end of file diff --git a/lib/base/bufferedstream.h b/lib/base/bufferedstream.h index 75934f553..a6028f3c9 100644 --- a/lib/base/bufferedstream.h +++ b/lib/base/bufferedstream.h @@ -45,6 +45,8 @@ public: virtual void Close(void); + virtual bool IsEof(void) const; + void WaitReadable(size_t count); void WaitWritable(size_t count); @@ -54,6 +56,7 @@ private: Stream::Ptr m_InnerStream; bool m_Stopped; + bool m_Eof; FIFO::Ptr m_RecvQ; FIFO::Ptr m_SendQ; @@ -62,7 +65,7 @@ private: boost::exception_ptr m_Exception; - boost::mutex m_Mutex; + mutable boost::mutex m_Mutex; boost::condition_variable m_ReadCV; boost::condition_variable m_WriteCV; diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index d5914a596..1c8773d2d 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -59,13 +59,6 @@ struct DictionaryKeyLessComparer } }; -/** - * Constructor for the Dictionary class. - */ -Dictionary::Dictionary(void) - : m_Sealed(false) -{ } - /** * Restrieves a value from a dictionary. * @@ -114,9 +107,6 @@ void Dictionary::Set(const String& key, const Value& value) ASSERT(!OwnsLock()); ObjectLock olock(this); - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be sealed.")); - std::pair::iterator, bool> ret; ret = m_Data.insert(std::make_pair(key, value)); if (!ret.second) @@ -194,9 +184,6 @@ void Dictionary::Remove(const String& key) if (it == m_Data.end()) return; - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be sealed.")); - m_Data.erase(it); } @@ -209,37 +196,9 @@ void Dictionary::Remove(Dictionary::Iterator it) { ASSERT(OwnsLock()); - if (m_Sealed) - BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionary must not be sealed.")); - m_Data.erase(it); } -/** - * Marks the dictionary as read-only. Attempting to modify a sealed - * dictionary is an error. - */ -void Dictionary::Seal(void) -{ - ASSERT(!OwnsLock()); - ObjectLock olock(this); - - m_Sealed = true; -} - -/** - * Checks whether the dictionary is sealed. - * - * @returns true if the dictionary is sealed, false otherwise. - */ -bool Dictionary::IsSealed(void) const -{ - ASSERT(!OwnsLock()); - ObjectLock olock(this); - - return m_Sealed; -} - /** * Makes a shallow copy of a dictionary. * diff --git a/lib/base/dictionary.h b/lib/base/dictionary.h index 8f8e669c3..9331505ea 100644 --- a/lib/base/dictionary.h +++ b/lib/base/dictionary.h @@ -43,16 +43,11 @@ public: */ typedef std::map::iterator Iterator; - Dictionary(void); - Value Get(const char *key) const; Value Get(const String& key) const; void Set(const String& key, const Value& value); bool Contains(const String& key) const; - void Seal(void); - bool IsSealed(void) const; - Iterator Begin(void); Iterator End(void); @@ -68,7 +63,6 @@ public: private: std::map m_Data; /**< The data for the dictionary. */ - bool m_Sealed; /**< Whether the dictionary is read-only. */ }; inline Dictionary::Iterator range_begin(Dictionary::Ptr x) diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 73a5d40ba..485cb2fe7 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -272,7 +272,7 @@ void DynamicObject::RestoreObjects(const String& filename, int attributeTypes) DynamicType::Ptr dt = DynamicType::GetByName(type); if (!dt) - BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid type: " + type)); + continue; DynamicObject::Ptr object = dt->GetObject(name); diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index b908c7843..6f968e481 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -111,6 +111,11 @@ void FIFO::Write(const void *buffer, size_t count) void FIFO::Close(void) { } +bool FIFO::IsEof(void) const +{ + return false; +} + size_t FIFO::GetAvailableBytes(void) const { return m_DataSize; diff --git a/lib/base/fifo.h b/lib/base/fifo.h index cab32b160..d7d6ec88f 100644 --- a/lib/base/fifo.h +++ b/lib/base/fifo.h @@ -44,6 +44,7 @@ public: virtual size_t Read(void *buffer, size_t count); virtual void Write(const void *buffer, size_t count); virtual void Close(void); + virtual bool IsEof(void) const; size_t GetAvailableBytes(void) const; diff --git a/lib/base/networkstream.cpp b/lib/base/networkstream.cpp index 9bc83a5ec..4335a245a 100644 --- a/lib/base/networkstream.cpp +++ b/lib/base/networkstream.cpp @@ -25,7 +25,7 @@ using namespace icinga; NetworkStream::NetworkStream(const Socket::Ptr& socket) - : m_Socket(socket) + : m_Socket(socket), m_Eof(false) { } void NetworkStream::Close(void) @@ -43,7 +43,12 @@ void NetworkStream::Close(void) */ size_t NetworkStream::Read(void *buffer, size_t count) { - return m_Socket->Read(buffer, count); + size_t rc = m_Socket->Read(buffer, count); + + if (rc == 0) + m_Eof = true; + + return rc; } /** @@ -59,3 +64,8 @@ void NetworkStream::Write(const void *buffer, size_t count) if (rc < count) BOOST_THROW_EXCEPTION(std::runtime_error("Short write for socket.")); } + +bool NetworkStream::IsEof(void) const +{ + return m_Eof; +} diff --git a/lib/base/networkstream.h b/lib/base/networkstream.h index 018f02f30..c98c1da40 100644 --- a/lib/base/networkstream.h +++ b/lib/base/networkstream.h @@ -44,8 +44,11 @@ public: virtual void Close(void); + virtual bool IsEof(void) const; + private: Socket::Ptr m_Socket; + bool m_Eof; }; } diff --git a/lib/base/stdiostream.cpp b/lib/base/stdiostream.cpp index ec4cf4d0c..777eb1193 100644 --- a/lib/base/stdiostream.cpp +++ b/lib/base/stdiostream.cpp @@ -61,3 +61,8 @@ void StdioStream::Close(void) m_OwnsStream = false; } } + +bool StdioStream::IsEof(void) const +{ + return m_InnerStream->eof(); +} diff --git a/lib/base/stdiostream.h b/lib/base/stdiostream.h index f1b9079f5..96db5a92e 100644 --- a/lib/base/stdiostream.h +++ b/lib/base/stdiostream.h @@ -39,6 +39,8 @@ public: virtual void Close(void); + virtual bool IsEof(void) const; + private: std::iostream *m_InnerStream; bool m_OwnsStream; diff --git a/lib/base/stream.h b/lib/base/stream.h index 3f0fa5e0c..10a2d3c00 100644 --- a/lib/base/stream.h +++ b/lib/base/stream.h @@ -74,6 +74,13 @@ public: */ virtual void Close(void) = 0; + /** + * Checks whether we've reached the end-of-file condition. + * + * @returns true if EOF. + */ + virtual bool IsEof(void) const = 0; + bool ReadLine(String *line, ReadLineContext& context); }; diff --git a/lib/base/stream_bio.cpp b/lib/base/stream_bio.cpp index 324d0735e..07ca1f9fc 100644 --- a/lib/base/stream_bio.cpp +++ b/lib/base/stream_bio.cpp @@ -111,7 +111,7 @@ static int I2Stream_read(BIO *bi, char *out, int outl) return -1; } - if (data_read == 0) { + if (data_read == 0 && !bp->StreamObj->IsEof()) { BIO_set_retry_read(bi); return -1; } diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index 5e727bb43..ea20871df 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -214,3 +214,8 @@ void TlsStream::Close(void) { m_InnerStream->Close(); } + +bool TlsStream::IsEof(void) const +{ + return m_InnerStream->IsEof(); +} diff --git a/lib/base/tlsstream.h b/lib/base/tlsstream.h index cd59ed51e..813044a44 100644 --- a/lib/base/tlsstream.h +++ b/lib/base/tlsstream.h @@ -57,6 +57,8 @@ public: virtual size_t Read(void *buffer, size_t count); virtual void Write(const void *buffer, size_t count); + virtual bool IsEof(void) const; + private: shared_ptr m_SSLContext; shared_ptr m_SSL; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 7ea26928d..4f5381a4f 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -179,8 +179,6 @@ DynamicObject::Ptr ConfigItem::Commit(void) } } - attrs->Seal(); - DynamicObject::Ptr dobj = dtype->CreateObject(attrs); dobj->Register(); diff --git a/lib/icinga/Makefile.am b/lib/icinga/Makefile.am index 0472df905..62a378601 100644 --- a/lib/icinga/Makefile.am +++ b/lib/icinga/Makefile.am @@ -88,5 +88,4 @@ libicinga_la_LIBADD = \ $(BOOST_THREAD_LIB) \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ - ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la + ${top_builddir}/lib/config/libconfig.la diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index ee1513265..63b5a1079 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -183,10 +183,6 @@ type HostGroup { } type IcingaApplication { - %attribute string "cert_path", - %attribute string "ca_path", - %attribute string "node", - %attribute string "service", %attribute string "pid_path", %attribute string "state_path", %attribute dictionary "macros" { diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 919bd12d3..6166d574a 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -18,7 +18,6 @@ ******************************************************************************/ #include "icinga/icingaapplication.h" -#include "remoting/endpointmanager.h" #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/objectlock.h" @@ -50,22 +49,6 @@ int IcingaApplication::Main(void) UpdatePidFile(GetPidPath()); - if (!GetCertificateFile().IsEmpty() && !GetCAFile().IsEmpty()) { - /* set up SSL context */ - shared_ptr cert = GetX509Certificate(GetCertificateFile()); - String identity = GetCertificateCN(cert); - Log(LogInformation, "icinga", "My identity: " + identity); - EndpointManager::GetInstance()->SetIdentity(identity); - - m_SSLContext = MakeSSLContext(GetCertificateFile(), GetCertificateFile(), GetCAFile()); - - EndpointManager::GetInstance()->SetSSLContext(m_SSLContext); - } - - /* create the primary RPC listener */ - if (!GetService().IsEmpty()) - EndpointManager::GetInstance()->AddListener(GetService()); - /* restore the previous program state */ DynamicObject::RestoreObjects(GetStatePath()); @@ -104,34 +87,6 @@ IcingaApplication::Ptr IcingaApplication::GetInstance(void) return static_pointer_cast(Application::GetInstance()); } -String IcingaApplication::GetCertificateFile(void) const -{ - ObjectLock olock(this); - - return m_CertPath; -} - -String IcingaApplication::GetCAFile(void) const -{ - ObjectLock olock(this); - - return m_CAPath; -} - -String IcingaApplication::GetNode(void) const -{ - ObjectLock olock(this); - - return m_Node; -} - -String IcingaApplication::GetService(void) const -{ - ObjectLock olock(this); - - return m_Service; -} - String IcingaApplication::GetPidPath(void) const { ObjectLock olock(this); @@ -146,10 +101,10 @@ String IcingaApplication::GetStatePath(void) const { ObjectLock olock(this); - if (m_PidPath.IsEmpty()) + if (m_StatePath.IsEmpty()) return Application::GetLocalStateDir() + "/lib/icinga2/icinga2.state"; else - return m_PidPath; + return m_StatePath; } Dictionary::Ptr IcingaApplication::GetMacros(void) const @@ -166,13 +121,6 @@ double IcingaApplication::GetStartTime(void) const return m_StartTime; } -shared_ptr IcingaApplication::GetSSLContext(void) const -{ - ObjectLock olock(this); - - return m_SSLContext; -} - bool IcingaApplication::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const { double now = Utility::GetTime(); @@ -209,10 +157,6 @@ void IcingaApplication::InternalSerialize(const Dictionary::Ptr& bag, int attrib DynamicObject::InternalSerialize(bag, attributeTypes); if (attributeTypes & Attribute_Config) { - bag->Set("cert_path", m_CertPath); - bag->Set("ca_path", m_CAPath); - bag->Set("node", m_Node); - bag->Set("service", m_Service); bag->Set("pid_path", m_PidPath); bag->Set("state_path", m_StatePath); bag->Set("macros", m_Macros); @@ -224,10 +168,6 @@ void IcingaApplication::InternalDeserialize(const Dictionary::Ptr& bag, int attr DynamicObject::InternalDeserialize(bag, attributeTypes); if (attributeTypes & Attribute_Config) { - m_CertPath = bag->Get("cert_path"); - m_CAPath = bag->Get("ca_path"); - m_Node = bag->Get("node"); - m_Service = bag->Get("service"); m_PidPath = bag->Get("pid_path"); m_StatePath = bag->Get("state_path"); m_Macros = bag->Get("macros"); diff --git a/lib/icinga/icingaapplication.h b/lib/icinga/icingaapplication.h index daedadc04..c0795ac9e 100644 --- a/lib/icinga/icingaapplication.h +++ b/lib/icinga/icingaapplication.h @@ -23,7 +23,6 @@ #include "icinga/i2-icinga.h" #include "icinga/macroresolver.h" #include "base/application.h" -#include "base/tlsutility.h" namespace icinga { @@ -43,14 +42,9 @@ public: static IcingaApplication::Ptr GetInstance(void); - String GetCertificateFile(void) const; - String GetCAFile(void) const; - String GetNode(void) const; - String GetService(void) const; String GetPidPath(void) const; String GetStatePath(void) const; Dictionary::Ptr GetMacros(void) const; - shared_ptr GetSSLContext(void) const; double GetStartTime(void) const; @@ -61,16 +55,10 @@ protected: virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes); private: - String m_CertPath; - String m_CAPath; - String m_Node; - String m_Service; String m_PidPath; String m_StatePath; Dictionary::Ptr m_Macros; - shared_ptr m_SSLContext; - double m_StartTime; void DumpProgramState(void); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index 4d8069ffc..a8370c53e 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -21,7 +21,6 @@ #include "icinga/notificationcommand.h" #include "icinga/macroprocessor.h" #include "icinga/service.h" -#include "remoting/endpointmanager.h" #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index db2cd643b..6c0112626 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -590,8 +590,6 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) cr->Set("vars_after", vars_after); - cr->Seal(); - olock.Lock(); SetLastCheckResult(cr); @@ -749,7 +747,6 @@ void Service::ExecuteCheck(void) checkInfo->Set("execution_end", Utility::GetTime()); checkInfo->Set("schedule_end", Utility::GetTime()); - checkInfo->Seal(); if (result) { if (!result->Contains("schedule_start")) diff --git a/lib/ido/Makefile.am b/lib/ido/Makefile.am index e26f8d611..b9057a7ec 100644 --- a/lib/ido/Makefile.am +++ b/lib/ido/Makefile.am @@ -57,5 +57,4 @@ libido_la_LIBADD = \ $(BOOST_SYSTEM_LIB) \ ${top_builddir}/lib/base/libbase.la \ ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ ${top_builddir}/lib/icinga/libicinga.la diff --git a/lib/python/Makefile.am b/lib/python/Makefile.am index 15fc347b3..0f79fb0df 100644 --- a/lib/python/Makefile.am +++ b/lib/python/Makefile.am @@ -27,6 +27,5 @@ libpython_la_LDFLAGS = \ libpython_la_LIBADD = \ $(BOOST_THREAD_LIB) \ ${top_builddir}/lib/base/libbase.la \ - ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la + ${top_builddir}/lib/config/libconfig.la endif diff --git a/lib/remoting/.gitignore b/lib/remoting/.gitignore deleted file mode 100644 index 83eb6c93b..000000000 --- a/lib/remoting/.gitignore +++ /dev/null @@ -1 +0,0 @@ -remoting-type.cpp diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp deleted file mode 100644 index b41d974b2..000000000 --- a/lib/remoting/endpointmanager.cpp +++ /dev/null @@ -1,411 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -#include "remoting/endpointmanager.h" -#include "base/dynamictype.h" -#include "base/objectlock.h" -#include "base/logger_fwd.h" -#include "base/convert.h" -#include "base/utility.h" -#include "base/tlsutility.h" -#include "base/networkstream.h" -#include -#include - -using namespace icinga; - -/** - * Constructor for the EndpointManager class. - */ -EndpointManager::EndpointManager(void) -{ - m_ReconnectTimer = boost::make_shared(); - m_ReconnectTimer->OnTimerExpired.connect(boost::bind(&EndpointManager::ReconnectTimerHandler, this)); - m_ReconnectTimer->SetInterval(5); - m_ReconnectTimer->Start(); -} - -/** - * Sets the SSL context. - * - * @param sslContext The new SSL context. - */ -void EndpointManager::SetSSLContext(const shared_ptr& sslContext) -{ - ObjectLock olock(this); - - m_SSLContext = sslContext; -} - -/** - * Retrieves the SSL context. - * - * @returns The SSL context. - */ -shared_ptr EndpointManager::GetSSLContext(void) const -{ - ObjectLock olock(this); - - return m_SSLContext; -} - -/** - * Sets the identity of the endpoint manager. This identity is used when - * connecting to remote peers. - * - * @param identity The new identity. - */ -void EndpointManager::SetIdentity(const String& identity) -{ - ObjectLock olock(this); - - m_Identity = identity; -} - -/** - * Retrieves the identity for the endpoint manager. - * - * @returns The identity. - */ -String EndpointManager::GetIdentity(void) const -{ - ObjectLock olock(this); - - return m_Identity; -} - -/** - * Creates a new JSON-RPC listener on the specified port. - * - * @param service The port to listen on. - */ -void EndpointManager::AddListener(const String& service) -{ - ObjectLock olock(this); - - shared_ptr sslContext = m_SSLContext; - - if (!sslContext) - BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddListener()")); - - std::ostringstream s; - s << "Adding new listener: port " << service; - Log(LogInformation, "icinga", s.str()); - - TcpSocket::Ptr server = boost::make_shared(); - server->Bind(service, AF_INET6); - - boost::thread thread(boost::bind(&EndpointManager::ListenerThreadProc, this, server)); - thread.detach(); - - m_Servers.insert(server); -} - -void EndpointManager::ListenerThreadProc(const Socket::Ptr& server) -{ - server->Listen(); - - for (;;) { - Socket::Ptr client = server->Accept(); - - try { - NewClientHandler(client, TlsRoleServer); - } catch (const std::exception& ex) { - std::stringstream message; - message << "Error for new JSON-RPC socket: " << boost::diagnostic_information(ex); - Log(LogInformation, "remoting", message.str()); - } - } -} - -/** - * Creates a new JSON-RPC client and connects to the specified host and port. - * - * @param node The remote host. - * @param service The remote port. - */ -void EndpointManager::AddConnection(const String& node, const String& service) { - { - ObjectLock olock(this); - - shared_ptr sslContext = m_SSLContext; - - if (!sslContext) - BOOST_THROW_EXCEPTION(std::logic_error("SSL context is required for AddConnection()")); - } - - TcpSocket::Ptr client = boost::make_shared(); - - try { - client->Connect(node, service); - NewClientHandler(client, TlsRoleClient); - } catch (const std::exception& ex) { - Log(LogInformation, "remoting", "Could not connect to " + node + ":" + service + ": " + ex.what()); - } -} - -/** - * Processes a new client connection. - * - * @param client The new client. - */ -void EndpointManager::NewClientHandler(const Socket::Ptr& client, TlsRole role) -{ - NetworkStream::Ptr netStream = boost::make_shared(client); - - TlsStream::Ptr tlsStream = boost::make_shared(netStream, role, m_SSLContext); - tlsStream->Handshake(); - - shared_ptr cert = tlsStream->GetPeerCertificate(); - String identity = GetCertificateCN(cert); - - Log(LogInformation, "icinga", "New client connection for identity '" + identity + "'"); - - Endpoint::Ptr endpoint = Endpoint::GetByName(identity); - - if (!endpoint) { - Log(LogInformation, "remoting", "Closing endpoint '" + identity + "': No configuration available."); - return; - } - - endpoint->SetClient(tlsStream); -} - -///** -// * Sends an anonymous unicast message to the specified recipient. -// * -// * @param recipient The recipient of the message. -// * @param message The message. -// */ -//void EndpointManager::SendUnicastMessage(const Endpoint::Ptr& recipient, -// const MessagePart& message) -//{ -// SendUnicastMessage(Endpoint::Ptr(), recipient, message); -//} - -///** -// * Sends a unicast message to the specified recipient. -// * -// * @param sender The sender of the message. -// * @param recipient The recipient of the message. -// * @param message The message. -// */ -//void EndpointManager::SendUnicastMessage(const Endpoint::Ptr& sender, -// const Endpoint::Ptr& recipient, const MessagePart& message) -//{ -// /* don't forward messages between non-local endpoints, assume that -// * anonymous senders (sender == null) are local */ -//// if ((sender && !sender->IsLocal()) && !recipient->IsLocal()) -//// return; -// -// if (ResponseMessage::IsResponseMessage(message)) -// recipient->ProcessResponse(sender, message); -// else -// recipient->ProcessRequest(sender, message); -//} - -///** -// * Sends a message to exactly one recipient out of all recipients who have a -// * subscription for the message's topic. -// * -// * @param sender The sender of the message. -// * @param message The message. -// */ -//void EndpointManager::SendAnycastMessage(const Endpoint::Ptr& sender, -// const RequestMessage& message) -//{ -// String method; -// if (!message.GetMethod(&method)) -// BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property.")); -// -// std::vector candidates; -// -// BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { -// /* don't forward messages between non-local endpoints */ -//// if ((sender && !sender->IsLocal()) && !endpoint->IsLocal()) -//// continue; -// -// if (endpoint->HasSubscription(method)) -// candidates.push_back(endpoint); -// } -// -// if (candidates.empty()) -// return; -// -// Endpoint::Ptr recipient = candidates[rand() % candidates.size()]; -// SendUnicastMessage(sender, recipient, message); -//} - -///** -// * Sends an anonymous message to all recipients who have a subscription for the -// * message's topic. -// * -// * @param message The message. -// */ -//void EndpointManager::SendMulticastMessage(const RequestMessage& message) -//{ -// SendMulticastMessage(Endpoint::Ptr(), message); -//} - -///** -// * Sends a message to all recipients who have a subscription for the -// * message's topic. -// * -// * @param sender The sender of the message. -// * @param message The message. -// */ -//void EndpointManager::SendBroadcastMessage(const Endpoint::Ptr& sender, -// const RequestMessage& message) -//{ -// String method; -// if (!message.GetMethod(&method)) -// BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property.")); -// -// BOOST_FOREACH(const Endpoint::Ptr& recipient, DynamicType::GetObjects()) { -// /* don't forward messages back to the sender */ -// if (sender == recipient) -// continue; -// -// Log(LogDebug, "remoting", "Send multicast message using method " + method); -// if (recipient->HasSubscription(method)) -// SendUnicastMessage(sender, recipient, message); -// } -//} - -//void EndpointManager::SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, -// RequestMessage& message, -// const EndpointManager::APICallback& callback, double timeout) -//{ -// ObjectLock olock(this); -// -// m_NextMessageID++; -// -// String id = Convert::ToString(m_NextMessageID); -// message.SetID(id); -// -// PendingRequest pr; -// pr.Request = message; -// pr.Callback = callback; -// pr.Timeout = Utility::GetTime() + timeout; -// -// m_Requests[id] = pr; -// -// if (!recipient) -// SendAnycastMessage(sender, message); -// else -// SendUnicastMessage(sender, recipient, message); -//} -// -//bool EndpointManager::RequestTimeoutLessComparer(const std::pair& a, -// const std::pair& b) -//{ -// return a.second.Timeout < b.second.Timeout; -//} -// -//void EndpointManager::SubscriptionTimerHandler(void) -//{ -// Dictionary::Ptr subscriptions = boost::make_shared(); -// -// BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { -// /* don't copy subscriptions from non-local endpoints or the identity endpoint */ -//// if (!endpoint->IsLocalEndpoint() || endpoint == m_Endpoint) -//// continue; -// -// Dictionary::Ptr endpointSubscriptions = endpoint->GetSubscriptions(); -// -// if (endpointSubscriptions) { -// ObjectLock olock(endpointSubscriptions); -// -// String topic; -// BOOST_FOREACH(boost::tie(boost::tuples::ignore, topic), endpointSubscriptions) { -// subscriptions->Set(topic, topic); -// } -// } -// } -// -// subscriptions->Seal(); -// -// if (m_Endpoint) { -// ObjectLock olock(m_Endpoint); -// m_Endpoint->SetSubscriptions(subscriptions); -// } -//} - -void EndpointManager::ReconnectTimerHandler(void) -{ - BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects()) { - if (endpoint->IsConnected() || endpoint == m_Endpoint) - continue; - - String host, port; - host = endpoint->GetHost(); - port = endpoint->GetPort(); - - if (host.IsEmpty() || port.IsEmpty()) { - Log(LogWarning, "icinga", "Can't reconnect " - "to endpoint '" + endpoint->GetName() + "': No " - "host/port information."); - continue; - } - - AddConnection(host, port); - } -} - -//void EndpointManager::RequestTimerHandler(void) -//{ -// ObjectLock olock(this); -// -// std::map::iterator it; -// for (it = m_Requests.begin(); it != m_Requests.end(); ++it) { -// if (it->second.HasTimedOut()) { -// it->second.Callback(Endpoint::Ptr(), it->second.Request, -// ResponseMessage(), true); -// -// m_Requests.erase(it); -// -// break; -// } -// } -//} - -//void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, -// const ResponseMessage& message) -//{ -// ObjectLock olock(this); -// -// String id; -// if (!message.GetID(&id)) -// BOOST_THROW_EXCEPTION(std::invalid_argument("Response message must have a message ID.")); -// -// std::map::iterator it; -// it = m_Requests.find(id); -// -// if (it == m_Requests.end()) -// return; -// -// it->second.Callback(sender, it->second.Request, message, false); -// -// m_Requests.erase(it); -//} - -EndpointManager *EndpointManager::GetInstance(void) -{ - return Singleton::GetInstance(); -} diff --git a/lib/remoting/i2-remoting.h b/lib/remoting/i2-remoting.h deleted file mode 100644 index e44cafcd9..000000000 --- a/lib/remoting/i2-remoting.h +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software Foundation * - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ******************************************************************************/ - -#ifndef I2REMOTING_H -#define I2REMOTING_H - -/** - * @defgroup remoting Remoting library - * - * Implements server and client classes for the JSON-RPC protocol. Also - * supports endpoint-based communication using messages. - */ - -#include "base/i2-base.h" - -#ifdef I2_REMOTING_BUILD -# define I2_REMOTING_API I2_EXPORT -#else /* I2_REMOTING_BUILD */ -# define I2_REMOTING_API I2_IMPORT -#endif /* I2_REMOTING_BUILD */ - -#endif /* I2REMOTING_H */ diff --git a/lib/remoting/remoting.vcxproj.filters b/lib/remoting/remoting.vcxproj.filters deleted file mode 100644 index b3662201f..000000000 --- a/lib/remoting/remoting.vcxproj.filters +++ /dev/null @@ -1,58 +0,0 @@ - - - - - Quelldateien - - - Quelldateien - - - Quelldateien - - - Quelldateien - - - Quelldateien - - - Quelldateien - - - - - - Headerdateien - - - Headerdateien - - - Headerdateien - - - Headerdateien - - - Headerdateien - - - Headerdateien - - - - - - {796f79ec-5628-4c91-9e2b-3d603ab2acfc} - - - {0457f937-d12b-4328-818b-77359de2425f} - - - - - Quelldateien - - - \ No newline at end of file