bittorrent-dht
Advanced tools
Comparing version 0.5.0 to 0.6.0
11
index.js
@@ -12,9 +12,8 @@ // TODO: | ||
var compact2string = require('compact2string') | ||
var crypto = require('crypto') | ||
var dgram = require('dgram') // or chrome-dgram | ||
var debug = require('debug')('bittorrent-dht') | ||
var dgram = require('dgram') | ||
var EventEmitter = require('events').EventEmitter | ||
var hat = require('hat') | ||
var inherits = require('inherits') | ||
var portfinder = require('portfinder') // or chrome-portfinder | ||
var debug = require('debug')('bittorrent-dht'); | ||
var portfinder = require('portfinder') | ||
@@ -122,3 +121,3 @@ // Use random port above 1024 | ||
var port = Number(addr.split(':')[1]) | ||
if (!(port > 0 && port < 65535)) return; | ||
if (!(port > 0 && port < 65535)) return | ||
this.socket.send(this.message, 0, this.message.length, port, host, function () { | ||
@@ -128,3 +127,3 @@ setTimeout(function () { | ||
if (!this.nodes[addr] && this.reqs[addr] < MAX_REQUESTS) { | ||
this.query.call(this, addr); | ||
this.query.call(this, addr) | ||
} | ||
@@ -131,0 +130,0 @@ }.bind(this), REQ_TIMEOUT) |
{ | ||
"name": "bittorrent-dht", | ||
"description": "Simple, robust, BitTorrent DHT implementation", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"author": { | ||
@@ -10,6 +10,2 @@ "name": "Feross Aboukhadijeh", | ||
}, | ||
"browser": { | ||
"dgram": "chrome-dgram/index.js", | ||
"portfinder": "chrome-portfinder/index.js" | ||
}, | ||
"bugs": { | ||
@@ -19,15 +15,12 @@ "url": "https://github.com/feross/bittorrent-dht/issues" | ||
"dependencies": { | ||
"bitfield": "~0.1.0", | ||
"bncode": "~0.5.2", | ||
"chrome-dgram": "2.x", | ||
"chrome-portfinder": "0.x", | ||
"compact2string": "~1.2.0", | ||
"hat": "0.0.3", | ||
"inherits": "~2.0.1", | ||
"portfinder": "~0.2.1", | ||
"debug": "^0.7.4" | ||
"bncode": "^0.5.3", | ||
"compact2string": "^1.2.0", | ||
"debug": "^0.8.0", | ||
"hat": "^0.0.3", | ||
"inherits": "^2.0.1", | ||
"portfinder": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"once": "1.x", | ||
"tape": "2.x" | ||
"once": "^1.3.0", | ||
"tape": "^2.12.3" | ||
}, | ||
@@ -34,0 +27,0 @@ "homepage": "http://webtorrent.io", |
@@ -1,6 +0,2 @@ | ||
# bittorrent-dht | ||
[](https://travis-ci.org/feross/bittorrent-dht) | ||
[](https://npmjs.org/package/bittorrent-dht) | ||
[](https://npmjs.org/package/bittorrent-dht) | ||
[](https://www.gittip.com/feross/) | ||
# bittorrent-dht [](https://travis-ci.org/feross/bittorrent-dht) [](https://npmjs.org/package/bittorrent-dht) [](https://npmjs.org/package/bittorrent-dht) [](https://www.gittip.com/feross/) | ||
@@ -11,8 +7,6 @@ ### Simple, robust, BitTorrent DHT implementation | ||
Works in the browser with [browserify](http://browserify.org/) and [chrome-dgram](https://github.com/feross/chrome-dgram)! | ||
This module is used by [WebTorrent](https://github.com/feross/WebTorrent). Works in the browser with [browserify](http://browserify.org/) and a `dgram` shim (like [chrome-dgram](https://github.com/feross/chrome-dgram) for chrome apps). | ||
This module is used by [WebTorrent](https://github.com/feross/WebTorrent). | ||
### install | ||
## install | ||
``` | ||
@@ -22,8 +16,81 @@ npm install bittorrent-dht | ||
## methods | ||
### example | ||
TODO | ||
```javascript | ||
var DHT = require('bittorrent-dht'); | ||
var magnet = require('magnet-uri'); | ||
## license | ||
var uri = "magnet:?xt=urn:btih:e3811b9539cacff680e418124272177c47477157&dn=Ubuntu+13.10+Desktop+Live+ISO+amd64"; | ||
var parsed = magnet(uri); | ||
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). | ||
var dht = new DHT(); | ||
dht.on('peer', function (addr, hash) { | ||
console.log('Found peer at ' + addr + '!'); | ||
}); | ||
dht.setInfoHash(parsed.infoHash); | ||
var port = 20000; | ||
dht.listen(port, function (port) { | ||
console.log("Now listening on port " + port); | ||
}); | ||
dht.findPeers(); | ||
``` | ||
### methods | ||
#### `setInfoHash(infoHash)` | ||
Associate an infoHash with the DHT object. Can be a String or Buffer. | ||
#### `dht.listen([port], [callback])` | ||
Open the socket. If port is undefined, one is picked with [portfinder](https://github.com/indexzero/node-portfinder). | ||
`callback` is equivalent to `listening` event. | ||
#### `findPeers([num])` | ||
Get `num` peers from the DHT. Defaults to unlimited. | ||
### events | ||
#### 'peer' | ||
function (addr, infoHash){ ... } | ||
Called when a peer is found. `addr` is of the form `IP_ADDRESS:PORT` | ||
#### 'message' | ||
function (data, rinfo){ ... } | ||
Called when a message is received. `rinfo` is an object with properties `address`, `port` | ||
#### 'node' | ||
function (addr){ ... } | ||
Called when client finds a new DHT node. | ||
#### 'listening' | ||
function () { ... } | ||
#### 'error' | ||
function (err){ ... } | ||
### license | ||
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). |
14530
6
95
333
+ Addedcompact2string@1.4.1(transitive)
+ Addeddebug@0.8.1(transitive)
+ Addedipaddr.js@2.2.0(transitive)
- Removedbitfield@~0.1.0
- Removedchrome-dgram@2.x
- Removedchrome-portfinder@0.x
- Removedbitfield@0.1.0(transitive)
- Removedchrome-dgram@2.1.7(transitive)
- Removedchrome-net@3.3.4(transitive)
- Removedchrome-portfinder@0.3.5(transitive)
- Removedcompact2string@1.2.0(transitive)
- Removeddebug@0.7.4(transitive)
- Removedrun-series@1.1.9(transitive)
Updatedbncode@^0.5.3
Updatedcompact2string@^1.2.0
Updateddebug@^0.8.0
Updatedhat@^0.0.3
Updatedinherits@^2.0.1
Updatedportfinder@^0.2.1