hypercore 10.5.3 → 10.6.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/README.md +6 -4
- package/index.js +10 -11
- package/lib/replicator.js +25 -16
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Hypercore
|
|
2
2
|
|
|
3
|
+
### [See the full API docs at docs.holepunch.to](https://docs.holepunch.to/building-blocks/hypercore)
|
|
4
|
+
|
|
3
5
|
Hypercore is a secure, distributed append-only log.
|
|
4
6
|
|
|
5
7
|
Built for sharing large datasets and streams of real time data
|
|
@@ -76,7 +78,7 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
|
|
|
76
78
|
|
|
77
79
|
You can also set valueEncoding to any [abstract-encoding](https://github.com/mafintosh/abstract-encoding) or [compact-encoding](https://github.com/compact-encoding) instance.
|
|
78
80
|
|
|
79
|
-
valueEncodings will be applied to
|
|
81
|
+
valueEncodings will be applied to individual blocks, even if you append batches. If you want to control encoding at the batch-level, you can use the `encodeBatch` option, which is a function that takes a batch and returns a binary-encoded batch. If you provide a custom valueEncoding, it will not be applied prior to `encodeBatch`.
|
|
80
82
|
|
|
81
83
|
#### `const { length, byteLength } = await core.append(block)`
|
|
82
84
|
|
|
@@ -124,7 +126,7 @@ Check if the core has all blocks between `start` and `end`.
|
|
|
124
126
|
|
|
125
127
|
#### `const updated = await core.update()`
|
|
126
128
|
|
|
127
|
-
Wait for the core to try and find a signed update to
|
|
129
|
+
Wait for the core to try and find a signed update to its length.
|
|
128
130
|
Does not download any data from peers except for a proof of the new core length.
|
|
129
131
|
|
|
130
132
|
``` js
|
|
@@ -137,7 +139,7 @@ console.log('core was updated?', updated, 'length is', core.length)
|
|
|
137
139
|
|
|
138
140
|
Seek to a byte offset.
|
|
139
141
|
|
|
140
|
-
Returns `[index, relativeOffset]`, where `index` is the data block the byteOffset is contained in and `relativeOffset` is
|
|
142
|
+
Returns `[index, relativeOffset]`, where `index` is the data block the `byteOffset` is contained in and `relativeOffset` is
|
|
141
143
|
the relative byte offset in the data block.
|
|
142
144
|
|
|
143
145
|
``` js
|
|
@@ -293,7 +295,7 @@ as all internals await this themself.
|
|
|
293
295
|
|
|
294
296
|
#### `core.on('ready')`
|
|
295
297
|
|
|
296
|
-
Emitted after the core has initially opened all
|
|
298
|
+
Emitted after the core has initially opened all its internal state.
|
|
297
299
|
|
|
298
300
|
#### `core.writable`
|
|
299
301
|
|
package/index.js
CHANGED
|
@@ -385,7 +385,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
async _close (err) {
|
|
388
|
-
await this.opening
|
|
388
|
+
if (this.opened === false) await this.opening
|
|
389
389
|
|
|
390
390
|
const i = this.sessions.indexOf(this)
|
|
391
391
|
if (i === -1) return
|
|
@@ -646,20 +646,19 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
646
646
|
return this._updateSnapshot()
|
|
647
647
|
}
|
|
648
648
|
|
|
649
|
-
const
|
|
650
|
-
const req = this.replicator.addUpgrade(activeRequests)
|
|
649
|
+
const remoteWait = typeof (opts && opts.wait) === 'boolean' ? opts.wait : this._findingPeers > 0
|
|
651
650
|
|
|
652
|
-
let upgraded =
|
|
651
|
+
let upgraded = false
|
|
653
652
|
|
|
654
|
-
if (
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const end = this.core.tree.length
|
|
658
|
-
const contig = this.contiguousLength
|
|
653
|
+
if (await this.replicator.applyPendingReorg()) {
|
|
654
|
+
upgraded = true
|
|
655
|
+
}
|
|
659
656
|
|
|
660
|
-
|
|
657
|
+
if (!upgraded && remoteWait) {
|
|
658
|
+
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
659
|
+
const req = this.replicator.addUpgrade(activeRequests)
|
|
661
660
|
|
|
662
|
-
|
|
661
|
+
upgraded = await req.promise
|
|
663
662
|
}
|
|
664
663
|
|
|
665
664
|
if (!upgraded) return false
|
package/lib/replicator.js
CHANGED
|
@@ -909,7 +909,7 @@ module.exports = class Replicator {
|
|
|
909
909
|
this._hadPeers = false
|
|
910
910
|
this._ifAvailable = 0
|
|
911
911
|
this._updatesPending = 0
|
|
912
|
-
this._applyingReorg =
|
|
912
|
+
this._applyingReorg = null
|
|
913
913
|
}
|
|
914
914
|
|
|
915
915
|
cork () {
|
|
@@ -959,6 +959,23 @@ module.exports = class Replicator {
|
|
|
959
959
|
await Promise.allSettled(all)
|
|
960
960
|
}
|
|
961
961
|
|
|
962
|
+
async applyPendingReorg () {
|
|
963
|
+
if (this._applyingReorg !== null) {
|
|
964
|
+
await this._applyingReorg
|
|
965
|
+
return true
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
for (let i = this._reorgs.length - 1; i >= 0; i--) {
|
|
969
|
+
const f = this._reorgs[i]
|
|
970
|
+
if (f.batch !== null && f.batch.finished) {
|
|
971
|
+
await this._applyReorg(f)
|
|
972
|
+
return true
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
return false
|
|
977
|
+
}
|
|
978
|
+
|
|
962
979
|
addUpgrade (session) {
|
|
963
980
|
if (this._upgrade !== null) {
|
|
964
981
|
const ref = this._upgrade.attach(session)
|
|
@@ -968,14 +985,6 @@ module.exports = class Replicator {
|
|
|
968
985
|
|
|
969
986
|
const ref = this._addUpgrade().attach(session)
|
|
970
987
|
|
|
971
|
-
for (let i = this._reorgs.length - 1; i >= 0 && this._applyingReorg === false; i--) {
|
|
972
|
-
const f = this._reorgs[i]
|
|
973
|
-
if (f.batch !== null && f.batch.finished) {
|
|
974
|
-
this._applyReorg(f)
|
|
975
|
-
break
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
|
|
979
988
|
this.updateAll()
|
|
980
989
|
|
|
981
990
|
return ref
|
|
@@ -1070,7 +1079,7 @@ module.exports = class Replicator {
|
|
|
1070
1079
|
|
|
1071
1080
|
// check if reorgs in progress...
|
|
1072
1081
|
|
|
1073
|
-
if (this._applyingReorg
|
|
1082
|
+
if (this._applyingReorg !== null) return
|
|
1074
1083
|
|
|
1075
1084
|
// TODO: we prob should NOT wait for inflight reorgs here, seems better to just resolve the upgrade
|
|
1076
1085
|
// and then apply the reorg on the next call in case it's slow - needs some testing in practice
|
|
@@ -1429,17 +1438,17 @@ module.exports = class Replicator {
|
|
|
1429
1438
|
|
|
1430
1439
|
const u = this._upgrade
|
|
1431
1440
|
|
|
1432
|
-
this._applyingReorg = true
|
|
1433
1441
|
this._reorgs = [] // clear all as the nodes are against the old tree - easier
|
|
1442
|
+
this._applyingReorg = this.core.reorg(f.batch, null) // TODO: null should be the first/last peer?
|
|
1434
1443
|
|
|
1435
1444
|
try {
|
|
1436
|
-
await this.
|
|
1445
|
+
await this._applyingReorg
|
|
1437
1446
|
} catch (err) {
|
|
1438
1447
|
this._upgrade = null
|
|
1439
1448
|
u.reject(err)
|
|
1440
1449
|
}
|
|
1441
1450
|
|
|
1442
|
-
this._applyingReorg =
|
|
1451
|
+
this._applyingReorg = null
|
|
1443
1452
|
|
|
1444
1453
|
if (this._upgrade !== null) {
|
|
1445
1454
|
this._resolveUpgradeRequest(null)
|
|
@@ -1461,7 +1470,7 @@ module.exports = class Replicator {
|
|
|
1461
1470
|
}
|
|
1462
1471
|
|
|
1463
1472
|
_updateFork (peer) {
|
|
1464
|
-
if (this._applyingReorg
|
|
1473
|
+
if (this._applyingReorg !== null || this.allowFork === false || peer.remoteFork <= this.core.tree.fork) {
|
|
1465
1474
|
return false
|
|
1466
1475
|
}
|
|
1467
1476
|
|
|
@@ -1531,7 +1540,7 @@ module.exports = class Replicator {
|
|
|
1531
1540
|
|
|
1532
1541
|
updatePeer (peer) {
|
|
1533
1542
|
// Quick shortcut to wait for flushing reorgs - not needed but less waisted requests
|
|
1534
|
-
if (this._applyingReorg
|
|
1543
|
+
if (this._applyingReorg !== null) return
|
|
1535
1544
|
|
|
1536
1545
|
while (this._updatePeer(peer) === true);
|
|
1537
1546
|
while (this._updatePeerNonPrimary(peer) === true);
|
|
@@ -1542,7 +1551,7 @@ module.exports = class Replicator {
|
|
|
1542
1551
|
|
|
1543
1552
|
updateAll () {
|
|
1544
1553
|
// Quick shortcut to wait for flushing reorgs - not needed but less waisted requests
|
|
1545
|
-
if (this._applyingReorg
|
|
1554
|
+
if (this._applyingReorg !== null) return
|
|
1546
1555
|
|
|
1547
1556
|
const peers = new RandomIterator(this.peers)
|
|
1548
1557
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/
|
|
12
|
+
"url": "git+https://github.com/holepunchto/hypercore.git"
|
|
13
13
|
},
|
|
14
14
|
"contributors": [
|
|
15
15
|
{
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
],
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/holepunchto/hypercore/issues"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
30
|
+
"homepage": "https://github.com/holepunchto/hypercore#readme",
|
|
31
31
|
"files": [
|
|
32
32
|
"index.js",
|
|
33
33
|
"lib/**.js"
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"random-access-file": "^4.0.0",
|
|
48
48
|
"random-array-iterator": "^1.0.0",
|
|
49
49
|
"safety-catch": "^1.0.1",
|
|
50
|
-
"sodium-universal": "^
|
|
50
|
+
"sodium-universal": "^4.0.0",
|
|
51
51
|
"streamx": "^2.12.4",
|
|
52
52
|
"xache": "^1.1.0",
|
|
53
53
|
"z32": "^1.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"brittle": "^3.0.0",
|
|
57
|
-
"hyperswarm": "^4.3.
|
|
57
|
+
"hyperswarm": "^4.3.6",
|
|
58
58
|
"random-access-memory": "^6.1.0",
|
|
59
59
|
"random-access-memory-overlay": "^3.0.0",
|
|
60
60
|
"standard": "^17.0.0",
|