From 645374a485fb5bdba1a4fa5c728837981dcecad0 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 14:52:30 +0800 Subject: [PATCH 01/11] Added coverage test --- .gitignore | 3 ++- package.json | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 123ae94..09c0cc1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,9 @@ pids # Directory for instrumented libs generated by jscoverage/JSCover lib-cov -# Coverage directory used by tools like istanbul +# Coverage directory used by tools like nyc coverage +.nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt diff --git a/package.json b/package.json index 0c0a407..ac5edb0 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,14 @@ "dependencies": {}, "devDependencies": { "faucet": "0.0.1", - "pre-commit": "^1.1.2", - "standard": "^5.4.1", - "tape": "^4.2.2" + "nyc": "^14.1.1", + "pre-commit": "^1.2.2", + "standard": "^13.0.2", + "tape": "^4.11.0" }, "scripts": { - "test": "standard && tape test.js | faucet" + "test": "standard && tape test.js | faucet", + "coverage": "nyc --reporter=lcov tape test.js" }, "repository": { "type": "git", From 05d21d20902ec155b11d02f16a918d5a352c3b0d Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 14:53:17 +0800 Subject: [PATCH 02/11] Support nodejs 6, 8, 10 & 12 --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 91b317c..db95448 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: node_js node_js: - - "0.10" - - "0.12" - - "4" - - "5" + - 0.10 + - 0.12 + - 4 + - 6 + - 8 + - 10 + - 12 From 3621bd8b85522fbe04eac7970812b9279c303cb1 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 17:30:09 +0800 Subject: [PATCH 03/11] Not to mix && and || --- packet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packet.js b/packet.js index da81391..c99ed2d 100644 --- a/packet.js +++ b/packet.js @@ -3,7 +3,7 @@ function Packet (original, broker) { this.cmd = original.cmd || 'publish' this.brokerId = original.brokerId || (broker && broker.id) - this.brokerCounter = original.brokerCounter || (broker && (++broker.counter) || 0) + this.brokerCounter = original.brokerCounter || (broker ? (++broker.counter) : 0) this.topic = original.topic this.payload = original.payload || new Buffer(0) this.qos = original.qos || 0 From d4d47734ad1e14e34291e336eb03b93057fa6ea1 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 17:30:51 +0800 Subject: [PATCH 04/11] Not to use deprecated new Buffer(0) --- packet.js | 2 +- test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packet.js b/packet.js index c99ed2d..7d32c07 100644 --- a/packet.js +++ b/packet.js @@ -5,7 +5,7 @@ function Packet (original, broker) { this.brokerId = original.brokerId || (broker && broker.id) this.brokerCounter = original.brokerCounter || (broker ? (++broker.counter) : 0) this.topic = original.topic - this.payload = original.payload || new Buffer(0) + this.payload = original.payload || Buffer.alloc(0) this.qos = original.qos || 0 this.retain = original.retain || false this.messageId = 0 diff --git a/test.js b/test.js index 953764c..ab60150 100644 --- a/test.js +++ b/test.js @@ -9,7 +9,7 @@ test('Packet defaults', function (t) { t.equal(instance.brokerId, undefined) t.equal(instance.brokerCounter, 0) t.equal(instance.topic, undefined) - t.deepEqual(instance.payload, new Buffer(0)) + t.deepEqual(instance.payload, Buffer.alloc(0)) t.equal(instance.qos, 0) t.equal(instance.retain, false) t.equal(instance.messageId, 0) From 5ecdd3010d5ba2de46d94a9c46912065a23bed08 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 17:44:04 +0800 Subject: [PATCH 05/11] QoS 0 PUBLISH not contain packet identifier --- packet.js | 7 ++++++- test.js | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/packet.js b/packet.js index 7d32c07..b29024a 100644 --- a/packet.js +++ b/packet.js @@ -8,7 +8,12 @@ function Packet (original, broker) { this.payload = original.payload || Buffer.alloc(0) this.qos = original.qos || 0 this.retain = original.retain || false - this.messageId = 0 + // [MQTT-2.3.1-5] + // qos = 0 and publish + if (this.qos > 0 || this.cmd !== 'publish') { + // [MQTT-2.3.1-1] + this.messageId = original.messageId || 1 + } } module.exports = Packet diff --git a/test.js b/test.js index ab60150..250e3f7 100644 --- a/test.js +++ b/test.js @@ -3,7 +3,7 @@ var test = require('tape') var Packet = require('./') -test('Packet defaults', function (t) { +test('Packet defaults - PUBLISH, QoS 0', function (t) { var instance = new Packet({}) t.equal(instance.cmd, 'publish') t.equal(instance.brokerId, undefined) @@ -12,7 +12,33 @@ test('Packet defaults', function (t) { t.deepEqual(instance.payload, Buffer.alloc(0)) t.equal(instance.qos, 0) t.equal(instance.retain, false) - t.equal(instance.messageId, 0) + t.equal(instance.messageId, undefined) + t.end() +}) + +test('Packet defaults - PUBREL, QoS 0', function (t) { + var instance = new Packet({ cmd: 'pubrel' }) + t.equal(instance.cmd, 'pubrel') + t.equal(instance.brokerId, undefined) + t.equal(instance.brokerCounter, 0) + t.equal(instance.topic, undefined) + t.deepEqual(instance.payload, Buffer.alloc(0)) + t.equal(instance.qos, 0) + t.equal(instance.retain, false) + t.equal(instance.messageId, 1) + t.end() +}) + +test('Packet defaults - PUBLISH, QoS 1', function (t) { + var instance = new Packet({ qos: 1 }) + t.equal(instance.cmd, 'publish') + t.equal(instance.brokerId, undefined) + t.equal(instance.brokerCounter, 0) + t.equal(instance.topic, undefined) + t.deepEqual(instance.payload, Buffer.alloc(0)) + t.equal(instance.qos, 1) + t.equal(instance.retain, false) + t.equal(instance.messageId, 1) t.end() }) @@ -36,7 +62,7 @@ test('Packet copies over most data', function (t) { payload: 'world', qos: 2, retain: true, - messageId: 0 // this is different + messageId: 24 } t.deepEqual(instance, expected) @@ -65,7 +91,7 @@ test('Packet fills in broker data', function (t) { payload: 'world', qos: 2, retain: true, - messageId: 0 // this is different + messageId: 24 } t.deepEqual(instance, expected) From a11cbe6ce216ee8429a3084965d14a8d70f29dab Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 17:44:38 +0800 Subject: [PATCH 06/11] Bumped to 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ac5edb0..cf283e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aedes-packet", - "version": "1.0.0", + "version": "2.0.0", "description": "Basic data structure for packets in Aedes ", "main": "packet.js", "dependencies": {}, From 7ec5b6bfc487599bfc3d1338777c61c3309fd864 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 17:45:10 +0800 Subject: [PATCH 07/11] Removed extra comment --- packet.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packet.js b/packet.js index b29024a..675fc39 100644 --- a/packet.js +++ b/packet.js @@ -9,7 +9,6 @@ function Packet (original, broker) { this.qos = original.qos || 0 this.retain = original.retain || false // [MQTT-2.3.1-5] - // qos = 0 and publish if (this.qos > 0 || this.cmd !== 'publish') { // [MQTT-2.3.1-1] this.messageId = original.messageId || 1 From 3d45de25f18d30f6c5d62e599f8ebc2527150b73 Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 17:50:30 +0800 Subject: [PATCH 08/11] Drop nodejs 0.10, 0.12 support --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index db95448..f04f381 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: - - 0.10 - - 0.12 - 4 - 6 - 8 From 536a4a53425295383f7e5ac12941e63c81528d3a Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 13 Jul 2019 18:01:21 +0800 Subject: [PATCH 09/11] Restored messageId as a locked field --- packet.js | 2 +- test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packet.js b/packet.js index 675fc39..d084269 100644 --- a/packet.js +++ b/packet.js @@ -11,7 +11,7 @@ function Packet (original, broker) { // [MQTT-2.3.1-5] if (this.qos > 0 || this.cmd !== 'publish') { // [MQTT-2.3.1-1] - this.messageId = original.messageId || 1 + this.messageId = 1 } } diff --git a/test.js b/test.js index 250e3f7..ad3301c 100644 --- a/test.js +++ b/test.js @@ -62,7 +62,7 @@ test('Packet copies over most data', function (t) { payload: 'world', qos: 2, retain: true, - messageId: 24 + messageId: 1 // this is different } t.deepEqual(instance, expected) @@ -91,7 +91,7 @@ test('Packet fills in broker data', function (t) { payload: 'world', qos: 2, retain: true, - messageId: 24 + messageId: 1 // this is different } t.deepEqual(instance, expected) From 57e9aa16dcd612e28b083cf98189e8c0effd7e75 Mon Sep 17 00:00:00 2001 From: Gnought <1684105+gnought@users.noreply.github.com> Date: Mon, 15 Jul 2019 17:46:14 +0800 Subject: [PATCH 10/11] Removed nodejs 4 & 6 support --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f04f381..d72655c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: - - 4 - - 6 - 8 - 10 - 12 From 478f89cff414e4e6377fadc064bad2f5481be043 Mon Sep 17 00:00:00 2001 From: Gnought <1684105+gnought@users.noreply.github.com> Date: Mon, 15 Jul 2019 17:46:41 +0800 Subject: [PATCH 11/11] Restore bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf283e4..ac5edb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aedes-packet", - "version": "2.0.0", + "version": "1.0.0", "description": "Basic data structure for packets in Aedes ", "main": "packet.js", "dependencies": {},