Skip to content

Instantly share code, notes, and snippets.

@shime
Last active November 8, 2015 13:57
Show Gist options
  • Save shime/cc4b9d5737b9ada9baf8 to your computer and use it in GitHub Desktop.
Save shime/cc4b9d5737b9ada9baf8 to your computer and use it in GitHub Desktop.

Revisions

  1. shime renamed this gist Nov 8, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. shime created this gist Nov 8, 2015.
    2 changes: 2 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    node_modules
    *.log
    8 changes: 8 additions & 0 deletions _README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # Hello world over Bittorrent DHT

    git clone [email protected]:8af1e7887515133208af.git hello-world
    cd hello-world
    npm install
    npm start

    ![](https://i.imgur.com/TcOgvgB.png)
    17 changes: 17 additions & 0 deletions hello.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    var DHT = require('bittorrent-dht')
    var dht = new DHT()
    var value = new Buffer(11).fill('hello world')

    console.log('putting data, please wait...')
    dht.on('ready', function () {
    dht.put({ v: value }, function (errors, hash) {
    console.error('errors=', errors)
    console.log('hash=', hash)

    console.log('getting data, please wait...')
    dht.get(hash, function(errors, res){
    console.error('errors=', errors)
    console.log(res.v.toString())
    })
    })
    })
    15 changes: 15 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    "name": "bittorrent-example",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
    "start": "node hello.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
    "bittorrent-dht": "^4.0.3"
    }
    }