libp2p-mdns
npm i libp2p-mdns

libp2p-mdns

libp2p MulticastDNS Peer Discovery

by libp2p

0.18.0 (see all)License:MITTypeScript:Not Found
npm i libp2p-mdns
Readme

libp2p-mdns JavaScript implementation

Discourse posts Build Status Dependency Status js-standard-style

JavaScript libp2p MulticastDNS discovery implementation

Usage

import { MDNS } from '@libp2p/mdns'

const mdns = new MDNS(options)

mdns.on('peer', (peerData) => {
  console.log('Found a peer in the local network', peerData.id.toString(), 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' } ]

Contribute

The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:

  • Go through the modules and check out existing issues. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
  • Perform code reviews. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Downloads/wk

11.2K

GitHub Stars

42

LAST COMMIT

2mos ago

MAINTAINERS

5

CONTRIBUTORS

16

OPEN ISSUES

4

OPEN PRs

1
VersionTagPublished
0.18.0
latest
6mos ago
0.15.0
beta
2yrs ago
No alternatives found
No tutorials found
Add a tutorial