You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
631 B
22 lines
631 B
6 years ago
|
const dht = require('../')
|
||
|
const crypto = require('crypto')
|
||
|
|
||
|
const hex = process.argv[2]
|
||
|
const node = dht({ ephemeral: true, bootstrap: ['localhost:10001'] })
|
||
|
|
||
|
node.query('values', Buffer.from(hex, 'hex'))
|
||
|
.on('data', function (data) {
|
||
|
if (data.value && sha256(data.value).toString('hex') === hex) {
|
||
|
// We found the value! Destroy the query stream as there is no need to continue.
|
||
|
console.log(hex, '-->', data.value.toString())
|
||
|
this.destroy()
|
||
|
}
|
||
|
})
|
||
|
.on('end', function () {
|
||
|
console.log('(query finished)')
|
||
|
})
|
||
|
|
||
|
function sha256 (val) {
|
||
|
return crypto.createHash('sha256').update(val).digest()
|
||
|
}
|