diff options
-rw-r--r-- | lib/torrent.js | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index 99947eb..7c49e6e 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -529,14 +529,6 @@ class Torrent extends EventEmitter { this.bitfield = new BitField(this.pieces.length) - this.wires.forEach(wire => { - // If we didn't have the metadata at the time ut_metadata was initialized for this - // wire, we still want to make it available to the peer in case they request it. - if (wire.ut_metadata) wire.ut_metadata.setMetadata(this.metadata) - - this._onWireWithMetadata(wire) - }) - // Emit 'metadata' before 'ready' and 'done' this.emit('metadata') @@ -690,6 +682,15 @@ class Torrent extends EventEmitter { // In case any selections were made before torrent was ready this._updateSelections() + + // Start requesting pieces after we have initially verified them + this.wires.forEach(wire => { + // If we didn't have the metadata at the time ut_metadata was initialized for this + // wire, we still want to make it available to the peer in case they request it. + if (wire.ut_metadata) wire.ut_metadata.setMetadata(this.metadata) + + this._onWireWithMetadata(wire) + }) } destroy (opts, cb) { @@ -1109,7 +1110,7 @@ class Torrent extends EventEmitter { // More info: https://github.com/webtorrent/bittorrent-protocol#extension-api this.emit('wire', wire, addr) - if (this.metadata) { + if (this.ready) { queueMicrotask(() => { // This allows wire.handshake() to be called (by Peer.onHandshake) before any // messages get sent on the wire |