Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broker TTL #45

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aedes-packet",
"version": "2.3.1",
"version": "2.3.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the version bump

"description": "Basic data structure for packets in Aedes ",
"main": "packet.js",
"types": "packet.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare namespace aedes {
type AedesPacket = IPacket & {
brokerId: string
brokerCounter: number
ttlInSeconds?: number
}

function Packet(object?: AedesPacket) : aedes.AedesPacket
Expand Down
1 change: 1 addition & 0 deletions packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Packet (original, broker) {
this.qos = original.qos || 0
this.retain = original.retain || false
this.dup = original.dup || false
this.ttlInSeconds = original.properties?.messageExpiryInterval
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't keep the original packet structure and use packet properties?

// [MQTT-2.3.1-5]
if (this.qos > 0 || this.cmd !== 'publish') {
// [MQTT-2.3.1-1]
Expand Down
45 changes: 43 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('Packet defaults - PUBLISH, QoS 0', function (t) {
t.equal(instance.qos, 0)
t.equal(instance.dup, false)
t.equal(instance.retain, false)
t.equal(instance.ttlInSeconds, undefined)
t.notOk(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.end()
})
Expand All @@ -29,6 +30,7 @@ test('Packet defaults - PUBREL, QoS 0', function (t) {
t.equal(instance.retain, false)
t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.equal(instance.messageId, undefined)
t.equal(instance.ttlInSeconds, undefined)
t.end()
})

Expand All @@ -44,6 +46,7 @@ test('Packet defaults - PUBLISH, QoS 1', function (t) {
t.equal(instance.retain, false)
t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.equal(instance.messageId, undefined)
t.equal(instance.ttlInSeconds, undefined)
t.end()
})

Expand All @@ -58,6 +61,7 @@ test('Packet defaults - PUBLISH, dup=true', function (t) {
t.equal(instance.dup, true)
t.equal(instance.retain, false)
t.equal(instance.messageId, undefined)
t.equal(instance.ttlInSeconds, undefined)
t.end()
})

Expand All @@ -82,7 +86,43 @@ test('Packet copies over most data', function (t) {
payload: 'world',
qos: 2,
dup: true,
retain: true
retain: true,
ttlInSeconds: undefined
}

t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
t.equal(instance.messageId, undefined)
delete instance.messageId
t.deepEqual(instance, expected)
t.end()
})

test('Packet understands properties.messageExpiryInterval', function (t) {
const original = {
cmd: 'publish',
brokerId: 'A56c',
brokerCounter: 42,
topic: 'hello',
payload: 'world',
qos: 2,
dup: true,
retain: true,
messageId: 24,
properties: {
messageExpiryInterval: 4
}
}
const instance = new Packet(original)
const expected = {
cmd: 'publish',
brokerId: 'A56c',
brokerCounter: 42,
topic: 'hello',
payload: 'world',
qos: 2,
dup: true,
retain: true,
ttlInSeconds: 4
}

t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
Expand Down Expand Up @@ -114,7 +154,8 @@ test('Packet fills in broker data', function (t) {
payload: 'world',
qos: 2,
dup: false,
retain: true
retain: true,
ttlInSeconds: undefined
}

t.ok(Object.prototype.hasOwnProperty.call(instance, 'messageId'))
Expand Down