Skip to content

Commit

Permalink
Added usage example in README.
Browse files Browse the repository at this point in the history
Also made the DHT constructor a bit more user friendly.
  • Loading branch information
jameskeane committed Dec 14, 2023
1 parent 41dacda commit ff26e17
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ An implementation of the Kademlia DHT.
Supports:
- BEP-42 with `sse4_crc32` optional dependency.
- BEP-44 with `ed25519-supercop` optional dependency.

## Usage
```javascript
import DHT from 'kadem';

// load DHT from stored state file; if it doesn't
// exist or is not provided it'll bootstrap itself.
const dht = DHT.load('.dht_state');
dht.listen(/** listening port, can be anything */ 8468);

const value = await dht.get({ k: key, salt: salt });
```
1 change: 0 additions & 1 deletion index.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "kadem",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "mocha test/**/*.js"
},
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ util.inherits(DHT, EventEmitter);
* @param {string} filename The filename to load from.
*/
DHT.load = function(filename) {
if (filename == undefined || !fs.existsSync(filename)) return new DHT();

let state = JSON.parse(fs.readFileSync(filename).toString('utf-8'));
return new DHT({
K: state.K,
Expand Down

0 comments on commit ff26e17

Please sign in to comment.