diff options
author | Ivan Borzenkov <ivan.borzenkov@gmail.com> | 2021-08-17 21:16:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 21:16:50 +0300 |
commit | 9938c949eee9c69c6774767e885e40f0a73898d9 (patch) | |
tree | 1414874d11dad28ca45bfbf88322f01f16ff656d /index.js | |
parent | 3994304a0d9e08b382d4e5907ec0eea45441b6f6 (diff) |
feat: Add PE/MSE support (#1820)
* reimplement #1384
* add option for secure - performance issue
* fixes after code review
* fix error
* use const in hex
* use stored hash
* Update lib/peer.js
Co-authored-by: Diego RodrÃguez Baquero <github@diegorbaquero.com>
* fix const
Co-authored-by: Diego RodrÃguez Baquero <github@diegorbaquero.com>
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -13,6 +13,7 @@ const path = require('path') const Peer = require('simple-peer') const queueMicrotask = require('queue-microtask') const randombytes = require('randombytes') +const sha1 = require('simple-sha1') const speedometer = require('speedometer') const { ThrottleGroup } = require('speed-limiter') @@ -80,6 +81,10 @@ class WebTorrent extends EventEmitter { this._downloadLimit = Math.max((typeof opts.downloadLimit === 'number') ? opts.downloadLimit : -1, -1) this._uploadLimit = Math.max((typeof opts.uploadLimit === 'number') ? opts.uploadLimit : -1, -1) + if (opts.secure === true) { + require('./lib/peer').enableSecure() + } + this._debug( 'new webtorrent (peerId %s, nodeId %s, port %s)', this.peerId, this.nodeId, this.torrentPort @@ -446,6 +451,19 @@ class WebTorrent extends EventEmitter { args[0] = `[${this._debugId}] ${args[0]}` debug(...args) } + + _getByHash (infoHashHash) { + for (const torrent of this.torrents) { + if (!torrent.infoHashHash) { + torrent.infoHashHash = sha1.sync(Buffer.from('72657132' /* 'req2' */ + torrent.infoHash, 'hex')) + } + if (infoHashHash === torrent.infoHashHash) { + return torrent + } + } + + return null + } } WebTorrent.WEBRTC_SUPPORT = Peer.WEBRTC_SUPPORT |