hypercore 10.37.2 → 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 +13 -6
- 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)
|
|
@@ -862,7 +868,9 @@ class Peer {
|
|
|
862
868
|
this.inflight--
|
|
863
869
|
this.replicator._removeInflight(req.id, true)
|
|
864
870
|
if (this.roundtripQueue === null) return
|
|
865
|
-
|
|
871
|
+
const flushed = this.roundtripQueue.flush(req.rt)
|
|
872
|
+
if (flushed === null) return
|
|
873
|
+
for (const id of flushed) this.replicator._inflight.reusable(id)
|
|
866
874
|
}
|
|
867
875
|
|
|
868
876
|
onwant ({ start, length }) {
|
|
@@ -1341,6 +1349,9 @@ class Peer {
|
|
|
1341
1349
|
return
|
|
1342
1350
|
}
|
|
1343
1351
|
|
|
1352
|
+
// this was cancelled during the above async work
|
|
1353
|
+
if (req.priority === PRIORITY.CANCELLED) return
|
|
1354
|
+
|
|
1344
1355
|
this.tracer.trace('send', req)
|
|
1345
1356
|
|
|
1346
1357
|
this.wireRequest.send(req)
|
|
@@ -1792,10 +1803,6 @@ module.exports = class Replicator {
|
|
|
1792
1803
|
|
|
1793
1804
|
if (b === null || removeInflight(b.inflight, req) === false) return
|
|
1794
1805
|
|
|
1795
|
-
// if (isBlock && this.core.bitfield.get(index) === false) {
|
|
1796
|
-
// for (const peer of this.peers) peer.skipList.set(index, false)
|
|
1797
|
-
// }
|
|
1798
|
-
|
|
1799
1806
|
if (b.refs.length > 0 && isBlock === true) {
|
|
1800
1807
|
this._queueBlock(b)
|
|
1801
1808
|
return
|