๐ Archived - this module has been merged into js-libp2p
Node.js libp2p mDNS discovery implementation for peer discovery
$ npm i @libp2p/mdnsimport { mdns } from '@libp2p/mdns' const options = { peerDiscovery: [ mdns() ] } async function start () { const libp2p = await createLibp2p(options) libp2p.on('peer:discovery', function (peerId) { console.log('found peer: ', peerId.toB58String()) }) await libp2p.start() }- options
peerName- Peer name to announce (should not be peeer id), default random stringmultiaddrs- multiaddrs to announcebroadcast- (true/false) announce our presence through mDNS, defaultfalseinterval- query interval, default 10 * 1000 (10 seconds)serviceTag- name of the service announce , default 'ipfs.local`
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' } ]Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
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.