hypercore 11.28.1 → 11.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/index.js +18 -2
- package/lib/messages.js +4 -7
- package/lib/replicator.js +1 -0
- package/lib/session-state.js +17 -7
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -34,7 +34,8 @@ const {
|
|
|
34
34
|
SESSION_MOVED,
|
|
35
35
|
SESSION_NOT_WRITABLE,
|
|
36
36
|
SNAPSHOT_NOT_AVAILABLE,
|
|
37
|
-
DECODING_ERROR
|
|
37
|
+
DECODING_ERROR,
|
|
38
|
+
REQUEST_CANCELLED
|
|
38
39
|
} = require('hypercore-errors')
|
|
39
40
|
|
|
40
41
|
// Hypercore actually does not have any notion of max/min block sizes
|
|
@@ -192,7 +193,12 @@ class Hypercore extends EventEmitter {
|
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
static clearRequests(session, err) {
|
|
195
|
-
|
|
196
|
+
Replicator.clearRequests(session, err)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static destroyRequests(session, err) {
|
|
200
|
+
Replicator.clearRequests(session, err)
|
|
201
|
+
session.push(null) // mark as dead
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
static async treeHashFromStorage(session, length = session.length) {
|
|
@@ -736,6 +742,8 @@ class Hypercore extends EventEmitter {
|
|
|
736
742
|
|
|
737
743
|
if (!upgraded && remoteWait) {
|
|
738
744
|
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
745
|
+
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()
|
|
746
|
+
|
|
739
747
|
const req = this.core.replicator.addUpgrade(activeRequests)
|
|
740
748
|
|
|
741
749
|
try {
|
|
@@ -755,6 +763,7 @@ class Hypercore extends EventEmitter {
|
|
|
755
763
|
if (!isValidIndex(bytes)) throw ASSERTION('seek is invalid', this.discoveryKey)
|
|
756
764
|
|
|
757
765
|
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
766
|
+
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()
|
|
758
767
|
|
|
759
768
|
if (this.encryption && !this.core.manifest) {
|
|
760
769
|
const req = this.replicator.addUpgrade(activeRequests)
|
|
@@ -777,6 +786,7 @@ class Hypercore extends EventEmitter {
|
|
|
777
786
|
|
|
778
787
|
if (!this._shouldWait(opts, this.wait)) return null
|
|
779
788
|
|
|
789
|
+
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()
|
|
780
790
|
const req = this.core.replicator.addSeek(activeRequests, s)
|
|
781
791
|
|
|
782
792
|
const timeout = opts && opts.timeout !== undefined ? opts.timeout : this.timeout
|
|
@@ -916,6 +926,7 @@ class Hypercore extends EventEmitter {
|
|
|
916
926
|
if (this.onwait) this.onwait(index, this)
|
|
917
927
|
|
|
918
928
|
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
|
|
929
|
+
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()
|
|
919
930
|
|
|
920
931
|
const force = opts ? opts.force === true : false
|
|
921
932
|
const req = this.core.replicator.addBlock(activeRequests, index, force)
|
|
@@ -1393,3 +1404,8 @@ function createDiscoveryKeyHandler(fn) {
|
|
|
1393
1404
|
return fn(id)
|
|
1394
1405
|
}
|
|
1395
1406
|
}
|
|
1407
|
+
|
|
1408
|
+
function isRequestsDestroyed(activeRequests) {
|
|
1409
|
+
// TODO: move this to an object instead so we can store a property in next major
|
|
1410
|
+
return activeRequests.length > 0 && activeRequests[0] === null
|
|
1411
|
+
}
|
package/lib/messages.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
const c = require('compact-encoding')
|
|
2
|
-
const b4a = require('b4a')
|
|
3
2
|
const { DEFAULT_NAMESPACE } = require('./caps')
|
|
4
3
|
const { INVALID_OPLOG_VERSION } = require('hypercore-errors')
|
|
5
4
|
const unslab = require('unslab')
|
|
6
5
|
|
|
7
|
-
const EMPTY = b4a.alloc(0)
|
|
8
|
-
|
|
9
6
|
const MANIFEST_PATCH = 0b00000001
|
|
10
7
|
const MANIFEST_PROLOGUE = 0b00000010
|
|
11
8
|
const MANIFEST_LINKED = 0b00000100
|
|
@@ -403,14 +400,14 @@ const dataUpgrade = {
|
|
|
403
400
|
c.uint.preencode(state, u.length)
|
|
404
401
|
nodeArray.preencode(state, u.nodes)
|
|
405
402
|
nodeArray.preencode(state, u.additionalNodes)
|
|
406
|
-
c.
|
|
403
|
+
c.optionalBuffer.preencode(state, u.signature)
|
|
407
404
|
},
|
|
408
405
|
encode(state, u) {
|
|
409
406
|
c.uint.encode(state, u.start)
|
|
410
407
|
c.uint.encode(state, u.length)
|
|
411
408
|
nodeArray.encode(state, u.nodes)
|
|
412
409
|
nodeArray.encode(state, u.additionalNodes)
|
|
413
|
-
c.
|
|
410
|
+
c.optionalBuffer.encode(state, u.signature)
|
|
414
411
|
},
|
|
415
412
|
decode(state) {
|
|
416
413
|
return {
|
|
@@ -418,7 +415,7 @@ const dataUpgrade = {
|
|
|
418
415
|
length: c.uint.decode(state),
|
|
419
416
|
nodes: nodeArray.decode(state),
|
|
420
417
|
additionalNodes: nodeArray.decode(state),
|
|
421
|
-
signature: c.
|
|
418
|
+
signature: c.optionalBuffer.decode(state)
|
|
422
419
|
}
|
|
423
420
|
}
|
|
424
421
|
}
|
|
@@ -454,7 +451,7 @@ const dataBlock = {
|
|
|
454
451
|
decode(state) {
|
|
455
452
|
return {
|
|
456
453
|
index: c.uint.decode(state),
|
|
457
|
-
value: c.buffer.decode(state)
|
|
454
|
+
value: c.buffer.decode(state),
|
|
458
455
|
nodes: nodeArray.decode(state)
|
|
459
456
|
}
|
|
460
457
|
}
|
package/lib/replicator.js
CHANGED
package/lib/session-state.js
CHANGED
|
@@ -408,8 +408,12 @@ class SessionState {
|
|
|
408
408
|
const batch = this.createTreeBatch()
|
|
409
409
|
await MerkleTree.truncate(this, length, batch, fork)
|
|
410
410
|
|
|
411
|
-
if (
|
|
412
|
-
|
|
411
|
+
if (signature) {
|
|
412
|
+
batch.signature = signature
|
|
413
|
+
this.core._verifyBatchUpgrade(batch)
|
|
414
|
+
} else if (keyPair) {
|
|
415
|
+
batch.signature = this.core.verifier.sign(batch, keyPair)
|
|
416
|
+
}
|
|
413
417
|
|
|
414
418
|
const tx = this.createWriteBatch()
|
|
415
419
|
|
|
@@ -646,8 +650,12 @@ class SessionState {
|
|
|
646
650
|
throw INVALID_OPERATION('Append is not consistent with prologue', this.core.discoveryKey)
|
|
647
651
|
}
|
|
648
652
|
|
|
649
|
-
if (
|
|
650
|
-
|
|
653
|
+
if (signature) {
|
|
654
|
+
batch.signature = signature
|
|
655
|
+
this.core._verifyBatchUpgrade(batch)
|
|
656
|
+
} else if (keyPair) {
|
|
657
|
+
batch.signature = this.core.verifier.sign(batch, keyPair)
|
|
658
|
+
}
|
|
651
659
|
|
|
652
660
|
batch.commit(tx)
|
|
653
661
|
|
|
@@ -873,9 +881,11 @@ class SessionState {
|
|
|
873
881
|
|
|
874
882
|
rx.tryFlush()
|
|
875
883
|
|
|
876
|
-
const blocks = await Promise.all(
|
|
877
|
-
|
|
878
|
-
|
|
884
|
+
const [blocks, nodes, roots] = await Promise.all([
|
|
885
|
+
Promise.all(blockPromises),
|
|
886
|
+
Promise.all(treePromises),
|
|
887
|
+
Promise.all(rootPromises)
|
|
888
|
+
])
|
|
879
889
|
|
|
880
890
|
if (this.core.destroyed) throw new Error('Core destroyed')
|
|
881
891
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.30.0",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"b4a": "^1.1.0",
|
|
49
49
|
"bare-events": "^2.2.0",
|
|
50
50
|
"big-sparse-array": "^1.0.3",
|
|
51
|
-
"compact-encoding": "^
|
|
51
|
+
"compact-encoding": "^3.0.0",
|
|
52
52
|
"fast-fifo": "^1.3.0",
|
|
53
53
|
"flat-tree": "^1.9.0",
|
|
54
54
|
"hypercore-crypto": "^3.2.1",
|