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

Downgrade qos to client sub if needed #229

Merged
merged 1 commit into from
Feb 11, 2019
Merged
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
5 changes: 5 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ function Client (broker, conn) {
that.broker.authorizeForward(that, _packet)
if (toForward) {
var packet = new QoSPacket(toForward, that)
// Downgrading to client subscription qos if needed
var clientSub = that.subscriptions[packet.topic]
if (clientSub && clientSub.qos && clientSub.qos < packet.qos) {
packet.qos = clientSub.qos
}
packet.writeCallback = cb
if (that.clean) {
writeQoS(null, that, packet)
Expand Down
33 changes: 33 additions & 0 deletions test/qos2.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,39 @@ test('subscribe QoS 0, but publish QoS 2', function (t) {
})
})

test('subscribe QoS 1, but publish QoS 2', function (t) {
var broker = aedes()
var publisher = connect(setup(broker))
var subscriber = connect(setup(broker))
var expected = {
cmd: 'publish',
topic: 'hello',
payload: Buffer.from('world'),
qos: 1,
dup: false,
length: 14,
retain: false
}

subscribe(t, subscriber, 'hello', 1, function () {
subscriber.outStream.once('data', function (packet) {
delete packet.messageId
t.deepEqual(packet, expected, 'packet must match')
t.end()
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add some checks on the follow up packets to verify that the full QoS flow is respected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


publish(t, publisher, {
cmd: 'publish',
topic: 'hello',
payload: Buffer.from('world'),
qos: 2,
retain: false,
messageId: 42,
dup: false
})
})
})

test('restore QoS 2 subscriptions not clean', function (t) {
var broker = aedes()
var publisher
Expand Down