[xmppd-dev] commit r1532 - in branches/RELEASE-1_6_1: . jabberd jabberd/base

mail at jabberd.org mail at jabberd.org
Sun Sep 7 17:41:50 CEST 2008


Author: mawis
Date: Sun Sep  7 17:39:03 2008
New Revision: 1532

Log:
Fix for dynamic routing extension
(see rev 1531 in trunk)

Modified:
   branches/RELEASE-1_6_1/ChangeLog
   branches/RELEASE-1_6_1/bootstrap
   branches/RELEASE-1_6_1/jabberd/base/base_accept.cc
   branches/RELEASE-1_6_1/jabberd/base/base_connect.cc
   branches/RELEASE-1_6_1/jabberd/deliver.cc
   branches/RELEASE-1_6_1/jabberd/jabberd.h

Modified: branches/RELEASE-1_6_1/ChangeLog
==============================================================================
--- branches/RELEASE-1_6_1/ChangeLog	Sun Sep  7 17:33:12 2008	(r1531)
+++ branches/RELEASE-1_6_1/ChangeLog	Sun Sep  7 17:39:03 2008	(r1532)
@@ -1,3 +1,11 @@
+2008-09-07  Matthias Wimmer  <m at tthias.eu>
+
+    * bootstrap: update for newer build tools
+    * jabberd/jabberd.h: fix for dynamic routing extension
+    * jabberd/base/base_connect.cc: same
+    * jabberd/base/base_accept.cc: same
+    * jabberd/deliver.cc: same
+
 2008-05-05  Matthias Wimmer  <m at tthias.eu>
 
     * jabberd/mio_tls.cc: patch by Martin Matuschka to support newer GnuTLS

Modified: branches/RELEASE-1_6_1/bootstrap
==============================================================================
--- branches/RELEASE-1_6_1/bootstrap	Sun Sep  7 17:33:12 2008	(r1531)
+++ branches/RELEASE-1_6_1/bootstrap	Sun Sep  7 17:39:03 2008	(r1532)
@@ -8,17 +8,17 @@
 #
 ## Using prereq in autoconf rather than here, mostly for the debian systems at
 ## this point
-if test -z "`autoconf --version 2>&1|head -n 1|egrep '2.[56]'`"; then
+if test -z "`autoconf --version 2>&1|head -n 1|egrep '2\.[56]'`"; then
 	echo "Autoconf 2.50+ is required. Aborting build...";
     exit 1;
 fi
 
-if test -z "`automake --version 2>&1|head -n 1|egrep '1.[5-9]'`"; then
+if test -z "`automake --version 2>&1|head -n 1|egrep '1\.([5-9]|10)'`"; then
 	echo "Automake 1.5+ is required. Aborting build...";
 	exit 1;
 fi
 
-if test -z "`libtool --version 2>&1|head -n 1|egrep '1.[45]'`"; then
+if test -z "`libtool --version 2>&1|head -n 1|egrep '1\.[45]'`"; then
 	echo "Libtool 1.4+ is required. Aborting build...";
 	exit 1;
 fi

Modified: branches/RELEASE-1_6_1/jabberd/base/base_accept.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/base/base_accept.cc	Sun Sep  7 17:33:12 2008	(r1531)
+++ branches/RELEASE-1_6_1/jabberd/base/base_accept.cc	Sun Sep  7 17:39:03 2008	(r1532)
@@ -190,6 +190,27 @@
             }
             ai->q = NULL;
 
+	    // if we are configured as uplink, request the routings to the other instances of this process from our peer process
+	    if (deliver_is_uplink(ai->i)) {
+		std::set<std::string> hosts_to_route = deliver_routed_hosts(p_NORM, ai->i);
+
+		for (std::set<std::string>::const_iterator p = hosts_to_route.begin(); p != hosts_to_route.end(); ++p) {
+
+		    log_debug2(ZONE, LOGT_DYNAMIC, "base_accept is uplink. Sending routing request: %s", p->c_str());
+		    xmlnode route_stanza = xmlnode_new_tag_ns("xdb", NULL, NS_SERVER);
+		    xmlnode_put_attrib_ns(route_stanza, "ns", NULL, NULL, "");
+		    xmlnode_put_attrib_ns(route_stanza, "from", NULL, NULL, ai->i->id);
+		    jid magic_jid = jid_new(xmlnode_pool(route_stanza), "host at -internal");
+		    jid_set(magic_jid, p->c_str(), JID_RESOURCE);
+		    xmlnode_put_attrib_ns(route_stanza, "to", NULL, NULL, jid_full(magic_jid));
+		    mio_write(m, route_stanza, NULL, 0);
+		}
+	    }
+
+
+
+
+
             break;
 
         case MIO_ERROR:

Modified: branches/RELEASE-1_6_1/jabberd/base/base_connect.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/base/base_connect.cc	Sun Sep  7 17:33:12 2008	(r1531)
+++ branches/RELEASE-1_6_1/jabberd/base/base_connect.cc	Sun Sep  7 17:39:03 2008	(r1532)
@@ -160,6 +160,23 @@
                     mio_write(ci->io, b->packet->x, NULL, 0);
                 /* Update connection state flag */
                 ci->state = conn_AUTHD;
+
+		// if we are configured as uplink, request the routings to the other instances of this process from our peer process
+		if (deliver_is_uplink(ci->inst)) {
+		    std::set<std::string> hosts_to_route = deliver_routed_hosts(p_NORM, ci->inst);
+
+		    for (std::set<std::string>::const_iterator p = hosts_to_route.begin(); p != hosts_to_route.end(); ++p) {
+
+			log_debug2(ZONE, LOGT_DYNAMIC, "base_connect is uplink. Sending routing request: %s", p->c_str());
+			xmlnode route_stanza = xmlnode_new_tag_ns("xdb", NULL, NS_SERVER);
+			xmlnode_put_attrib_ns(route_stanza, "ns", NULL, NULL, "");
+			xmlnode_put_attrib_ns(route_stanza, "from", NULL, NULL, ci->inst->id);
+			jid magic_jid = jid_new(xmlnode_pool(route_stanza), "host at -internal");
+			jid_set(magic_jid, p->c_str(), JID_RESOURCE);
+			xmlnode_put_attrib_ns(route_stanza, "to", NULL, NULL, jid_full(magic_jid));
+			mio_write(ci->io, route_stanza, NULL, 0);
+		    }
+		}
             }
             xmlnode_free(x);
             return;

Modified: branches/RELEASE-1_6_1/jabberd/deliver.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/deliver.cc	Sun Sep  7 17:33:12 2008	(r1531)
+++ branches/RELEASE-1_6_1/jabberd/deliver.cc	Sun Sep  7 17:39:03 2008	(r1532)
@@ -217,18 +217,84 @@
  * @return the correct hashtable used for the routing of this stanza type
  */
 static xht deliver_hashtable(ptype type) {
-    switch(type)
-    {
-    case p_LOG:
-        return deliver__hlog;
-    case p_XDB:
-        return deliver__hxdb;
-    default:
-        return deliver__hnorm;
+    switch(type) {
+	case p_LOG:
+	    return deliver__hlog;
+	case p_XDB:
+	    return deliver__hxdb;
+	default:
+	    return deliver__hnorm;
     }
 }
 
 /**
+ * arguments for the deliver_routed_hosts_walk xhash walker function
+ */
+struct deliver_routed_hosts_walk_args {
+    std::set<std::string>*	result;	/**< where to place the results */
+    instance			i;	/**< the instance to exclude */
+};
+
+/**
+ * helper function that walks a deliver hash to check for which domains explicit routings exist
+ *
+ * @param h the xhash to walk
+ * @param key the currently processed host
+ * @param value the instances responsible for this host
+ * @param arg arguments provided by the user of this walker
+ */
+static void deliver_routed_hosts_walk(xht h, char const* key, void* value, void* arg) {
+    // sanity checks
+    if (!h || !key || !value || !arg) {
+	return;
+    }
+
+    // restore types of void* params
+    deliver_routed_hosts_walk_args* args = static_cast<deliver_routed_hosts_walk_args*>(arg);
+    ilist instances = static_cast<ilist>(value);
+
+    // check if some other instance than args->i is responsible for this host
+    bool do_include = false;
+    for (ilist cur = instances; cur; cur = cur->next) {
+	if (cur->i != args->i) {
+	    do_include = true;
+	}
+    }
+
+    // include in result
+    if (do_include) {
+	args->result->insert(key);
+    }
+}
+
+/**
+ * get list of hosts with explicit routing
+ *
+ * @param type the type to get the routing for
+ * @param i the instance to exclude from the result (NULL for not excluding any instance)
+ * @return list of the hosts that have explicit routings to other components than i for the given type
+ */
+std::set<std::string> deliver_routed_hosts(ptype type, instance i) {
+    std::set<std::string> result;
+
+    // get the correct table
+    xht deliver_table = deliver_hashtable(type);
+
+    // create walker params
+    deliver_routed_hosts_walk_args* args = new deliver_routed_hosts_walk_args();
+    args->result = &result;
+    args->i = i;
+
+    // walk the table
+    xhash_walk(deliver_table, deliver_routed_hosts_walk, args);
+
+    // destroy arguments struct
+    delete args;
+
+    return result;
+}
+
+/**
  * utility to find the right ilist in the hashtable
  *
  * @param ht the hashtable for the routing of a stanzatype

Modified: branches/RELEASE-1_6_1/jabberd/jabberd.h
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/jabberd.h	Sun Sep  7 17:33:12 2008	(r1531)
+++ branches/RELEASE-1_6_1/jabberd/jabberd.h	Sun Sep  7 17:39:03 2008	(r1532)
@@ -103,6 +103,7 @@
 #include <jabberdlib.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
+#include <set>
 
 #ifdef HAVE_GNUTLS_EXTRA
 #  include <gnutls/extra.h>
@@ -209,6 +210,7 @@
 void deliver_instance(instance i, dpacket p); /* deliver packet TO the instance, if the result != r_DONE, you have to handle the packet! */
 instance deliver_hostcheck(char *host); /* util that returns the instance handling this hostname for normal packets */
 bool deliver_is_uplink(instance i); // checks if an instance is configured to be the uplink
+std::set<std::string> deliver_routed_hosts(ptype type, instance i);
 
 /*** global logging/signal symbols ***/
 #define LOGT_LEGACY 1


More information about the dev mailing list