# libp2p-mdns

> Node.js libp2p mDNS discovery implementation for peer discovery

Latest version **0.18.0** (published 2021-12-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install libp2p-mdns
pnpm add libp2p-mdns
yarn add libp2p-mdns
bun add libp2p-mdns
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.18.0 |
| Published | 2021-12-02 |
| First published | 2016-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51 |
| Maintainers | jacobheun, daviddias, dignifiedquire, achingbrain, vascosantos |
| Keywords | IPFS |

## Links

- npm: https://www.npmjs.com/package/libp2p-mdns
- Repository: https://github.com/libp2p/js-libp2p-mdns
- Issues: https://github.com/libp2p/js-libp2p-mdns/issues
- npm.io page: https://npm.io/package/libp2p-mdns

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^4.3.1
- [peer-id](https://npm.io/package/peer-id.md) ^0.16.0
- [multiaddr](https://npm.io/package/multiaddr.md) ^10.0.0
- [multicast-dns](https://npm.io/package/multicast-dns.md) ^7.2.0

## Recent versions

- 0.18.0 (latest) — 2021-12-02
- 0.15.0 (beta) — 2020-08-11
- 0.17.0 — 2021-07-08
- 0.16.0 — 2021-04-13
- 0.14.3 — 2020-08-07
- 0.14.2 — 2020-07-02
- 0.14.1 — 2020-04-29
- 0.14.0 — 2020-04-23
- 0.13.3 — 2020-02-17
- 0.13.2 — 2020-02-02
- 0.13.1 — 2020-01-17
- 0.13.0 — 2019-09-27
- 0.12.3 — 2019-05-09
- 0.12.2 — 2019-01-04
- 0.12.1 — 2018-11-26
- … 15 more at https://npm.io/package/libp2p-mdns/versions

## README

libp2p-mdns JavaScript implementation
=====================================

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-mdns.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-mdns)
[![](https://img.shields.io/travis/libp2p/js-libp2p-mdns.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-mdns)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-mdns.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-mdns)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

> JavaScript libp2p MulticastDNS discovery implementation

## Lead Maintainer

[Jacob Heun](https://github.com/jacobheun)

## Usage

```JavaScript
const MDNS = require('libp2p-mdns')

const mdns = new MDNS(options)

mdns.on('peer', (peerData) => {
  console.log('Found a peer in the local network', peerData.id.toB58String(), peerData.multiaddrs)
})

// Broadcast for 20 seconds
mdns.start()
setTimeout(() => mdns.stop(), 20 * 1000)
```

- options
  - `peerId` - PeerId to announce
  - `multiaddrs` - multiaddrs to announce
  - `broadcast` - (true/false) announce our presence through mDNS, default `false`
  - `interval` - query interval, default 10 * 1000 (10 seconds)
  - `serviceTag` - name of the service announce , default 'ipfs.local`
  - `compat` - enable/disable compatibility with go-libp2p-mdns, default `true`

## MDNS messages

A query is sent to discover the IPFS nodes on the local network

```
{ type: 'query',
  questions: [ { name: 'ipfs.local', type: 'PTR' } ]
}
```

When a query is detected, each IPFS node sends an answer about itself

```
[ { name: 'ipfs.local',
    type: 'PTR',
    class: 'IN',
    ttl: 120,
    data: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK.ipfs.local' },
  { name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK.ipfs.local',
    type: 'SRV',
    class: 'IN',
    ttl: 120,
    data:
     { priority: 10,
       weight: 1,
       port: '20002',
       target: 'LAPTOP-G5LJ7VN9' } },
  { name: 'QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK.ipfs.local',
    type: 'TXT',
    class: 'IN',
    ttl: 120,
    data: ['QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK'] },
  { name: 'LAPTOP-G5LJ7VN9',
    type: 'A',
    class: 'IN',
    ttl: 120,
    data: '127.0.0.1' },
  { name: 'LAPTOP-G5LJ7VN9',
    type: 'AAAA',
    class: 'IN',
    ttl: 120,
    data: '::1' } ]
```

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