hypercore 10.36.0 → 10.36.1
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 +8 -0
- package/index.js +4 -0
- package/lib/core.js +19 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -478,3 +478,11 @@ Emitted when a new connection has been established with a peer.
|
|
|
478
478
|
#### `core.on('peer-remove')`
|
|
479
479
|
|
|
480
480
|
Emitted when a peer's connection has been closed.
|
|
481
|
+
|
|
482
|
+
#### `core.on('upload', index, byteLength, peer)`
|
|
483
|
+
|
|
484
|
+
Emitted when a block is uploaded to a peer.
|
|
485
|
+
|
|
486
|
+
#### `core.on('download', index, byteLength, peer)`
|
|
487
|
+
|
|
488
|
+
Emitted when a block is downloaded from a peer.
|
package/index.js
CHANGED
|
@@ -335,6 +335,10 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
335
335
|
ensureEncryption(this, opts)
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
if (opts.manifest && !this.core.header.manifest) {
|
|
339
|
+
await this.core.setManifest(opts.manifest)
|
|
340
|
+
}
|
|
341
|
+
|
|
338
342
|
this.writable = this._isWritable()
|
|
339
343
|
|
|
340
344
|
if (opts.valueEncoding) {
|
package/lib/core.js
CHANGED
|
@@ -194,7 +194,21 @@ module.exports = class Core {
|
|
|
194
194
|
return new this(header, compat, crypto, oplog, bigHeader, tree, blocks, bitfield, verifier, legacy, opts.onupdate || noop, opts.onconflict || noop)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
setManifest (manifest
|
|
197
|
+
async setManifest (manifest) {
|
|
198
|
+
await this._mutex.lock()
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
if (manifest && this.header.manifest === null) {
|
|
202
|
+
if (!Verifier.isValidManifest(this.header.key, manifest)) throw INVALID_CHECKSUM('Manifest hash does not match')
|
|
203
|
+
this._setManifest(Verifier.createManifest(manifest), null)
|
|
204
|
+
await this._flushOplog()
|
|
205
|
+
}
|
|
206
|
+
} finally {
|
|
207
|
+
this._mutex.unlock()
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
_setManifest (manifest, keyPair) {
|
|
198
212
|
if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = Verifier.defaultSignerManifest(this.header.key)
|
|
199
213
|
if (!manifest) return
|
|
200
214
|
|
|
@@ -430,7 +444,7 @@ module.exports = class Core {
|
|
|
430
444
|
await this._mutex.lock()
|
|
431
445
|
|
|
432
446
|
// upsert compat manifest
|
|
433
|
-
if (this.verifier === null && keyPair) this.
|
|
447
|
+
if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
|
|
434
448
|
|
|
435
449
|
try {
|
|
436
450
|
const batch = await this.tree.truncate(length, fork)
|
|
@@ -549,7 +563,7 @@ module.exports = class Core {
|
|
|
549
563
|
|
|
550
564
|
try {
|
|
551
565
|
// upsert compat manifest
|
|
552
|
-
if (this.verifier === null && keyPair) this.
|
|
566
|
+
if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
|
|
553
567
|
|
|
554
568
|
if (this.tree.fork !== batch.fork) return null
|
|
555
569
|
|
|
@@ -623,7 +637,7 @@ module.exports = class Core {
|
|
|
623
637
|
|
|
624
638
|
try {
|
|
625
639
|
// upsert compat manifest
|
|
626
|
-
if (this.verifier === null && keyPair) this.
|
|
640
|
+
if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
|
|
627
641
|
|
|
628
642
|
if (preappend) await preappend(values)
|
|
629
643
|
|
|
@@ -790,7 +804,7 @@ module.exports = class Core {
|
|
|
790
804
|
// if we got a manifest AND its strictly a non compat one, lets store it
|
|
791
805
|
if (manifest && this.header.manifest === null) {
|
|
792
806
|
if (!Verifier.isValidManifest(this.header.key, manifest)) throw INVALID_CHECKSUM('Manifest hash does not match')
|
|
793
|
-
this.
|
|
807
|
+
this._setManifest(manifest, null)
|
|
794
808
|
}
|
|
795
809
|
|
|
796
810
|
batch.commit()
|