You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2018/11/09 20:01:05 UTC

qpid-dispatch git commit: DISPATCH-1178 - If router-id is not specified, the router provides a randomly generated id.

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 6160a35dc -> 2caa83f17


DISPATCH-1178 - If router-id is not specified, the router provides a randomly generated id.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/2caa83f1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/2caa83f1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/2caa83f1

Branch: refs/heads/master
Commit: 2caa83f17e029c0bdc2d210d36d24bb2f344a569
Parents: 6160a35
Author: Ted Ross <tr...@redhat.com>
Authored: Fri Nov 9 15:00:26 2018 -0500
Committer: Ted Ross <tr...@redhat.com>
Committed: Fri Nov 9 15:00:26 2018 -0500

----------------------------------------------------------------------
 ...ewing-default-router-configuration-file.adoc |  2 +-
 etc/qdrouterd.conf                              |  1 -
 include/qpid/dispatch/discriminator.h           | 34 +++++++++++++++++
 python/qpid_dispatch/management/qdrouter.json   |  2 +-
 src/CMakeLists.txt                              |  1 +
 src/discriminator.c                             | 40 ++++++++++++++++++++
 src/dispatch.c                                  | 25 ++++++++++--
 src/router_core/connections.c                   | 36 +++++-------------
 src/router_node.c                               |  7 ----
 9 files changed, 107 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/docs/books/user-guide/modules/viewing-default-router-configuration-file.adoc
----------------------------------------------------------------------
diff --git a/docs/books/user-guide/modules/viewing-default-router-configuration-file.adoc b/docs/books/user-guide/modules/viewing-default-router-configuration-file.adoc
index 80300fa..5963098 100644
--- a/docs/books/user-guide/modules/viewing-default-router-configuration-file.adoc
+++ b/docs/books/user-guide/modules/viewing-default-router-configuration-file.adoc
@@ -83,7 +83,7 @@ address {
 }
 ----
 <1> By default, the router operates in _standalone_ mode. This means that it can only communicate with endpoints that are directly connected to it. It cannot connect to other routers, or participate in a router network.
-<2> The unique identifier of the router. This ID is used as the `container-id` (container name) at the AMQP protocol level. It is required, and the router will not start if this attribute is not defined.
+<2> The unique identifier of the router. This ID is used as the `container-id` (container name) at the AMQP protocol level. If it is not specified, the router shall generate a random identifier at startup.
 <3> The `listener` entity handles incoming connections from client endpoints. By default, the router listens on all network interfaces on the default AMQP port (5672).
 <4> By default, the router is configured to use the message routing mechanism. Each `address` entity defines how messages that are received with a particular address `prefix` should be distributed. For example, all messages with addresses that start with `closest` will be distributed using the `closest` distribution pattern.
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/etc/qdrouterd.conf
----------------------------------------------------------------------
diff --git a/etc/qdrouterd.conf b/etc/qdrouterd.conf
index 4e8e506..42927e3 100644
--- a/etc/qdrouterd.conf
+++ b/etc/qdrouterd.conf
@@ -22,7 +22,6 @@
 
 router {
     mode: standalone
-    id: Router.A
 }
 
 listener {

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/include/qpid/dispatch/discriminator.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/discriminator.h b/include/qpid/dispatch/discriminator.h
new file mode 100644
index 0000000..8666ffd
--- /dev/null
+++ b/include/qpid/dispatch/discriminator.h
@@ -0,0 +1,34 @@
+#ifndef __dispatch_discriminator_h__
+#define __dispatch_discriminator_h__ 1
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#define QD_DISCRIMINATOR_SIZE 16
+
+/**
+ * Generate a random discriminator in the supplied string, not to exceed
+ * QD_DISCRIMINATOR_SIZE characters.  Such a discriminator may be used in
+ * identifiers, addresses, and other situations where a unique string is needed.
+ */
+void qd_generate_discriminator(char *string);
+
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/python/qpid_dispatch/management/qdrouter.json
----------------------------------------------------------------------
diff --git a/python/qpid_dispatch/management/qdrouter.json b/python/qpid_dispatch/management/qdrouter.json
index 9a1e778..5dbb8b5 100644
--- a/python/qpid_dispatch/management/qdrouter.json
+++ b/python/qpid_dispatch/management/qdrouter.json
@@ -374,7 +374,7 @@
             "singleton": true,
             "attributes": {
                 "id": {
-                    "description":"Router's unique identity. The router will fail to start without id.",
+                    "description":"Router's unique identity. If not specified, a random identity will be assigned at startup.",
                     "type": "string",
                     "required": false,
                     "create": true

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 35a1471..ebc0e09 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -60,6 +60,7 @@ set(qpid_dispatch_SOURCES
   compose.c
   connection_manager.c
   container.c
+  discriminator.c
   dispatch.c
   entity.c
   entity_cache.c

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/src/discriminator.c
----------------------------------------------------------------------
diff --git a/src/discriminator.c b/src/discriminator.c
new file mode 100644
index 0000000..1604d0f
--- /dev/null
+++ b/src/discriminator.c
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <qpid/dispatch/discriminator.h>
+#include <stdlib.h>
+
+void qd_generate_discriminator(char *string)
+{
+    static const char *table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+_";
+    long int rnd1 = random();
+    long int rnd2 = random();
+    long int rnd3 = random();
+    int      idx;
+    int      cursor = 0;
+
+    for (idx = 0; idx < 5; idx++) {
+        string[cursor++] = table[(rnd1 >> (idx * 6)) & 63];
+        string[cursor++] = table[(rnd2 >> (idx * 6)) & 63];
+        string[cursor++] = table[(rnd3 >> (idx * 6)) & 63];
+    }
+    string[cursor] = '\0';
+
+}
+

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/src/dispatch.c
----------------------------------------------------------------------
diff --git a/src/dispatch.c b/src/dispatch.c
index 9fb2186..a6bd256 100644
--- a/src/dispatch.c
+++ b/src/dispatch.c
@@ -24,6 +24,8 @@
 #include <qpid/dispatch/ctools.h>
 #include <qpid/dispatch/static_assert.h>
 #include <qpid/dispatch/alloc.h>
+#include <qpid/dispatch/discriminator.h>
+#include <stdlib.h>
 
 #include "config.h"
 #include "dispatch_private.h"
@@ -60,6 +62,13 @@ const char     *UNAVAILABLE_DISTRIBUTION = "unavailable";
 
 qd_dispatch_t *qd_dispatch(const char *python_pkgdir, bool test_hooks)
 {
+    //
+    // Seed the random number generator
+    //
+    struct timeval time;
+    gettimeofday(&time, NULL);
+    srandom((unsigned int)time.tv_sec + ((unsigned int)time.tv_usec << 11));
+    
     qd_dispatch_t *qd = NEW(qd_dispatch_t);
     ZERO(qd);
 
@@ -176,13 +185,21 @@ qd_error_t qd_dispatch_configure_router(qd_dispatch_t *qd, qd_entity_t *entity)
 {
     qd_dispatch_set_router_default_distribution(qd, qd_entity_opt_string(entity, "defaultDistribution", 0)); QD_ERROR_RET();
     qd_dispatch_set_router_id(qd, qd_entity_opt_string(entity, "id", 0)); QD_ERROR_RET();
+    qd->router_mode = qd_entity_get_long(entity, "mode"); QD_ERROR_RET();
     if (!qd->router_id) {
-        qd_log_source_t *router_log = qd_log_source("ROUTER");
-        qd_log(router_log, QD_LOG_CRITICAL, "Router Id not specified - process exiting");
-        exit(1);
+        char *mode;
+        switch (qd->router_mode) {
+        case QD_ROUTER_MODE_STANDALONE: mode = "Standalone_"; break;
+        case QD_ROUTER_MODE_INTERIOR:   mode = "Interior_";   break;
+        case QD_ROUTER_MODE_EDGE:       mode = "Edge_";       break;
+        case QD_ROUTER_MODE_ENDPOINT:   mode = "Endpoint_";   break;
+        }
+        
+        qd->router_id = (char*) malloc(strlen(mode) + QD_DISCRIMINATOR_SIZE + 2);
+        strcpy(qd->router_id, mode);
+        qd_generate_discriminator(qd->router_id + strlen(qd->router_id));
     }
 
-    qd->router_mode = qd_entity_get_long(entity, "mode"); QD_ERROR_RET();
     qd->thread_count = qd_entity_opt_long(entity, "workerThreads", 4); QD_ERROR_RET();
     qd->allow_resumable_link_route = qd_entity_opt_bool(entity, "allowResumableLinkRoute", true); QD_ERROR_RET();
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/src/router_core/connections.c
----------------------------------------------------------------------
diff --git a/src/router_core/connections.c b/src/router_core/connections.c
index a5e8a38..1ca6324 100644
--- a/src/router_core/connections.c
+++ b/src/router_core/connections.c
@@ -18,6 +18,7 @@
  */
 
 #include <qpid/dispatch/router_core.h>
+#include <qpid/dispatch/discriminator.h>
 #include "route_control.h"
 #include <qpid/dispatch/amqp.h>
 #include <stdio.h>
@@ -605,33 +606,14 @@ void qdr_link_enqueue_work_CT(qdr_core_t      *core,
 }
 
 
-#define QDR_DISCRIMINATOR_SIZE 16
-static void qdr_generate_discriminator(char *string)
-{
-    static const char *table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+_";
-    long int rnd1 = random();
-    long int rnd2 = random();
-    long int rnd3 = random();
-    int      idx;
-    int      cursor = 0;
-
-    for (idx = 0; idx < 5; idx++) {
-        string[cursor++] = table[(rnd1 >> (idx * 6)) & 63];
-        string[cursor++] = table[(rnd2 >> (idx * 6)) & 63];
-        string[cursor++] = table[(rnd3 >> (idx * 6)) & 63];
-    }
-    string[cursor] = '\0';
-}
-
-
 /**
  * Generate a temporary routable address for a destination connected to this
  * router node.
  */
 static void qdr_generate_temp_addr(qdr_core_t *core, char *buffer, size_t length)
 {
-    char discriminator[QDR_DISCRIMINATOR_SIZE];
-    qdr_generate_discriminator(discriminator);
+    char discriminator[QD_DISCRIMINATOR_SIZE];
+    qd_generate_discriminator(discriminator);
     if (core->router_mode == QD_ROUTER_MODE_EDGE)
         snprintf(buffer, length, "amqp:/_edge/%s/temp.%s", core->router_id, discriminator);
     else
@@ -645,8 +627,8 @@ static void qdr_generate_temp_addr(qdr_core_t *core, char *buffer, size_t length
  */
 static void qdr_generate_mobile_addr(qdr_core_t *core, char *buffer, size_t length)
 {
-    char discriminator[QDR_DISCRIMINATOR_SIZE];
-    qdr_generate_discriminator(discriminator);
+    char discriminator[QD_DISCRIMINATOR_SIZE];
+    qd_generate_discriminator(discriminator);
     snprintf(buffer, length, "amqp:/_$temp.%s", discriminator);
 }
 
@@ -656,8 +638,8 @@ static void qdr_generate_mobile_addr(qdr_core_t *core, char *buffer, size_t leng
  */
 static void qdr_generate_link_name(const char *label, char *buffer, size_t length)
 {
-    char discriminator[QDR_DISCRIMINATOR_SIZE];
-    qdr_generate_discriminator(discriminator);
+    char discriminator[QD_DISCRIMINATOR_SIZE];
+    qd_generate_discriminator(discriminator);
     snprintf(buffer, length, "%s.%s", label, discriminator);
 }
 
@@ -917,10 +899,10 @@ qdr_link_t *qdr_create_link_CT(qdr_core_t       *core,
     link->link_direction = dir;
     link->capacity       = conn->link_capacity;
     link->credit_pending = conn->link_capacity;
-    link->name           = (char*) malloc(QDR_DISCRIMINATOR_SIZE + 8);
+    link->name           = (char*) malloc(QD_DISCRIMINATOR_SIZE + 8);
     link->disambiguated_name = 0;
     link->terminus_addr  = 0;
-    qdr_generate_link_name("qdlink", link->name, QDR_DISCRIMINATOR_SIZE + 8);
+    qdr_generate_link_name("qdlink", link->name, QD_DISCRIMINATOR_SIZE + 8);
     link->admin_enabled  = true;
     link->oper_status    = QDR_LINK_OPER_DOWN;
     link->insert_prefix = 0;

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2caa83f1/src/router_node.c
----------------------------------------------------------------------
diff --git a/src/router_node.c b/src/router_node.c
index 96525ee..84472fc 100644
--- a/src/router_node.c
+++ b/src/router_node.c
@@ -1263,13 +1263,6 @@ qd_router_t *qd_router(qd_dispatch_t *qd, qd_router_mode_t mode, const char *are
     //
     qd_iterator_set_address(mode == QD_ROUTER_MODE_EDGE, area, id);
 
-    //
-    // Seed the random number generator
-    //
-    struct timeval time;
-    gettimeofday(&time, NULL);
-    srandom((unsigned int)time.tv_sec + ((unsigned int)time.tv_usec << 11));
-
     switch (router->router_mode) {
     case QD_ROUTER_MODE_STANDALONE: qd_log(router->log_source, QD_LOG_INFO, "Router started in Standalone mode");  break;
     case QD_ROUTER_MODE_INTERIOR:   qd_log(router->log_source, QD_LOG_INFO, "Router started in Interior mode, area=%s id=%s", area, id);  break;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org