@libp2p/mdns
v11.0.12
Published
Node.js libp2p mDNS discovery implementation for peer discovery
Downloads
37,341
Keywords
Readme
@libp2p/mdns
Node.js libp2p mDNS discovery implementation for peer discovery
About
A peer discover mechanism that uses mDNS to discover peers on the local network.
Example - Use with libp2p
import { createLibp2p } from 'libp2p'
import { mdns } from '@libp2p/mdns'
const libp2p = await createLibp2p({
peerDiscovery: [
mdns()
]
})
libp2p.addEventListener('peer:discovery', (evt) => {
console.log('found peer: ', evt.detail.toString())
})
MDNS messages
A query is sent to discover the libp2p nodes on the local network
{
"type": "query",
"questions": [{
"name": "_p2p._udp.local",
"type": "PTR"
}]
}
When a query is detected, each libp2p node sends an answer about itself
[{
"name": "_p2p._udp.local",
"type": "PTR",
"class": "IN",
"ttl": 120,
"data": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local"
}, {
"name": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.local",
"type": "SRV",
"class": "IN",
"ttl": 120,
"data": {
"priority": 10,
"weight": 1,
"port": "20002",
"target": "LAPTOP-G5LJ7VN9"
}
}, {
"name": "QmNPubsDWATVngE3d5WDSNe7eVrFLuk38qb9t6vdLnu2aK._p2p._udp.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"
}]
Install
$ npm i @libp2p/mdns
API Docs
License
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)
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.