# aedes-protocol-decoder

> Aedes plugin to decode connection frame and validate proxies

Latest version **2.2.0** (published 2023-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install aedes-protocol-decoder
pnpm add aedes-protocol-decoder
yarn add aedes-protocol-decoder
bun add aedes-protocol-decoder
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2023-09-20 |
| First published | 2020-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 36.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Edouard Maleix |
| Maintainers | matteo.collina, roberts_lando, gnought, getlarge |
| Keywords | mqtt, proxy, protocol, decoder, parser |

## Links

- npm: https://www.npmjs.com/package/aedes-protocol-decoder
- Repository: https://github.com/moscajs/aedes-protocol-decoder
- Homepage: https://github.com/moscajs/aedes-protocol-decoder#readme
- Issues: http://github.com/moscajs/aedes-protocol-decoder/issues
- npm.io page: https://npm.io/package/aedes-protocol-decoder

## Dependencies (2)

- [forwarded](https://npm.io/package/forwarded.md) ^0.2.0
- [proxy-protocol-js](https://npm.io/package/proxy-protocol-js.md) ^4.0.6

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2023-09-20
- 2.1.0 — 2021-06-28
- 2.0.1 — 2021-01-14
- 2.0.0 — 2020-10-28
- 1.0.0 — 2020-02-04

## README

# aedes-protocol-decoder

![](https://github.com/moscajs/aedes-protocol-decoder/workflows/ci/badge.svg)
[![Dependencies Status](https://david-dm.org/moscajs/aedes-protocol-decoder/status.svg)](https://david-dm.org/moscajs/aedes-protocol-decoder)
[![devDependencies Status](https://david-dm.org/moscajs/aedes-protocol-decoder/dev-status.svg)](https://david-dm.org/moscajs/aedes-protocol-decoder?type=dev)
<br/>
[![Known Vulnerabilities](https://snyk.io/test/github/moscajs/aedes-protocol-decoder/badge.svg)](https://snyk.io/test/github/moscajs/aedes-protocol-decoder)
[![Coverage Status](https://coveralls.io/repos/moscajs/aedes-protocol-decoder/badge.svg?branch=master&service=github)](https://coveralls.io/github/moscajs/aedes-protocol-decoder?branch=master)
[![NPM version](https://img.shields.io/npm/v/aedes-protocol-decoder.svg?style=flat)](https://www.npmjs.com/package/aedes-protocol-decoder)
[![NPM downloads](https://img.shields.io/npm/dm/aedes-protocol-decoder.svg?style=flat)](https://www.npmjs.com/package/aedes-protocol-decoder)


[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

Protocol decoder for Aedes MQTT Broker

The purpose of this module is to be used inside [aedes-server-factory](https://github.com/moscajs/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](https://nodejs.org/api/tls.html#tls_class_tls_tlssocket) socket, the module will extract the authorization status and the full certificate chain.

The function `protocolDecoder` and `extractSocketDetails` returns [ConnectionDetails](./types/index.d.ts), if the object contains `data` property, it will be parsed as an [mqtt-packet](https://github.com/mqttjs/mqtt-packet).

## Install

```bash
npm install aedes-protocol-decoder --save
```

## Example 

```js
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

---
_Source: https://npm.io/package/aedes-protocol-decoder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
