A fast and stable DHT crawler.
$ npm install dht-peer-crawler
import Crawler from 'dht-peer-crawler'
const crawler = new Crawler()
crawler.on('announce_peer', (infoHashStr, addressStr) => {
console.log(`got a peer ${addressStr} on ${infoHashStr}`)
})
crawler.start().then(() => {
console.log('start crawler success')
}, (error) => {
console.error(`start crawler failed: ${error}`)
})
const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2']
signalTraps.map(type => {
process.once(type, async () => {
try {
await crawler.stop()
console.log('stop crawler success')
} finally {
process.kill(process.pid, type)
}
})
})
run with the command:
$ node --experimental-specifier-resolution=node app.js
$ npm test
Create a new crawler instance.
announce the peer.
Emitted when received an announce_peer
message.
Emitted when find a new info_hash
.