hypercore 10.37.3 → 10.37.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/replicator.js +10 -5
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -41,7 +41,8 @@ const NOT_DOWNLOADING_SLACK = 20000 + (Math.random() * 20000) | 0
|
|
|
41
41
|
const PRIORITY = {
|
|
42
42
|
NORMAL: 0,
|
|
43
43
|
HIGH: 1,
|
|
44
|
-
VERY_HIGH: 2
|
|
44
|
+
VERY_HIGH: 2,
|
|
45
|
+
CANCELLED: 255 // reserved to mark cancellation
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
class Attachable {
|
|
@@ -140,6 +141,8 @@ class BlockRequest extends Attachable {
|
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
_unref () {
|
|
144
|
+
this.queued = false
|
|
145
|
+
|
|
143
146
|
for (const req of this.inflight) {
|
|
144
147
|
req.peer._cancelRequest(req.id)
|
|
145
148
|
}
|
|
@@ -748,6 +751,9 @@ class Peer {
|
|
|
748
751
|
const req = this.replicator._inflight.get(id)
|
|
749
752
|
if (!req) return
|
|
750
753
|
|
|
754
|
+
// mark as cancelled also
|
|
755
|
+
req.priority = PRIORITY.CANCELLED
|
|
756
|
+
|
|
751
757
|
this.inflight--
|
|
752
758
|
this.replicator._removeInflight(id, false)
|
|
753
759
|
if (isBlockRequest(req)) this.replicator._unmarkInflight(req.block.index)
|
|
@@ -1343,6 +1349,9 @@ class Peer {
|
|
|
1343
1349
|
return
|
|
1344
1350
|
}
|
|
1345
1351
|
|
|
1352
|
+
// this was cancelled during the above async work
|
|
1353
|
+
if (req.priority === PRIORITY.CANCELLED) return
|
|
1354
|
+
|
|
1346
1355
|
this.tracer.trace('send', req)
|
|
1347
1356
|
|
|
1348
1357
|
this.wireRequest.send(req)
|
|
@@ -1794,10 +1803,6 @@ module.exports = class Replicator {
|
|
|
1794
1803
|
|
|
1795
1804
|
if (b === null || removeInflight(b.inflight, req) === false) return
|
|
1796
1805
|
|
|
1797
|
-
// if (isBlock && this.core.bitfield.get(index) === false) {
|
|
1798
|
-
// for (const peer of this.peers) peer.skipList.set(index, false)
|
|
1799
|
-
// }
|
|
1800
|
-
|
|
1801
1806
|
if (b.refs.length > 0 && isBlock === true) {
|
|
1802
1807
|
this._queueBlock(b)
|
|
1803
1808
|
return
|