dht-keyvalue
Store key-value pairs on the mainline bittorrent DHT network, and retreive them by key lookup.
This is a work in progress. This version is a minimal viable iteration of this project.
It takes a little bit of time (seconds) to announce to DHT and retrieve the values.
It probably should not be used in production at this time. More work is required for handling updates to the DHT objects. Improvements to usability and security are also needed.
Install
npm i dht-keyvalue
Usage
Example
const dhtKv = require('dht-kv')
let opts = {
keep: true,
keepalive: 3600000
}
const dkv = new dhtKv(opts)
let items = [{key: "first key", value: "first value"}, {key: "second key", value: "second value"}]
dkv.on('error', err => {
console.log(err)
})
dkv.put(items)
for(item in items){
let key = items[item].key
dkv.on(key, hash => {
dkv.lookup(key)
dkv.on(hash, value => {
console.log(value)
let updated = Math.random()
dkv.update(key, updated)
})
})
}