hypercore 10.16.1 → 10.17.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 +13 -4
- package/package.json +5 -2
package/lib/replicator.js
CHANGED
|
@@ -6,7 +6,8 @@ const { REQUEST_CANCELLED, REQUEST_TIMEOUT, INVALID_CAPABILITY, SNAPSHOT_NOT_AVA
|
|
|
6
6
|
const m = require('./messages')
|
|
7
7
|
const caps = require('./caps')
|
|
8
8
|
|
|
9
|
-
const DEFAULT_MAX_INFLIGHT = 32
|
|
9
|
+
const DEFAULT_MAX_INFLIGHT = [32, 512]
|
|
10
|
+
const SCALE_LATENCY = 50
|
|
10
11
|
const DEFAULT_SEGMENT_SIZE = 128 * 1024 // 128 KiB
|
|
11
12
|
|
|
12
13
|
class Attachable {
|
|
@@ -276,7 +277,7 @@ class Peer {
|
|
|
276
277
|
this.wireExtension = this.channel.messages[9]
|
|
277
278
|
|
|
278
279
|
this.inflight = 0
|
|
279
|
-
this.
|
|
280
|
+
this.inflightRange = DEFAULT_MAX_INFLIGHT
|
|
280
281
|
this.dataProcessing = 0
|
|
281
282
|
|
|
282
283
|
this.canUpgrade = true
|
|
@@ -310,6 +311,14 @@ class Peer {
|
|
|
310
311
|
replicator._ifAvailable++
|
|
311
312
|
}
|
|
312
313
|
|
|
314
|
+
getMaxInflight () {
|
|
315
|
+
const stream = this.stream.rawStream
|
|
316
|
+
if (!stream.udx) return Math.min(this.inflightRange[1], this.inflightRange[0] * 3)
|
|
317
|
+
|
|
318
|
+
const scale = stream.rtt <= SCALE_LATENCY ? 1 : stream.rtt / SCALE_LATENCY
|
|
319
|
+
return Math.round(Math.min(this.inflightRange[1], this.inflightRange[0] * scale))
|
|
320
|
+
}
|
|
321
|
+
|
|
313
322
|
signalUpgrade () {
|
|
314
323
|
if (this._shouldUpdateCanUpgrade() === true) this._updateCanUpgradeAndSync()
|
|
315
324
|
else this.sendSync()
|
|
@@ -1492,7 +1501,7 @@ module.exports = class Replicator {
|
|
|
1492
1501
|
}
|
|
1493
1502
|
|
|
1494
1503
|
_updatePeer (peer) {
|
|
1495
|
-
if (peer.paused || peer.inflight >= peer.
|
|
1504
|
+
if (peer.paused || peer.inflight >= peer.getMaxInflight()) {
|
|
1496
1505
|
return false
|
|
1497
1506
|
}
|
|
1498
1507
|
|
|
@@ -1518,7 +1527,7 @@ module.exports = class Replicator {
|
|
|
1518
1527
|
}
|
|
1519
1528
|
|
|
1520
1529
|
_updatePeerNonPrimary (peer) {
|
|
1521
|
-
if (peer.paused || peer.inflight >= peer.
|
|
1530
|
+
if (peer.paused || peer.inflight >= peer.getMaxInflight()) {
|
|
1522
1531
|
return false
|
|
1523
1532
|
}
|
|
1524
1533
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.17.0",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -60,7 +60,10 @@
|
|
|
60
60
|
"random-access-memory": "^6.1.0",
|
|
61
61
|
"random-access-memory-overlay": "^3.0.0",
|
|
62
62
|
"range-parser": "^1.2.1",
|
|
63
|
+
"speedometer": "^1.1.0",
|
|
63
64
|
"standard": "^17.0.0",
|
|
64
|
-
"
|
|
65
|
+
"tiny-byte-size": "^1.1.0",
|
|
66
|
+
"tmp-promise": "^3.0.2",
|
|
67
|
+
"udx-native": "^1.6.1"
|
|
65
68
|
}
|
|
66
69
|
}
|