aedes 0.51.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/sticky-pr-comment/action.yml +55 -0
- package/.github/workflows/benchmark-compare-serial.yml +60 -0
- package/.github/workflows/ci.yml +12 -17
- package/.release-it.json +18 -0
- package/.taprc +15 -6
- package/README.md +6 -4
- package/aedes.d.ts +0 -6
- package/aedes.js +270 -242
- package/benchmarks/README.md +33 -0
- package/benchmarks/pingpong.js +94 -25
- package/benchmarks/receiver.js +77 -0
- package/benchmarks/report.js +150 -0
- package/benchmarks/runBenchmarks.js +118 -0
- package/benchmarks/sender.js +86 -0
- package/benchmarks/server.js +19 -18
- package/checkVersion.js +20 -0
- package/docs/Aedes.md +66 -8
- package/docs/Client.md +3 -4
- package/docs/Examples.md +39 -22
- package/docs/MIGRATION.md +50 -0
- package/eslint.config.js +8 -0
- package/example.js +51 -40
- package/examples/clusters/index.js +28 -23
- package/examples/clusters/package.json +10 -6
- package/lib/client.js +405 -306
- package/lib/handlers/connect.js +42 -38
- package/lib/handlers/index.js +9 -11
- package/lib/handlers/ping.js +2 -3
- package/lib/handlers/puback.js +5 -5
- package/lib/handlers/publish.js +29 -14
- package/lib/handlers/pubrec.js +9 -17
- package/lib/handlers/pubrel.js +34 -25
- package/lib/handlers/subscribe.js +47 -43
- package/lib/handlers/unsubscribe.js +16 -19
- package/lib/qos-packet.js +14 -17
- package/lib/utils.js +5 -12
- package/lib/write.js +4 -5
- package/package.json +134 -136
- package/test/auth.js +468 -804
- package/test/basic.js +613 -575
- package/test/bridge.js +44 -40
- package/test/client-pub-sub.js +531 -504
- package/test/close_socket_by_other_party.js +137 -102
- package/test/connect.js +487 -484
- package/test/drain-timeout.js +593 -0
- package/test/drain-toxiproxy.js +620 -0
- package/test/events.js +173 -145
- package/test/helper.js +351 -73
- package/test/keep-alive.js +40 -67
- package/test/meta.js +257 -210
- package/test/not-blocking.js +93 -197
- package/test/qos1.js +464 -554
- package/test/qos2.js +308 -393
- package/test/regr-21.js +39 -21
- package/test/require.cjs +22 -0
- package/test/retain.js +349 -398
- package/test/topics.js +176 -183
- package/test/types/aedes.test-d.ts +4 -8
- package/test/will.js +310 -428
- package/types/instance.d.ts +40 -35
- package/types/packet.d.ts +10 -10
- package/.coveralls.yml +0 -1
- package/benchmarks/bombing.js +0 -34
- package/benchmarks/bombingQoS1.js +0 -36
- package/benchmarks/throughputCounter.js +0 -23
- package/benchmarks/throughputCounterQoS1.js +0 -33
- package/types/.eslintrc.json +0 -47
package/lib/handlers/connect.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import retimer from 'retimer'
|
|
2
|
+
import { pipeline } from 'stream'
|
|
3
|
+
import write from '../write.js'
|
|
4
|
+
import QoSPacket from '../qos-packet.js'
|
|
5
|
+
import { through } from '../utils.js'
|
|
6
|
+
import handleSubscribe from './subscribe.js'
|
|
7
|
+
import hyperid from 'hyperid'
|
|
2
8
|
|
|
3
|
-
const
|
|
4
|
-
const { pipeline } = require('stream')
|
|
5
|
-
const write = require('../write')
|
|
6
|
-
const QoSPacket = require('../qos-packet')
|
|
7
|
-
const { through } = require('../utils')
|
|
8
|
-
const handleSubscribe = require('./subscribe')
|
|
9
|
-
const uniqueId = require('hyperid')()
|
|
9
|
+
const uniqueId = hyperid()
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
class Connack {
|
|
12
|
+
constructor (arg) {
|
|
13
|
+
this.cmd = 'connack'
|
|
14
|
+
this.returnCode = arg.returnCode
|
|
15
|
+
this.sessionPresent = arg.sessionPresent
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
class ClientPacketStatus {
|
|
20
|
+
constructor (client, packet) {
|
|
21
|
+
this.client = client
|
|
22
|
+
this.packet = packet
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
const connectActions = [
|
|
@@ -159,24 +163,22 @@ function setKeepAlive (arg, done) {
|
|
|
159
163
|
function fetchSubs (arg, done) {
|
|
160
164
|
const client = this.client
|
|
161
165
|
if (!this.packet.clean) {
|
|
162
|
-
|
|
166
|
+
const subsClient = {
|
|
163
167
|
id: client.id,
|
|
164
168
|
done,
|
|
165
169
|
arg
|
|
166
|
-
}
|
|
170
|
+
}
|
|
171
|
+
client.broker.persistence.subscriptionsByClient({ id: client.id })
|
|
172
|
+
.then(subs => gotSubs(subs, subsClient), subsClient.done)
|
|
167
173
|
return
|
|
168
174
|
}
|
|
169
175
|
arg.sessionPresent = false // [MQTT-3.2.2-1]
|
|
170
|
-
client.broker.persistence.cleanSubscriptions(
|
|
171
|
-
|
|
172
|
-
done)
|
|
176
|
+
client.broker.persistence.cleanSubscriptions(client)
|
|
177
|
+
.then(() => done(null), done)
|
|
173
178
|
}
|
|
174
179
|
|
|
175
|
-
function gotSubs (
|
|
176
|
-
|
|
177
|
-
return client.done(err)
|
|
178
|
-
}
|
|
179
|
-
client.arg.subs = subs
|
|
180
|
+
function gotSubs (subs, client) {
|
|
181
|
+
client.arg.subs = subs.length > 0 ? subs : null
|
|
180
182
|
client.done()
|
|
181
183
|
}
|
|
182
184
|
|
|
@@ -194,16 +196,15 @@ function storeWill (arg, done) {
|
|
|
194
196
|
const client = this.client
|
|
195
197
|
client.will = client._will
|
|
196
198
|
// delete any existing will messages from persistence
|
|
197
|
-
client.broker.persistence.delWill(client
|
|
198
|
-
|
|
199
|
-
client.
|
|
200
|
-
client,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
})
|
|
199
|
+
client.broker.persistence.delWill(client)
|
|
200
|
+
.finally(() => {
|
|
201
|
+
if (client.will) {
|
|
202
|
+
client.broker.persistence.putWill(client, client.will)
|
|
203
|
+
.then(() => done(null, client), done)
|
|
204
|
+
} else {
|
|
205
|
+
done()
|
|
206
|
+
}
|
|
207
|
+
})
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
function registerClient (arg, done) {
|
|
@@ -242,7 +243,9 @@ function emptyQueue (arg, done) {
|
|
|
242
243
|
// Object filled the buffer up to the highWaterMark preventing stored messages
|
|
243
244
|
// being sent
|
|
244
245
|
packet.writeCallback = (error, _client) => next(error)
|
|
245
|
-
|
|
246
|
+
const filter = (err) => emptyQueueFilter(err, client, packet)
|
|
247
|
+
persistence.outgoingUpdate(client, packet)
|
|
248
|
+
.then(() => filter(null, client, packet), err => filter(err, client, packet))
|
|
246
249
|
}),
|
|
247
250
|
done
|
|
248
251
|
)
|
|
@@ -263,10 +266,11 @@ function emptyQueueFilter (err, client, packet) {
|
|
|
263
266
|
const persistence = client.broker.persistence
|
|
264
267
|
|
|
265
268
|
if (client.clean || !authorized) {
|
|
266
|
-
persistence.outgoingClearMessageId(client, packet
|
|
269
|
+
persistence.outgoingClearMessageId(client, packet)
|
|
270
|
+
.then(packet => next(null, packet), next)
|
|
267
271
|
} else {
|
|
268
272
|
write(client, packet, next)
|
|
269
273
|
}
|
|
270
274
|
}
|
|
271
275
|
|
|
272
|
-
|
|
276
|
+
export default handleConnect
|
package/lib/handlers/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const handlePubrec = require('./pubrec')
|
|
10
|
-
const handlePing = require('./ping')
|
|
1
|
+
import handleConnect from './connect.js'
|
|
2
|
+
import handleSubscribe from './subscribe.js'
|
|
3
|
+
import handleUnsubscribe from './unsubscribe.js'
|
|
4
|
+
import handlePublish from './publish.js'
|
|
5
|
+
import handlePuback from './puback.js'
|
|
6
|
+
import handlePubrel from './pubrel.js'
|
|
7
|
+
import handlePubrec from './pubrec.js'
|
|
8
|
+
import handlePing from './ping.js'
|
|
11
9
|
|
|
12
10
|
function handle (client, packet, done) {
|
|
13
11
|
if (packet.cmd === 'connect') {
|
|
@@ -74,4 +72,4 @@ function finish (conn, packet, done) {
|
|
|
74
72
|
done(error)
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
|
|
75
|
+
export default handle
|
package/lib/handlers/ping.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import write from '../write.js'
|
|
2
2
|
|
|
3
|
-
const write = require('../write')
|
|
4
3
|
const pingResp = {
|
|
5
4
|
cmd: 'pingresp'
|
|
6
5
|
}
|
|
@@ -10,4 +9,4 @@ function handlePing (client, packet, done) {
|
|
|
10
9
|
write(client, pingResp, done)
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
export default handlePing
|
package/lib/handlers/puback.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
function handlePuback (client, packet, done) {
|
|
4
2
|
const persistence = client.broker.persistence
|
|
5
|
-
|
|
3
|
+
const emitAck = (err, origPacket) => {
|
|
6
4
|
client.broker.emit('ack', origPacket, client)
|
|
7
5
|
done(err)
|
|
8
|
-
}
|
|
6
|
+
}
|
|
7
|
+
persistence.outgoingClearMessageId(client, packet)
|
|
8
|
+
.then((packet) => emitAck(null, packet), emitAck)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export default handlePuback
|
package/lib/handlers/publish.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import write from '../write.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
class PubAck {
|
|
4
|
+
constructor (packet) {
|
|
5
|
+
this.cmd = 'puback'
|
|
6
|
+
this.messageId = packet.messageId
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
class PubRec {
|
|
11
|
+
constructor (packet) {
|
|
12
|
+
this.cmd = 'pubrec'
|
|
13
|
+
this.messageId = packet.messageId
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const publishActions = [
|
|
@@ -39,10 +41,23 @@ function enqueuePublish (packet, done) {
|
|
|
39
41
|
|
|
40
42
|
switch (packet.qos) {
|
|
41
43
|
case 2:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// MQTT-4.3.3-2: Check if we already have this packet by messageId
|
|
45
|
+
client.broker.persistence.incomingGetPacket(client, packet)
|
|
46
|
+
.then(() => {
|
|
47
|
+
// Duplicate packet: just send PUBREC, don't publish again
|
|
48
|
+
write(client, new PubRec(packet), done)
|
|
49
|
+
}, () => {
|
|
50
|
+
// New packet (not found in store): store first, then publish
|
|
51
|
+
// This ensures if storage fails, message hasn't been delivered yet
|
|
52
|
+
// preventing duplicate delivery on retransmission
|
|
53
|
+
client.broker.persistence.incomingStorePacket(client, packet)
|
|
54
|
+
.then(() => {
|
|
55
|
+
client.broker.publish(packet, client, (err) => {
|
|
56
|
+
if (err) { return done(err) }
|
|
57
|
+
write(client, new PubRec(packet), done)
|
|
58
|
+
})
|
|
59
|
+
}, done)
|
|
60
|
+
})
|
|
46
61
|
break
|
|
47
62
|
case 1:
|
|
48
63
|
write(client, new PubAck(packet), function (err) {
|
|
@@ -62,4 +77,4 @@ function authorizePublish (packet, done) {
|
|
|
62
77
|
this.broker.authorizePublish(this, packet, done)
|
|
63
78
|
}
|
|
64
79
|
|
|
65
|
-
|
|
80
|
+
export default handlePublish
|
package/lib/handlers/pubrec.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import write from '../write.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
class PubRel {
|
|
4
|
+
constructor (packet) {
|
|
5
|
+
this.cmd = 'pubrel'
|
|
6
|
+
this.messageId = packet.messageId
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
function handlePubrec (client, packet, done) {
|
|
@@ -15,16 +15,8 @@ function handlePubrec (client, packet, done) {
|
|
|
15
15
|
return
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
client.broker.persistence.outgoingUpdate(
|
|
19
|
-
client, pubrel,
|
|
20
|
-
|
|
21
|
-
function reply (err) {
|
|
22
|
-
if (err) {
|
|
23
|
-
done(err)
|
|
24
|
-
} else {
|
|
25
|
-
write(client, pubrel, done)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
18
|
+
client.broker.persistence.outgoingUpdate(client, pubrel)
|
|
19
|
+
.then(() => write(client, pubrel, done), done)
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
export default handlePubrec
|
package/lib/handlers/pubrel.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
import write from '../write.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
class ClientPacketStatus {
|
|
4
|
+
constructor (client, packet) {
|
|
5
|
+
this.client = client
|
|
6
|
+
this.packet = packet
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
class PubComp {
|
|
11
|
+
constructor (packet) {
|
|
12
|
+
this.cmd = 'pubcomp'
|
|
13
|
+
this.messageId = packet.messageId
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const pubrelActions = [
|
|
16
18
|
pubrelGet,
|
|
17
|
-
|
|
18
|
-
pubrelWrite
|
|
19
|
-
pubrelDel
|
|
19
|
+
pubrelDelete,
|
|
20
|
+
pubrelWrite
|
|
20
21
|
]
|
|
21
22
|
function handlePubrel (client, packet, done) {
|
|
22
23
|
client.broker._series(
|
|
@@ -25,26 +26,34 @@ function handlePubrel (client, packet, done) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function pubrelGet (arg, done) {
|
|
29
|
+
// MQTT-4.3.3-2: Check if we have this packet in persistence
|
|
28
30
|
const persistence = this.client.broker.persistence
|
|
29
|
-
persistence.incomingGetPacket(this.client, this.packet
|
|
31
|
+
persistence.incomingGetPacket(this.client, this.packet)
|
|
32
|
+
.then((packet) => {
|
|
33
|
+
arg.packet = this.packet
|
|
34
|
+
arg.foundInStore = !!packet
|
|
35
|
+
done(null, arg)
|
|
36
|
+
}, () => {
|
|
37
|
+
// Even if incomingGetPacket fails, continue to send PUBCOMP
|
|
38
|
+
arg.packet = this.packet
|
|
39
|
+
arg.foundInStore = false
|
|
40
|
+
done(null, arg)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
function pubrelDelete (arg, done) {
|
|
45
|
+
// Only delete if we found the packet in the store
|
|
46
|
+
if (!arg.foundInStore) {
|
|
47
|
+
return done(null, arg)
|
|
34
48
|
}
|
|
35
|
-
}
|
|
36
49
|
|
|
37
|
-
|
|
38
|
-
this.client.
|
|
50
|
+
const persistence = this.client.broker.persistence
|
|
51
|
+
persistence.incomingDelPacket(this.client, arg.packet).finally(() => done(null, arg))
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
function pubrelWrite (arg, done) {
|
|
55
|
+
// Always send PUBCOMP, even if packet was not found in store
|
|
42
56
|
write(this.client, new PubComp(arg.packet), done)
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
const persistence = this.client.broker.persistence
|
|
47
|
-
persistence.incomingDelPacket(this.client, arg.packet, done)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = handlePubrel
|
|
59
|
+
export default handlePubrel
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { through } = require('../utils')
|
|
6
|
-
const { validateTopic, $SYS_PREFIX } = require('../utils')
|
|
7
|
-
const write = require('../write')
|
|
1
|
+
import fastfall from 'fastfall'
|
|
2
|
+
import Packet from 'aedes-packet'
|
|
3
|
+
import { through, validateTopic, $SYS_PREFIX } from '../utils.js'
|
|
4
|
+
import write from '../write.js'
|
|
8
5
|
|
|
9
6
|
const subscribeTopicActions = fastfall([
|
|
10
7
|
authorize,
|
|
@@ -16,47 +13,55 @@ const restoreTopicActions = fastfall([
|
|
|
16
13
|
addSubs
|
|
17
14
|
])
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
class SubAck {
|
|
17
|
+
constructor (packet, granted) {
|
|
18
|
+
this.cmd = 'suback'
|
|
19
|
+
this.messageId = packet.messageId
|
|
20
|
+
// the qos granted
|
|
21
|
+
this.granted = granted
|
|
22
|
+
}
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
class Subscription {
|
|
26
|
+
constructor (qos, func, rh, rap, nl) {
|
|
27
|
+
this.qos = qos
|
|
28
|
+
this.func = func
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// retain-handling indicates how retained messages should be
|
|
31
|
+
// handled when a new subscription is created
|
|
32
|
+
// (see [MQTT-3.3.1-9] through [MQTT-3.3.1-11])
|
|
33
|
+
this.rh = rh
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
// retain-as-published indicates whether to leave the retain flag as-is (true)
|
|
36
|
+
// or to clear it before sending to subscriptions (false) default false
|
|
37
|
+
// (see [MQTT-3.3.1-12] through [MQTT-3.3.1-13])
|
|
38
|
+
this.rap = rap
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// no-local indicates that a client should not receive its own
|
|
41
|
+
// messages (see [MQTT-3.8.3-3])
|
|
42
|
+
this.nl = nl
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
class SubscribeState {
|
|
47
|
+
constructor (client, packet, restore, finish) {
|
|
48
|
+
this.client = client
|
|
49
|
+
this.packet = packet
|
|
50
|
+
this.actions = restore ? restoreTopicActions : subscribeTopicActions
|
|
51
|
+
this.finish = finish
|
|
52
|
+
this.subState = []
|
|
53
|
+
}
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
class SubState {
|
|
57
|
+
constructor (client, packet, granted, rh, rap, nl) {
|
|
58
|
+
this.client = client
|
|
59
|
+
this.packet = packet
|
|
60
|
+
this.granted = granted
|
|
61
|
+
this.rh = rh
|
|
62
|
+
this.rap = rap
|
|
63
|
+
this.nl = nl
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
// if same subscribed topic in subs array, we pick up the last one
|
|
@@ -123,9 +128,8 @@ function storeSubscriptions (sub, done) {
|
|
|
123
128
|
return done(null, sub)
|
|
124
129
|
}
|
|
125
130
|
|
|
126
|
-
client.broker.persistence.addSubscriptions(client, packet.subscriptions
|
|
127
|
-
done(err, sub)
|
|
128
|
-
})
|
|
131
|
+
client.broker.persistence.addSubscriptions(client, packet.subscriptions)
|
|
132
|
+
.then(() => done(null, sub), err => done(err, sub))
|
|
129
133
|
}
|
|
130
134
|
|
|
131
135
|
function addSubs (sub, done) {
|
|
@@ -252,4 +256,4 @@ function completeSubscribe (err) {
|
|
|
252
256
|
|
|
253
257
|
function noop () { }
|
|
254
258
|
|
|
255
|
-
|
|
259
|
+
export default handleSubscribe
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import write from '../write.js'
|
|
2
|
+
import { validateTopic, $SYS_PREFIX } from '../utils.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.messageId = packet.messageId // [MQTT-3.10.4-4]
|
|
4
|
+
class UnSubAck {
|
|
5
|
+
constructor (packet) {
|
|
6
|
+
this.cmd = 'unsuback'
|
|
7
|
+
this.messageId = packet.messageId // [MQTT-3.10.4-4]
|
|
8
|
+
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
class UnsubscribeState {
|
|
12
|
+
constructor (client, packet, finish) {
|
|
13
|
+
this.client = client
|
|
14
|
+
this.packet = packet
|
|
15
|
+
this.finish = finish
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
function handleUnsubscribe (client, packet, done) {
|
|
@@ -31,13 +33,8 @@ function handleUnsubscribe (client, packet, done) {
|
|
|
31
33
|
return actualUnsubscribe(client, packet, done)
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
broker.persistence.removeSubscriptions(client, unsubscriptions
|
|
35
|
-
|
|
36
|
-
return done(err)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
actualUnsubscribe(client, packet, done)
|
|
40
|
-
})
|
|
36
|
+
broker.persistence.removeSubscriptions(client, unsubscriptions)
|
|
37
|
+
.then(() => actualUnsubscribe(client, packet, done), done)
|
|
41
38
|
} else {
|
|
42
39
|
actualUnsubscribe(client, packet, done)
|
|
43
40
|
}
|
|
@@ -101,4 +98,4 @@ function completeUnsubscribe (err) {
|
|
|
101
98
|
|
|
102
99
|
function noop () { }
|
|
103
100
|
|
|
104
|
-
|
|
101
|
+
export default handleUnsubscribe
|
package/lib/qos-packet.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import Packet from 'aedes-packet'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class QoSPacket extends Packet {
|
|
4
|
+
constructor (original, client) {
|
|
5
|
+
super(original, client.broker)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
Packet.call(this, original, client.broker)
|
|
7
|
+
this.writeCallback = client._onError.bind(client)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (!original.messageId) {
|
|
10
|
+
this.messageId = client._nextId
|
|
11
|
+
if (client._nextId >= 65535) {
|
|
12
|
+
client._nextId = 1
|
|
13
|
+
} else {
|
|
14
|
+
client._nextId++
|
|
15
|
+
}
|
|
15
16
|
} else {
|
|
16
|
-
|
|
17
|
+
this.messageId = original.messageId
|
|
17
18
|
}
|
|
18
|
-
} else {
|
|
19
|
-
this.messageId = original.messageId
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
module.exports = QoSPacket
|
|
22
|
+
export default QoSPacket
|
package/lib/utils.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { Transform, Writable } from 'stream'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function validateTopic (topic, message) {
|
|
3
|
+
export function validateTopic (topic, message) {
|
|
6
4
|
if (!topic || topic.length === 0) { // [MQTT-3.8.3-3]
|
|
7
5
|
return new Error('impossible to ' + message + ' to an empty topic')
|
|
8
6
|
}
|
|
@@ -32,14 +30,14 @@ function validateTopic (topic, message) {
|
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
function through (transform) {
|
|
33
|
+
export function through (transform) {
|
|
36
34
|
return new Transform({
|
|
37
35
|
objectMode: true,
|
|
38
36
|
transform
|
|
39
37
|
})
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
function bulk (fn) {
|
|
40
|
+
export function bulk (fn) {
|
|
43
41
|
return new Writable({
|
|
44
42
|
objectMode: true,
|
|
45
43
|
writev: function (chunks, cb) {
|
|
@@ -48,9 +46,4 @@ function bulk (fn) {
|
|
|
48
46
|
})
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
validateTopic,
|
|
53
|
-
through,
|
|
54
|
-
bulk,
|
|
55
|
-
$SYS_PREFIX: '$SYS/'
|
|
56
|
-
}
|
|
49
|
+
export const $SYS_PREFIX = '$SYS/'
|
package/lib/write.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const mqtt = require('mqtt-packet')
|
|
1
|
+
import mqtt from 'mqtt-packet'
|
|
4
2
|
|
|
5
3
|
function write (client, packet, done) {
|
|
6
4
|
let error = null
|
|
@@ -8,7 +6,8 @@ function write (client, packet, done) {
|
|
|
8
6
|
try {
|
|
9
7
|
const result = mqtt.writeToStream(packet, client.conn)
|
|
10
8
|
if (!result && !client.errored) {
|
|
11
|
-
|
|
9
|
+
// Socket buffer is full - wait for drain
|
|
10
|
+
client.waitForDrain(done)
|
|
12
11
|
return
|
|
13
12
|
}
|
|
14
13
|
} catch (e) {
|
|
@@ -21,4 +20,4 @@ function write (client, packet, done) {
|
|
|
21
20
|
setImmediate(done, error, client)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
export default write
|