diff options
author | John Hiesey <john@hiesey.com> | 2021-02-27 01:37:28 +0300 |
---|---|---|
committer | John Hiesey <john@hiesey.com> | 2021-02-27 01:37:28 +0300 |
commit | 44426c5e3844ff265374b64a01fff8476481b8d0 (patch) | |
tree | 30d7a19baebdacb618d3e0de8f0f5ef177c9ac86 /lib | |
parent | 7a74efc60dbc8a17be4fb7324855ae49c6f78e82 (diff) |
Code review fixes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 15 | ||||
-rw-r--r-- | lib/webconn.js | 3 |
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 5d2b313..930304f 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -821,16 +821,15 @@ class Torrent extends EventEmitter { return newPeer } - addWebSeed (urlOrConnection) { + addWebSeed (urlOrConn) { if (this.destroyed) throw new Error('torrent is destroyed') let id let conn - if (typeof urlOrConnection === 'string') { - const url = urlOrConnection - id = urlOrConnection + if (typeof urlOrConn === 'string') { + id = urlOrConn - if (!/^https?:\/\/.+/.test(url)) { + if (!/^https?:\/\/.+/.test(id)) { this.emit('warning', new Error(`ignoring invalid web seed: ${id}`)) this.emit('invalidPeer', id) return @@ -842,9 +841,9 @@ class Torrent extends EventEmitter { return } - conn = new WebConn(url, this) - } else if (urlOrConnection && typeof urlOrConnection.connId === 'string') { - conn = urlOrConnection + conn = new WebConn(id, this) + } else if (urlOrConn && typeof urlOrConn.connId === 'string') { + conn = urlOrConn id = conn.connId if (this._peers[id]) { diff --git a/lib/webconn.js b/lib/webconn.js index 93ae966..a2c24a4 100644 --- a/lib/webconn.js +++ b/lib/webconn.js @@ -16,7 +16,8 @@ class WebConn extends Wire { super() this.url = url - this.webPeerId = sha1.sync(url) + this.connId = url // Unique id to deduplicate web seeds + this.webPeerId = sha1.sync(url) // Used as the peerId for this fake remote peer this._torrent = torrent this._init() |