[icinga-checkins] icinga.org: icinga2/master: Implement support for anonymous multicast messages.

git at icinga.org git at icinga.org
Tue Jan 22 10:16:06 CET 2013


Module: icinga2
Branch: master
Commit: c97b480b1ecab145f98ba12a1f6bf620ee75f6e9
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=c97b480b1ecab145f98ba12a1f6bf620ee75f6e9

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Jan 22 10:14:52 2013 +0100

Implement support for anonymous multicast messages.

Fixes #3545

---

 components/demo/democomponent.cpp               |    2 +-
 components/replication/replicationcomponent.cpp |    8 +++---
 components/replication/replicationcomponent.h   |    4 +-
 lib/remoting/endpointmanager.cpp                |   30 ++++++++++++++++++++--
 lib/remoting/endpointmanager.h                  |    2 +
 5 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/components/demo/democomponent.cpp b/components/demo/democomponent.cpp
index b72b02f..1914533 100644
--- a/components/demo/democomponent.cpp
+++ b/components/demo/democomponent.cpp
@@ -69,7 +69,7 @@ void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender,
     const RequestMessage& request)
 {
 	Logger::Write(LogInformation, "demo", "Got 'hello world' from identity=" +
-	    sender->GetName());
+	    (sender ? sender->GetName() : "(anonymous)"));
 }
 
 EXPORT_COMPONENT(demo, DemoComponent);
diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp
index ec71756..ef2c717 100644
--- a/components/replication/replicationcomponent.cpp
+++ b/components/replication/replicationcomponent.cpp
@@ -35,13 +35,13 @@ void ReplicationComponent::Start(void)
 	Endpoint::OnConnected.connect(boost::bind(&ReplicationComponent::EndpointConnectedHandler, this, _1));
 	
 	m_Endpoint->RegisterTopicHandler("config::ObjectUpdate",
-	    boost::bind(&ReplicationComponent::RemoteObjectUpdateHandler, this, _2, _3));
+	    boost::bind(&ReplicationComponent::RemoteObjectUpdateHandler, this, _3));
 	m_Endpoint->RegisterTopicHandler("config::ObjectRemoved",
 	    boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3));
 
 	/* service status */
 	m_Endpoint->RegisterTopicHandler("checker::ServiceStateChange",
-	    boost::bind(&ReplicationComponent::ServiceStateChangeRequestHandler, _2, _3));
+	    boost::bind(&ReplicationComponent::ServiceStateChangeRequestHandler, _3));
 }
 
 /**
@@ -52,7 +52,7 @@ void ReplicationComponent::Stop(void)
 	m_Endpoint->Unregister();
 }
 
-void ReplicationComponent::ServiceStateChangeRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
+void ReplicationComponent::ServiceStateChangeRequestHandler(const RequestMessage& request)
 {
 	ServiceStateChangeMessage params;
 	if (!request.GetParams(&params))
@@ -163,7 +163,7 @@ void ReplicationComponent::TransactionClosingHandler(const set<DynamicObject::Pt
 	}
 }
 
-void ReplicationComponent::RemoteObjectUpdateHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
+void ReplicationComponent::RemoteObjectUpdateHandler(const RequestMessage& request)
 {
 	MessagePart params;
 	if (!request.GetParams(&params))
diff --git a/components/replication/replicationcomponent.h b/components/replication/replicationcomponent.h
index 8b8dfc3..136770d 100644
--- a/components/replication/replicationcomponent.h
+++ b/components/replication/replicationcomponent.h
@@ -35,7 +35,7 @@ public:
 private:
 	Endpoint::Ptr m_Endpoint;
 
-	static void ServiceStateChangeRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
+	static void ServiceStateChangeRequestHandler(const RequestMessage& request);
 
 	void EndpointConnectedHandler(const Endpoint::Ptr& endpoint);
 
@@ -43,7 +43,7 @@ private:
 	void LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object);
 	void TransactionClosingHandler(const set<DynamicObject::Ptr>& modifiedObjects);
 
-	void RemoteObjectUpdateHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
+	void RemoteObjectUpdateHandler(const RequestMessage& request);
 	void RemoteObjectRemovedHandler(const RequestMessage& request);
 
 	static RequestMessage MakeObjectMessage(const DynamicObject::Ptr& object,
diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp
index 799f3c2..077b106 100644
--- a/lib/remoting/endpointmanager.cpp
+++ b/lib/remoting/endpointmanager.cpp
@@ -185,17 +185,30 @@ void EndpointManager::ClientClosedHandler(const Stream::Ptr& client)
 }
 
 /**
+ * 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 request.
+ * @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 */
-	if (!sender->IsLocal() && !recipient->IsLocal())
+	/* 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))
@@ -238,6 +251,17 @@ void EndpointManager::SendAnycastMessage(const Endpoint::Ptr& sender,
 }
 
 /**
+ * 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.
  *
diff --git a/lib/remoting/endpointmanager.h b/lib/remoting/endpointmanager.h
index b491846..120f9f5 100644
--- a/lib/remoting/endpointmanager.h
+++ b/lib/remoting/endpointmanager.h
@@ -47,8 +47,10 @@ public:
 	void AddListener(const String& service);
 	void AddConnection(const String& node, const String& service);
 
+	void SendUnicastMessage(const Endpoint::Ptr& recipient, const MessagePart& 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);
 
 	typedef function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> APICallback;





More information about the icinga-checkins mailing list