2.2.0 • Published 7 months ago

aedes-protocol-decoder v2.2.0

Weekly downloads
1,403
License
MIT
Repository
github
Last release
7 months ago

aedes-protocol-decoder

npm.io Dependencies Status devDependencies Status Known Vulnerabilities Coverage Status NPM version NPM downloads

js-standard-style

Protocol decoder for Aedes MQTT Broker

The purpose of this module is to be used inside aedes-server-factory bindConnection function, which is called when the server receives a connection from client (before CONNECT packet). The client object state is in default and its connected state is false. The function extract socket details and if aedes-server-factory trustProxy option is set to true, it will first parse http headers (x-real-ip | x-forwarded-for) and/or proxy protocol (v1 and v2), then passing the informations to aedes that will assign them to client.connDetails.

Additionally, if the current socket is a TLS socket, the module will extract the authorization status and the full certificate chain.

The function protocolDecoder and extractSocketDetails returns ConnectionDetails, if the object contains data property, it will be parsed as an mqtt-packet.

Install

npm install aedes-protocol-decoder --save

Example

var aedes = require('aedes')
var { protocolDecoder } = require('aedes-protocol-decoder')
var { createServer } = require('aedes-server-factory')
var port = 1883

var broker = aedes({
	preConnect: function (client, packet, done) {
	  if (client.connDetails && client.connDetails.ipAddress) {
	    client.ip = client.connDetails.ipAddress
	  }
	  return done(null, true)
	},
})

var server = createServer(broker, { trustProxy: true, protocolDecoder })
server.listen(port, function () {
  console.log('server listening on port', port)
})

License

MIT

2.2.0

7 months ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.0

4 years ago