mqtt-packet
Advanced tools
Comparing version 4.0.5 to 4.1.0
{ | ||
"name": "mqtt-packet", | ||
"version": "4.0.5", | ||
"version": "4.1.0", | ||
"description": "Parse and generate MQTT packets like a breeze", | ||
@@ -5,0 +5,0 @@ "main": "mqtt.js", |
@@ -333,2 +333,3 @@ mqtt-packet [![Build Status](https://travis-ci.org/mqttjs/mqtt-packet.png)](https://travis-ci.org/mqttjs/mqtt-packet) | ||
<tr><th align="left">Adam Rudd</th><td><a href="https://github.com/adamvr">GitHub/adamvr</a></td><td><a href="http://twitter.com/adam_vr">Twitter/@adam_vr</a></td></tr> | ||
<tr><th align="left">Peter Sorowka</th><td><a href="https://github.com/adamvr">GitHub/psorowka</a></td><td><a href="http://twitter.com/psorowka">Twitter/@psorowka</a></td></tr> | ||
</tbody></table> | ||
@@ -335,0 +336,0 @@ |
@@ -757,2 +757,7 @@ | ||
testGenerateError('Invalid keepalive', { | ||
cmd: 'connect' | ||
, keepalive: 3.1416 | ||
}) | ||
testGenerateError('Invalid will', { | ||
@@ -916,3 +921,3 @@ cmd: 'connect' | ||
// CONNECT Packets that contain an unsupported protocol version | ||
// CONNECT Packets that contain an unsupported protocol version | ||
// flag (i.e. not `3` or `4`) should cause an error | ||
@@ -931,3 +936,3 @@ testParseError('invalid protocol version', new Buffer([ | ||
// when a packet contains a string in the variable header and the | ||
// given string length of this exceeds the overall length of the packet that | ||
// given string length of this exceeds the overall length of the packet that | ||
// was specified in the fixed header, parsing must fail. | ||
@@ -934,0 +939,0 @@ // this case simulates this behavior with the protocol id string of the |
var mqtt = require('./') | ||
, crypto = require('crypto') | ||
, max = 100000 | ||
, max = 1E5 | ||
, i | ||
@@ -9,20 +9,88 @@ , start = Date.now() / 1000 | ||
, errors = 0 | ||
, packets = 0 | ||
, randomPacket | ||
, firstBytes = [ | ||
16*1, // CONNECT | ||
16*2, // CONNACK | ||
16*3, // PUBLISH, QoS: 0, No Retain, No Dup | ||
16*3 + 1, // PUBLISH, QoS: 0, Retain, No Dup | ||
16*3 + 8, // PUBLISH, QoS: 0, No Retain, Dup | ||
16*3 + 1 + 8, // PUBLISH, QoS: 0, Retain, Dup | ||
16*3 + 2, // PUBLISH, QoS: 1, No Retain, No Dup | ||
16*3 + + 1, // PUBLISH, QoS: 1, Retain, No Dup | ||
16*3 + 2 + 8, // PUBLISH, QoS: 1, No Retain, Dup | ||
16*3 + 2 + 1 + 8, // PUBLISH, QoS: 1, Retain, Dup | ||
16*3 + 4, // PUBLISH, QoS: 2, No Retain, No Dup | ||
16*3 + 4 + 1, // PUBLISH, QoS: 2, Retain, No Dup | ||
16*3 + 4 + 8, // PUBLISH, QoS: 2, No Retain, Dup | ||
16*3 + 4 + 1 + 8, // PUBLISH, QoS: 2, Retain, Dup | ||
16*4, // PUBACK | ||
16*5, // PUBREC | ||
16*6, // PUBREL | ||
16*7, // PUBCOMP | ||
16*8, // SUBSCRIBE | ||
16*9, // SUBACK | ||
16*10, // UNSUBSCRIBE | ||
16*11, // UNSUBACK | ||
16*12, // PINGREQ | ||
16*13, // PINGRESP | ||
16*14, // DISCONNECT | ||
16*15 // RESERVED | ||
] | ||
function doParse () { | ||
function doParse () { | ||
var parser = mqtt.parser() | ||
parser.on('error', onError) | ||
parser.parse(crypto.randomBytes(Math.floor(Math.random() * 10))) | ||
var parser = mqtt.parser(); | ||
parser.on('error', onError); | ||
parser.on('packet', onPacket); | ||
randomPacket = crypto.randomBytes(Math.floor(Math.random() * 512)); | ||
// Increase probability to have a valid first byte in order to at least | ||
// enter the parser | ||
if(Math.random() > 0.2 && randomPacket.length > 0) { | ||
randomPacket.writeUInt8(firstBytes[Math.floor(Math.random()*firstBytes.length)],0); | ||
} | ||
parser.parse(randomPacket); | ||
} | ||
for (i = 0; i < max; i++) { | ||
doParse() | ||
try { | ||
for (i = 0; i < max; i++) { | ||
doParse(); | ||
} | ||
} | ||
catch(e) { | ||
console.log('Exception occured at packet'); | ||
console.log(randomPacket); | ||
console.log(e.message); | ||
console.log(e.stack); | ||
} | ||
function onError () { | ||
errors++ | ||
errors++; | ||
} | ||
time = Date.now() / 1000 - start | ||
console.log('Total time', Math.round(time * 100) / 100) | ||
console.log('Errors/s', errors / time) | ||
function onPacket() { | ||
packets++; | ||
} | ||
time = Date.now() / 1000 - start; | ||
console.log('Total time', Math.round(time * 100) / 100); | ||
console.log('Valid Packets', packets); | ||
console.log('Errors', errors); | ||
console.log('Valid Packets + Errors', packets + errors); | ||
delta = max - packets - errors; | ||
if(delta > 0) { | ||
console.log(delta + ' packets too short to generate parse results'); | ||
} | ||
else { | ||
console.log(-1 * delta + ' more packets parsed then generated'); | ||
} |
@@ -111,3 +111,4 @@ | ||
keepalive < 0 || | ||
keepalive > 65535) { | ||
keepalive > 65535 || | ||
keepalive % 1 !== 0) { | ||
stream.emit('error', new Error('Invalid keepalive')) | ||
@@ -114,0 +115,0 @@ } else { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64272
2031
340