Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex <alxmorais8@msn.com>2022-03-27 23:09:55 +0300
committerGitHub <noreply@github.com>2022-03-27 23:09:55 +0300
commit11f6158445e7b54785b5764cdd9f1e64255aaec1 (patch)
tree349d012d5ef537caecc4000916eb319e881e2c45
parent38848a5410188f935d4c1d9b4476b5ac733e8b9f (diff)
refactor: trigger _onWireWithMetadata after selections are updated (#2103)
Co-authored-by: Diego Rodríguez Baquero <github@diegorbaquero.com>
-rw-r--r--lib/torrent.js19
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