hypercore 10.29.2 → 10.30.0
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 -0
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -11,6 +11,7 @@ const caps = require('./caps')
|
|
|
11
11
|
const DEFAULT_MAX_INFLIGHT = [32, 512]
|
|
12
12
|
const SCALE_LATENCY = 50
|
|
13
13
|
const DEFAULT_SEGMENT_SIZE = 256 * 1024 * 8 // 256 KiB in bits
|
|
14
|
+
const BLOCK_TIMEOUT = 5000
|
|
14
15
|
|
|
15
16
|
const PRIORITY = {
|
|
16
17
|
NORMAL: 0,
|
|
@@ -208,6 +209,7 @@ class InflightTracker {
|
|
|
208
209
|
const id = this._free.length ? this._free.pop() : this._requests.push(null)
|
|
209
210
|
|
|
210
211
|
req.id = id
|
|
212
|
+
req.timeout = setTimeout(onblocktimeout, BLOCK_TIMEOUT, req)
|
|
211
213
|
this._requests[id - 1] = req
|
|
212
214
|
return req
|
|
213
215
|
}
|
|
@@ -218,6 +220,9 @@ class InflightTracker {
|
|
|
218
220
|
|
|
219
221
|
remove (id) {
|
|
220
222
|
if (id <= this._requests.length) {
|
|
223
|
+
const req = this._requests[id - 1]
|
|
224
|
+
clearTimeout(req.timeout)
|
|
225
|
+
req.timeout = null
|
|
221
226
|
this._requests[id - 1] = null
|
|
222
227
|
this._free.push(id)
|
|
223
228
|
}
|
|
@@ -785,6 +790,7 @@ class Peer {
|
|
|
785
790
|
return {
|
|
786
791
|
peer: this,
|
|
787
792
|
id: 0,
|
|
793
|
+
timeout: null,
|
|
788
794
|
fork: this.remoteFork,
|
|
789
795
|
block: null,
|
|
790
796
|
hash: null,
|
|
@@ -2068,3 +2074,7 @@ function onwirerange (m, c) {
|
|
|
2068
2074
|
function onwireextension (m, c) {
|
|
2069
2075
|
return c.userData.onextension(m)
|
|
2070
2076
|
}
|
|
2077
|
+
|
|
2078
|
+
function onblocktimeout (req) {
|
|
2079
|
+
if (req.peer.isActive()) req.peer.stream.destroy(REQUEST_TIMEOUT())
|
|
2080
|
+
}
|