diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-12-04 05:03:54 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-12-04 05:03:54 +0300 |
commit | 3a6a7afcabcef7a0600bb50692c2cca7ff1f3d46 (patch) | |
tree | 0ad17f5d6283b4dc4d3da3a52ee7fb784393f433 | |
parent | be882a41aef365faed42c0f46d12d97c6351b34a (diff) | |
parent | f0570b32596b9ca9840a56df03b87ead72ef12af (diff) |
Merge pull request #510 from feross/standardize-var-names
Standardize variable names (Fix #374)
-rw-r--r-- | index.js | 41 | ||||
-rw-r--r-- | package.json | 8 |
2 files changed, 29 insertions, 20 deletions
@@ -18,25 +18,38 @@ 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 */ 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, { diff --git a/package.json b/package.json index 02b9b5d..a2b8584 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ "dependencies": { "addr-to-ip-port": "^1.0.1", "bitfield": "^1.0.2", - "bittorrent-dht": "^4.0.4", - "bittorrent-swarm": "^5.0.0", + "bittorrent-dht": "^5.0.0", + "bittorrent-swarm": "^6.0.0", "chunk-store-stream": "^2.0.0", "clivas": "^0.2.0", "create-torrent": "^3.4.0", @@ -58,10 +58,10 @@ "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", + "ut_metadata": "^3.0.1", "ut_pex": "^1.0.1", "videostream": "^1.1.4", "windows-no-runnable": "0.0.6", |