{
"repo": "dht-rpc",
"timestamp": "2026-01-16T23:39:33.380Z",
"entryPoint": "index.js",
"exports": {
"packageJson": {
"main": "index.js"
}
},
"api": {
"file": "index.js",
"exports": [
{
"type": "default",
"name": "DHT"
}
],
"classes": [
{
"name": "DHT"
}
],
"functions": [
{
"name": "ondata"
},
{
"name": "onsuccess"
},
{
"name": "onswap"
},
{
"name": "onmessage"
},
{
"name": "localIP"
},
{
"name": "parseNode"
},
{
"name": "randomBytes"
},
{
"name": "randomOffset"
},
{
"name": "requestAll"
},
{
"name": "onsuccess"
},
{
"name": "onerror"
},
{
"name": "noop"
}
]
},
"readme": {
"content": "# dht-rpc\n\nMake RPC calls over a [Kademlia](https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf) based DHT.\n\n```\nnpm install dht-rpc\n```\n\n## Key Features\n\n- Remote IP / firewall detection\n- Easily add any command to your DHT\n- Streaming queries and updates\n\nNote that internally V5 of dht-rpc differs significantly from V4, due to a series\nof improvements to NAT detection, secure routing IDs and more.\n\n## Usage\n\nHere is an example implementing a simple key value store\n\nFirst spin up a bootstrap node. You can make multiple if you want for redundancy.\nThere is nothing special about a bootstrap node, except it needs to know it's own host and port,\nsince it knows no other nodes to infer it from.\n\n```js\nimport DHT from 'dht-rpc'\n\nconst bootstrap = DHT.bootstrapper(10001, '127.0.0.1')\n```\n\nNow lets make some dht nodes that can store values in our key value store.\n\n```js\nimport DHT from 'dht-rpc'\nimport crypto from 'crypto'\n\n// Let's create 100 dht nodes for our example.\nfor (",
"sections": [
"intro",
"key features",
"usage",
"api",
"license"
],
"hasApi": true,
"hasExamples": true,
"exampleCount": 13,
"examples": [
"npm install dht-rpc",
"import DHT from 'dht-rpc'\n\nconst bootstrap = DHT.bootstrapper(10001, '127.0.0.1')",
"import DHT from 'dht-rpc'\nimport crypto from 'crypto'\n\n// Let's create 100 dht nodes for our example.\nfor (var i = 0; i < 100; i++) createNode()\n\nfunction createNode() {\n const node = new DHT({\n bootstrap: ['localhost:10001']\n })\n\n const values = new Map()\n const VALUES = 0 // define a command enum\n\n node.on('request', function (req) {\n if (req.command === VALUES) {\n if (req.token) {\n // if we are the closest node store the value (ie the node sent a valid roundtrip token)\n const key = hash(req.value).toString('hex')\n values.set(key, req.value)\n console.log('Storing', key, '-->', req.value.toString())\n return req.reply(null)\n }\n\n const value = values.get(req.target.toString('hex'))\n req.reply(value)\n }\n })\n}\n\nfunction hash(value) {\n return crypto.createHash('sha256').update(value).digest()\n}"
]
},
"patterns": [
"binary-encoding",
"cryptography",
"streaming"
]
}