Local Service Discovery (LSD) provides a SSDP-like (http over udp-multicast) mechanism to announce the presence in specific swarms to local neighbors.
This module is used by WebTorrent.
npm install bittorrent-lsd
const opts = {
peerId: new Buffer('01234567890123456789'), // hex string or Buffer
infoHash: new Buffer('01234567890123456789'), // hex string or Buffer
port: common.randomPort() // torrent client port
}
const lsd = new LSD(opts)
// start getting peers from local network
lsd.start()
lsd.on('peer', (peerAddress, infoHash) => {
console.log('found a peer: ' + peerAddress)
})
lsd.destroy()
Create a new lsd
instance.
Start listening and sending (every 5 minutes) for local network announces.
Destroy the LSD. Closes the socket and cleans up resources.
Emitted when a potential peer is found. peerAddress
is of the form host:port
. infoHash
is the torrent info hash.
Emitted when the LSD gets an unexpected message.
Emitted when the LSD has a fatal error.
MIT. Copyright (c) Julen Garcia Leunda and WebTorrent, LLC.