aedes-protocol-decoder
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