From accc2792a2e08634a08fdb2acf5423fac8b24f30 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Mon, 2 Sep 2019 23:13:01 +0800 Subject: [PATCH 1/2] Use uuid for broker id while shortid for client id --- aedes.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aedes.js b/aedes.js index 49a99959..e3e04834 100644 --- a/aedes.js +++ b/aedes.js @@ -6,7 +6,7 @@ var util = require('util') var memory = require('aedes-persistence') var parallel = require('fastparallel') var series = require('fastseries') -var shortid = require('shortid') +var uuidv5 = require('uuid/v5') var Packet = require('aedes-packet') var bulk = require('bulk-write-stream') var reusify = require('reusify') @@ -36,12 +36,13 @@ function Aedes (opts) { opts = Object.assign({}, defaultOptions, opts) - this.id = opts.id || shortid() + this.id = opts.id || uuidv5('https://github.com/mcollina/aedes', uuidv5.URL) this.counter = 0 this.connectTimeout = opts.connectTimeout this.mq = opts.mq || mqemitter(opts) this.handle = function handle (conn) { conn.setMaxListeners(opts.concurrency * 2) + // create a new Client instance for a new connection // return, just to please standard return new Client(that, conn) } @@ -244,8 +245,7 @@ Aedes.prototype.unsubscribe = function (topic, func, done) { Aedes.prototype.registerClient = function (client) { var that = this if (this.clients[client.id]) { - // moving out so we wait for this, so we don't - // unregister a good client + // [MQTT-3.1.4-2] this.clients[client.id].close(function closeClient () { that._finishRegisterClient(client) }) From 9be3209859f031ae047728bd88d0105da8547ea3 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Mon, 2 Sep 2019 23:17:02 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1092ef59..c1fe06f9 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Options: * `connectTimeout`: the max number of milliseconds to wait for the CONNECT packet to arrive, defaults to `30000` milliseconds * `id`: id used to identify this broker instance in `$SYS` messages, - defaults to `shortid()` + defaults to `uuidv5()` * `preConnect`: function called when a valid CONNECT is received, see [instance.preConnect()](#preConnect) * `authenticate`: function used to authenticate clients, see @@ -376,7 +376,7 @@ Events: ### client#id -The id of the client, as specified by the CONNECT packet. +The id of the client, as specified by the CONNECT packet, defaults to 'aedes_' + shortid() -------------------------------------------------------