{
  "name": "bittorrent-dht",
  "description": "Simple, robust, BitTorrent DHT implementation",
  "version": "1.3.1",
  "author": {
    "name": "Feross Aboukhadijeh",
    "email": "feross@feross.org",
    "url": "http://feross.org/"
  },
  "bugs": {
    "url": "https://github.com/feross/bittorrent-dht/issues"
  },
  "dependencies": {
    "bencode": "^0.6.0",
    "buffer-equal": "^0.0.1",
    "compact2string": "^1.2.0",
    "debug": "^1.0.0",
    "hat": "^0.0.3",
    "inherits": "^2.0.1",
    "k-bucket": "^0.4.2",
    "once": "^1.3.0",
    "portfinder": "^0.2.1",
    "run-parallel": "^1.0.0",
    "string2compact": "^1.1.1"
  },
  "devDependencies": {
    "ip": "^0.3.0",
    "tape": "^2.12.3"
  },
  "homepage": "http://webtorrent.io",
  "keywords": [
    "torrent",
    "bittorrent",
    "dht",
    "distributed hash table",
    "protocol",
    "peer",
    "p2p",
    "peer-to-peer"
  ],
  "license": "MIT",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/feross/bittorrent-dht.git"
  },
  "scripts": {
    "test": "tape test/*.js",
    "test-live": "tape test/live/*.js",
    "start": "node server.js"
  },
  "readme": "# bittorrent-dht [![build](https://img.shields.io/travis/feross/bittorrent-dht.svg)](https://travis-ci.org/feross/bittorrent-dht) [![npm](https://img.shields.io/npm/v/bittorrent-dht.svg)](https://npmjs.org/package/bittorrent-dht) [![npm downloads](https://img.shields.io/npm/dm/bittorrent-dht.svg)](https://npmjs.org/package/bittorrent-dht) [![gittip](https://img.shields.io/gittip/feross.svg)](https://www.gittip.com/feross/)\n\n### Simple, robust, BitTorrent DHT implementation\n\nNode.js implementation of the [BitTorrent DHT protocol](http://www.bittorrent.org/beps/bep_0005.html). BitTorrent DHT is the main peer discovery layer for BitTorrent, which allows for trackerless torrents. DHTs are awesome!\n\nThis module is used by [WebTorrent](http://webtorrent.io).\n\n### features\n\n- complete implementation of the DHT protocol in JavaScript\n- follows [the spec](http://www.bittorrent.org/beps/bep_0005.html)\n- robust and well-tested (comprehensive test suite, and used by [WebTorrent](http://webtorrent.io) and [peerflix](https://github.com/mafintosh/peerflix))\n- efficient recursive lookup algorithm minimizes UDP traffic\n- supports multiple, concurrent lookups using the same routing table\n\n### install\n\n```\nnpm install bittorrent-dht\n```\n\n### example\n\n```\nnpm install magnet-uri\n```\n\n```javascript\nvar DHT    = require('bittorrent-dht')\nvar magnet = require('magnet-uri')\n\nvar uri = 'magnet:?xt=urn:btih:e3811b9539cacff680e418124272177c47477157'\nvar parsed = magnet(uri)\n\nconsole.log(parsed.infoHash) // 'e3811b9539cacff680e418124272177c47477157'\n\nvar dht = new DHT()\n\ndht.listen(20000, function () {\n  console.log('now listening')\n})\n\ndht.on('ready', function () {\n  // DHT is ready to use (i.e. the routing table contains at least K nodes, discovered\n  // via the bootstrap nodes)\n\n  // find peers for the given torrent info hash\n  dht.lookup(parsed.infoHash)\n})\n\ndht.on('peer', function (addr, hash) {\n  console.log('found potential peer ' + addr)\n})\n\n```\n\n### api\n\n#### `dht = new DHT([opts])`\n\nCreate a new `dht` instance.\n\nIf `opts` is specified, then the default options (shown below) will be overridden.\n\n``` js\n{\n  nodeId: '',   // 160-bit DHT node ID (Buffer or hex string, default: randomly generated)\n  bootstrap: [] // bootstrap servers (default: router.bittorrent.com:6881, router.utorrent.com:6881, dht.transmissionbt.com:6881)\n}\n```\n\n#### `dht.lookup(infoHash)`\n\nFind peers for the given infoHash. `infoHash` can be a string or Buffer.\n\nThis does a recursive lookup in the DHT. Potential peers that are discovered are emitted\nas `peer` events. See the `peer` event below for more info.\n\n`dht.lookup()` should only be called after the ready event has fired, otherwise the lookup\nmay fail because the DHT routing table doesn't contain enough nodes.\n\n\n#### `dht.listen([port], [onlistening])`\n\nMake the DHT listen on the given `port`. If `port` is undefined, an available port is\nautomatically picked with [portfinder](https://github.com/indexzero/node-portfinder).\n\nIf `onlistening` is defined, it is attached to the `listening` event.\n\n\n#### `arr = dht.toArray()`\n\nReturns the nodes in the DHT as an array. This is useful for persisting the DHT\nto disk between restarts of a BitTorrent client (as recommended by the spec). Each node in the array is an object with `id` (hex string) and `addr` (string) properties.\n\nTo restore the DHT nodes when instantiating a new `DHT` object, simply pass in the array as the value of the `bootstrap` option.\n\n```js\nvar dht1 = new DHT()\n\n// some time passes ...\n\n// destroy the dht\nvar arr = dht1.toArray()\ndht1.destroy()\n\n// initialize a new dht with the same routing table as the first\nvar dht2 = new DHT({ bootstrap: arr })\n```\n\n#### `dht.addNode(addr, [nodeId])`\n\nManually add a node to the DHT routing table. If there is space in the routing table (or\nan unresponsive node can be evicted to make space), the node will be added. If not, the\nnode will not be added. This is useful to call when a peer wire sends a `PORT` message to\nshare their DHT port.\n\nIf `nodeId` is undefined, then the peer will be pinged to learn their node id. If the peer does not respond, the will not be added to the routing table.\n\n\n#### `dht.destroy([callback])`\n\nDestroy the DHT. Closes the socket and cleans up large data structure resources.\n\n\n### events\n\n#### `self.on('ready', function () { ... })`\n\nEmitted when the DHT is ready to handle lookups (i.e. the routing table contains at least K nodes, discovered via the bootstrap nodes).\n\n\n#### `self.on('peer', function (addr, infoHash) { ... })`\n\nEmitted when a potential peer is found. `addr` is of the form `IP_ADDRESS:PORT`.\n`infoHash` is the torrent info hash of the swarm that the peer belongs to. Emitted\nin response to a `lookup(infoHash)` call.\n\n\n#### `self.on('node', function (addr) { ... })`\n\nEmitted when the DHT finds a new node.\n\n\n#### `self.on('listening', function () { ... })`\n\nEmitted when the DHT is listening.\n\n\n#### `self.on('warning', function (err) { ... })`\n\nEmitted when the DHT gets an unexpected message from another DHT node. This is purely\ninformational.\n\n\n#### `self.on('error', function (err) { ... })`\n\nEmitted when the DHT has a fatal error.\n\n\n### further reading\n\n- [BitTorrent DHT protocol](http://www.bittorrent.org/beps/bep_0005.html)\n- [Kademlia: A Peer-to-peer Information System Based on the XOR Metric](http://www.cs.rice.edu/Conferences/IPTPS02/109.pdf)\n\n\n### license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n",
  "readmeFilename": "README.md",
  "_id": "bittorrent-dht@1.3.1",
  "dist": {
    "shasum": "797d82572be551a0e6ce32a18ae76f750b402536"
  },
  "_resolved": "https://registry.npmjs.org/bittorrent-dht/-/bittorrent-dht-1.3.1.tgz",
  "_from": "bittorrent-dht@^1.0.0"
}
