From 9c99e2f3edbee5ea174edcc483ccabbb2e56759a Mon Sep 17 00:00:00 2001 From: ldstein Date: Fri, 10 Jan 2014 14:09:19 +0800 Subject: [PATCH 1/2] Bumped async_bench to allow dev depencies to be installed in Windows. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 286fc81..d7ceefc 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "sinon": "~1.7.3", "sinon-chai": "~2.4.0", "optimist": "~0.6.0", - "async_bench": "~0.1.0", + "async_bench": "~0.3.0", "dox-foundation": "0.5.4", "mosca": "git://github.com/mcollina/mosca.git", "jshint": "~2.3.0", From 7b4da72c65a000fbfb6679a72a72552cc02dac71 Mon Sep 17 00:00:00 2001 From: ldstein Date: Fri, 10 Jan 2014 14:42:21 +0800 Subject: [PATCH 2/2] Added ability to connect to secure MQTT broker. --- README.md | 5 ++++- lib/mqtt_ascoltatore.js | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1ecfb1e..393c5bb 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,10 @@ settings = { json: false, mqtt: require('mqtt'), host: '127.0.0.1', - port: 1883 + port: 1883, + keyPath: 'path/to/cert.key', + certPath: 'path/to/cert.cert', + rejectUnauthorized: true }; ascoltatori.build(settings, function (ascoltatore) { diff --git a/lib/mqtt_ascoltatore.js b/lib/mqtt_ascoltatore.js index c008d12..07e746a 100644 --- a/lib/mqtt_ascoltatore.js +++ b/lib/mqtt_ascoltatore.js @@ -18,7 +18,9 @@ var SubsCounter = require("./subs_counter"); * - `port`, the port to connect to; * - `host`, the host to connect to; * - `mqtt`, the mqtt module (it will automatically be required if not present). - * + * - `keyPath`, path to TLS-key (optional, used for connecting to a secure broker). + * - `certPath`, path to TLS-certificate (optional, for connecting to a secure broker). + * - `rejectUnauthorized`, Reject unauthorized connections (optional, for connecting to a secure broker). * @api public * @param {Object} opts The options object */ @@ -50,15 +52,23 @@ MQTTAscoltatore.prototype = Object.create(AbstractAscoltatore.prototype); */ MQTTAscoltatore.prototype._startConn = function() { var that = this, - settings = null; + settings = null, + createMethod = 'createClient'; if (this._client === undefined) { settings = { keepalive: that._opts.keepalive, - clientId: that._opts.clientId, + clientId: that._opts.clientId }; + if(that._opts.keyPath) settings.keyPath = that._opts.keyPath; + if(that._opts.certPath) settings.certPath = that._opts.certPath; + if(that._opts.rejectUnauthorized) settings.rejectUnauthorized = that._opts.rejectUnauthorized; + if(settings.certPath || settings.keyPath) { + createMethod = 'createSecureClient'; + } + debug("connecting.."); - this._client = that._opts.mqtt.createClient(that._opts.port, that._opts.host, settings); + this._client = that._opts.mqtt[createMethod](that._opts.port, that._opts.host, settings); this._client.setMaxListeners(0); this._client.on("connect", function() { debug("connected");