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.
25 lines
638 B
25 lines
638 B
const DHT = require('../')
|
|
const crypto = require('crypto')
|
|
|
|
const hex = process.argv[2]
|
|
const node = new DHT({ ephemeral: true, bootstrap: ['localhost:10001'] })
|
|
|
|
run()
|
|
|
|
async function run () {
|
|
const q = node.query(Buffer.from(hex, 'hex'), 'values')
|
|
|
|
for await (const data of q) {
|
|
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())
|
|
break
|
|
}
|
|
}
|
|
|
|
console.log('(query finished)')
|
|
}
|
|
|
|
function sha256 (val) {
|
|
return crypto.createHash('sha256').update(val).digest()
|
|
}
|
|
|