From eaf085b36b5a5ac78369210fc39ba272d033d829 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Dec 2015 22:38:25 -0800 Subject: [PATCH 1/5] Standardize hash variable names (fix #374) --- index.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 9e783bee..dbf91f0e 100644 --- a/index.js +++ b/index.js @@ -18,16 +18,28 @@ var Torrent = require('./lib/torrent') inherits(WebTorrent, EventEmitter) +/** + * WebTorrent version. + */ var VERSION = require('./package.json').version /** - * BitTorrent client version string (used in peer ID). - * Generated from package.json major and minor version. For example: + * Version number in Azureus-style. Generated from major and minor semver version. + * For example: * '0.16.1' -> '0016' * '1.2.5' -> '0102' */ var VERSION_STR = VERSION.match(/([0-9]+)/g).slice(0, 2).map(zeroFill(2)).join('') +/** + * Version prefix string (used in peer ID). WebTorrent uses the Azureus-style + * encoding: '-', two characters for client id ('WW'), four ascii digits for version + * number, '-', followed by random numbers. + * For example: + * '-WW0102-'... + */ +var VERSION_PREFIX = '-WW' + VERSION_STR + '-' + /** * WebTorrent Client * @param {Object} opts @@ -35,8 +47,9 @@ var VERSION_STR = VERSION.match(/([0-9]+)/g).slice(0, 2).map(zeroFill(2)).join(' function WebTorrent (opts) { var self = this if (!(self instanceof WebTorrent)) return new WebTorrent(opts) - if (!opts) opts = {} EventEmitter.call(self) + + if (!opts) opts = {} if (!debug.enabled) self.setMaxListeners(0) self.destroyed = false @@ -51,19 +64,15 @@ function WebTorrent (opts) { self.downloadSpeed = speedometer() self.uploadSpeed = speedometer() - self.peerId = opts.peerId === undefined - ? new Buffer('-WW' + VERSION_STR + '-' + hat(48), 'utf8') - : typeof opts.peerId === 'string' - ? new Buffer(opts.peerId, 'hex') - : opts.peerId - self.peerIdHex = self.peerId.toString('hex') + self.peerId = typeof opts.peerId === 'string' + ? opts.peerId + : (opts.peerId || new Buffer(VERSION_PREFIX + hat(48))).toString('hex') + self.peerIdBuffer = new Buffer(self.peerId, 'hex') - self.nodeId = opts.nodeId === undefined - ? new Buffer(hat(160), 'hex') - : typeof opts.nodeId === 'string' - ? new Buffer(opts.nodeId, 'hex') - : opts.nodeId - self.nodeIdHex = self.nodeId.toString('hex') + self.nodeId = typeof opts.nodeId === 'string' + ? opts.nodeId + : (opts.nodeId && opts.nodeId.toString('hex')) || hat(160) + self.nodeIdBuffer = new Buffer(self.nodeId, 'hex') if (opts.dht !== false && typeof DHT === 'function' /* browser exclude */) { // use a single DHT instance for all torrents, so the routing table can be reused @@ -71,7 +80,7 @@ function WebTorrent (opts) { self.dht.listen(opts.dhtPort) } - debug('new webtorrent (peerId %s, nodeId %s)', self.peerIdHex, self.nodeIdHex) + debug('new webtorrent (peerId %s, nodeId %s)', self.peerId, self.nodeId) if (typeof loadIPSet === 'function') { loadIPSet(opts.blocklist, { From 8e88e4a514d34df0d9f5aa38e6d92383ee4b9ad6 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Dec 2015 22:49:43 -0800 Subject: [PATCH 2/5] torrent-discovery@4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc060b90..f713e67d 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "simple-sha1": "^2.0.0", "speedometer": "^1.0.0", "thunky": "^0.1.0", - "torrent-discovery": "^3.0.0", + "torrent-discovery": "^4.0.0", "torrent-piece": "^1.0.0", "uniq": "^1.0.1", "ut_metadata": "^2.1.0", From 3c3a06a145fa4b2d0cd3f39fd277c305e6c445bc Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Dec 2015 22:54:05 -0800 Subject: [PATCH 3/5] bittorrent-dht@5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f713e67d..3413984c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "dependencies": { "addr-to-ip-port": "^1.0.1", "bitfield": "^1.0.2", - "bittorrent-dht": "^4.0.4", + "bittorrent-dht": "^5.0.0", "bittorrent-swarm": "^5.0.0", "chunk-store-stream": "^2.0.0", "clivas": "^0.2.0", From 0e513474f721ade53c7e30fb0277fd822fbe7a4a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Dec 2015 22:59:06 -0800 Subject: [PATCH 4/5] bittorrent-swarm@6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3413984c..8cc8ffd0 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "addr-to-ip-port": "^1.0.1", "bitfield": "^1.0.2", "bittorrent-dht": "^5.0.0", - "bittorrent-swarm": "^5.0.0", + "bittorrent-swarm": "^6.0.0", "chunk-store-stream": "^2.0.0", "clivas": "^0.2.0", "create-torrent": "^3.4.0", From f0570b32596b9ca9840a56df03b87ead72ef12af Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Dec 2015 23:02:40 -0800 Subject: [PATCH 5/5] ut_metadata@3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8cc8ffd0..7d0c23de 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "torrent-discovery": "^4.0.0", "torrent-piece": "^1.0.0", "uniq": "^1.0.1", - "ut_metadata": "^2.1.0", + "ut_metadata": "^3.0.1", "ut_pex": "^1.0.1", "videostream": "^1.1.4", "windows-no-runnable": "0.0.6",