hypercore 11.25.0 → 11.26.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/index.js +10 -0
- package/lib/feature-flags.js +3 -0
- package/lib/replicator.js +5 -1
- package/lib/wants.js +13 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11,6 +11,9 @@ const safetyCatch = require('safety-catch')
|
|
|
11
11
|
const unslab = require('unslab')
|
|
12
12
|
const flat = require('flat-tree')
|
|
13
13
|
|
|
14
|
+
const { SMALL_WANTS } = require('./lib/feature-flags')
|
|
15
|
+
const { UPDATE_COMPAT } = require('./lib/wants')
|
|
16
|
+
|
|
14
17
|
const inspect = require('./lib/inspect')
|
|
15
18
|
const Core = require('./lib/core')
|
|
16
19
|
const Info = require('./lib/info')
|
|
@@ -107,6 +110,13 @@ class Hypercore extends EventEmitter {
|
|
|
107
110
|
|
|
108
111
|
static DefaultEncryption = DefaultEncryption
|
|
109
112
|
|
|
113
|
+
static SMALL_WANTS = SMALL_WANTS
|
|
114
|
+
|
|
115
|
+
static enable(flag) {
|
|
116
|
+
const enableCompat = (flag & SMALL_WANTS) === 0
|
|
117
|
+
UPDATE_COMPAT(enableCompat)
|
|
118
|
+
}
|
|
119
|
+
|
|
110
120
|
static key(manifest, { compat, version, namespace } = {}) {
|
|
111
121
|
if (b4a.isBuffer(manifest)) {
|
|
112
122
|
manifest = { version, signers: [{ publicKey: manifest, namespace }] }
|
package/lib/replicator.js
CHANGED
|
@@ -31,7 +31,8 @@ const ReceiverQueue = require('./receiver-queue')
|
|
|
31
31
|
const HotswapQueue = require('./hotswap-queue')
|
|
32
32
|
const RemoteBitfield = require('./remote-bitfield')
|
|
33
33
|
const { MerkleTree } = require('./merkle-tree')
|
|
34
|
-
const
|
|
34
|
+
const w = require('./wants')
|
|
35
|
+
const { LocalWants, RemoteWants } = w
|
|
35
36
|
const {
|
|
36
37
|
REQUEST_CANCELLED,
|
|
37
38
|
REQUEST_TIMEOUT,
|
|
@@ -1730,6 +1731,7 @@ class Peer {
|
|
|
1730
1731
|
}
|
|
1731
1732
|
|
|
1732
1733
|
_addRangeBatch(r, offset, end) {
|
|
1734
|
+
const { WANT_BATCH } = w
|
|
1733
1735
|
while (offset < end) {
|
|
1734
1736
|
const next = this.core.bitfield.findFirst(false, offset)
|
|
1735
1737
|
if (next === -1 || next >= end) return false
|
|
@@ -1745,6 +1747,7 @@ class Peer {
|
|
|
1745
1747
|
}
|
|
1746
1748
|
|
|
1747
1749
|
_populateRangeBatches(r) {
|
|
1750
|
+
const { WANT_BATCH } = w
|
|
1748
1751
|
for (let i = r.batches.length - 1; i >= 0; i--) {
|
|
1749
1752
|
const b = r.batches[i]
|
|
1750
1753
|
const minStart = b.batch * WANT_BATCH
|
|
@@ -1800,6 +1803,7 @@ class Peer {
|
|
|
1800
1803
|
}
|
|
1801
1804
|
|
|
1802
1805
|
_requestRange(r) {
|
|
1806
|
+
const { WANT_BATCH } = w
|
|
1803
1807
|
if (this.syncsProcessing > 0) return false
|
|
1804
1808
|
|
|
1805
1809
|
const { length, fork } = this.core.state
|
package/lib/wants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
let COMPAT = true
|
|
2
|
+
let BATCH_UINTS = COMPAT ? 65536 : 128
|
|
3
|
+
let BATCH_BYTES = BATCH_UINTS * 4
|
|
4
|
+
let BATCH = BATCH_BYTES * 8 // in bits
|
|
5
5
|
const MAX_REMOTE_BATCHES = 4
|
|
6
6
|
const MAX_RANGE = 8 * 256 * 1024
|
|
7
7
|
const MIN_RANGE = 32 // 4bit ints
|
|
@@ -295,9 +295,18 @@ class RemoteWants {
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
function UPDATE_COMPAT(isCompat) {
|
|
299
|
+
COMPAT = isCompat
|
|
300
|
+
BATCH_UINTS = COMPAT ? 65536 : 128
|
|
301
|
+
BATCH_BYTES = BATCH_UINTS * 4
|
|
302
|
+
BATCH = BATCH_BYTES * 8 // in bits
|
|
303
|
+
exports.WANT_BATCH = BATCH
|
|
304
|
+
}
|
|
305
|
+
|
|
298
306
|
exports.LocalWants = LocalWants
|
|
299
307
|
exports.RemoteWants = RemoteWants
|
|
300
308
|
exports.WANT_BATCH = BATCH
|
|
309
|
+
exports.UPDATE_COMPAT = UPDATE_COMPAT
|
|
301
310
|
|
|
302
311
|
function validateBatchRange(range) {
|
|
303
312
|
if (range.length > MAX_RANGE || range.length < MIN_RANGE) {
|