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.
24 lines
653 B
24 lines
653 B
import DHT from '../index.js'
|
|
import crypto from 'crypto'
|
|
|
|
const GET = 1
|
|
|
|
const hex = process.argv[2]
|
|
const node = new DHT({ ephemeral: true, bootstrap: ['localhost:10001'] })
|
|
await node.ready()
|
|
|
|
const q = node.query({ target: Buffer.from(hex, 'hex'), command: GET }, { commit: true })
|
|
|
|
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()
|
|
}
|
|
|