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.
19 lines
507 B
19 lines
507 B
const DHT = require('../')
|
|
const crypto = require('crypto')
|
|
|
|
// Set ephemeral: true as we are not part of the network.
|
|
const node = new DHT({ ephemeral: true, bootstrap: ['localhost:10001'] })
|
|
const val = Buffer.from(process.argv[2])
|
|
|
|
run()
|
|
|
|
async function run () {
|
|
const q = node.query(sha256(val), 'values')
|
|
await q.finished()
|
|
await q.commit('values', val)
|
|
console.log('Inserted', sha256(val).toString('hex'))
|
|
}
|
|
|
|
function sha256 (val) {
|
|
return crypto.createHash('sha256').update(val).digest()
|
|
}
|
|
|