-
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: nolocal flag support for bridges (#737)
Co-authored-by: Daniel Lando <daniel.sorridi@gmail.com>
- Loading branch information
1 parent
00549ee
commit f82b8f8
Showing
9 changed files
with
127 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { setup, connect, subscribe } = require('./helper') | ||
|
||
for (const qos of [0, 1, 2]) { | ||
const packet = { | ||
qos, | ||
cmd: 'publish', | ||
topic: 'hello', | ||
payload: 'world' | ||
} | ||
|
||
if (qos > 0) packet.messageId = 42 | ||
|
||
test('normal client sends a publish message and shall receive it back, qos = ' + qos, function (t) { | ||
const s = connect(setup()) | ||
t.teardown(s.broker.close.bind(s.broker)) | ||
|
||
const handle = setTimeout(() => { | ||
t.fail('did not receive packet back') | ||
t.end() | ||
}, 1000) | ||
|
||
subscribe(t, s, 'hello', qos, function () { | ||
s.outStream.on('data', (packet) => { | ||
if (packet.cmd === 'publish') { | ||
clearTimeout(handle) | ||
t.end() | ||
} else if (packet.cmd === 'pubrec') { | ||
s.inStream.write({ cmd: 'pubrel', messageId: 42 }) | ||
} | ||
}) | ||
|
||
s.inStream.write(packet) | ||
}) | ||
}) | ||
|
||
test('bridge client sends a publish message but shall not receive it back, qos = ' + qos, function (t) { | ||
// protocolVersion 128 + 4 means mqtt 3.1.1 with bridgeMode enabled | ||
// https://github.com/mqttjs/mqtt-packet/blob/7f7c2ed8bcb4b2c582851d120a94e0b4a731f661/parser.js#L171 | ||
const s = connect(setup(), { clientId: 'my-client-bridge-1', protocolVersion: 128 + 4 }) | ||
t.teardown(s.broker.close.bind(s.broker)) | ||
|
||
const handle = setTimeout(() => t.end(), 1000) | ||
|
||
subscribe(t, s, 'hello', qos, function () { | ||
s.outStream.on('data', function () { | ||
clearTimeout(handle) | ||
t.fail('should not receive packet back') | ||
t.end() | ||
}) | ||
|
||
s.inStream.write(packet) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters