hypercore 11.6.0 → 11.6.2
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 +5 -5
- package/lib/session-state.js +21 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -235,8 +235,8 @@ class Hypercore extends EventEmitter {
|
|
|
235
235
|
return s
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
setEncryptionKey (
|
|
239
|
-
const encryption = this._getEncryptionProvider(
|
|
238
|
+
setEncryptionKey (key, opts) {
|
|
239
|
+
const encryption = this._getEncryptionProvider({ key, block: !!(opts && opts.block) })
|
|
240
240
|
return this.setEncryption(encryption, opts)
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -331,7 +331,8 @@ class Hypercore extends EventEmitter {
|
|
|
331
331
|
const parent = opts.parent || null
|
|
332
332
|
if (parent && parent.encryption) this.encryption = parent.encryption
|
|
333
333
|
|
|
334
|
-
|
|
334
|
+
const e = getEncryptionOption(opts)
|
|
335
|
+
if (!this.encryption) this.encryption = this._getEncryptionProvider(e)
|
|
335
336
|
|
|
336
337
|
this.writable = this._isWritable()
|
|
337
338
|
|
|
@@ -1054,8 +1055,7 @@ class Hypercore extends EventEmitter {
|
|
|
1054
1055
|
return block
|
|
1055
1056
|
}
|
|
1056
1057
|
|
|
1057
|
-
_getEncryptionProvider (
|
|
1058
|
-
const e = getEncryptionOption(opts)
|
|
1058
|
+
_getEncryptionProvider (e) {
|
|
1059
1059
|
if (isEncryptionProvider(e)) return e
|
|
1060
1060
|
if (!e || !e.key) return null
|
|
1061
1061
|
return new DefaultEncryption(e.key, this.key, { block: e.block, compat: this.core.compat })
|
package/lib/session-state.js
CHANGED
|
@@ -287,14 +287,16 @@ module.exports = class SessionState {
|
|
|
287
287
|
|
|
288
288
|
if (dependency) this.storage.setDependencyHead(dependency)
|
|
289
289
|
|
|
290
|
-
const
|
|
290
|
+
const b = bitfield
|
|
291
291
|
|
|
292
|
-
if (
|
|
293
|
-
this.ontruncate(tree,
|
|
294
|
-
if (!
|
|
292
|
+
if (b && b.truncated && b.start < currLength) {
|
|
293
|
+
this.ontruncate(tree, b.start, currLength, true)
|
|
294
|
+
if (!b || b.appends === 0) return
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
|
|
297
|
+
const append = b ? { start: b.start, length: b.appends, drop: false } : null
|
|
298
|
+
|
|
299
|
+
this.onappend(tree, append, true)
|
|
298
300
|
} finally {
|
|
299
301
|
this.mutex.unlock()
|
|
300
302
|
this.core.checkIfIdle()
|
|
@@ -604,35 +606,36 @@ module.exports = class SessionState {
|
|
|
604
606
|
const b = bitfield
|
|
605
607
|
|
|
606
608
|
if (b.drop) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
609
|
+
// truncation must be from end
|
|
610
|
+
if (p && (b.start + b.length !== p.start + p.appends)) {
|
|
611
|
+
throw INVALID_OPERATION('Atomic truncations must be contiguous')
|
|
610
612
|
}
|
|
611
613
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
614
|
+
// actual truncation
|
|
615
|
+
if (p === null || b.start < p.start) {
|
|
616
|
+
this._pendingBitfield = { truncated: true, start: b.start, appends: 0 }
|
|
615
617
|
return
|
|
616
618
|
}
|
|
617
619
|
|
|
618
|
-
|
|
619
|
-
p.
|
|
620
|
+
// just clearing batch data
|
|
621
|
+
p.appends = b.start - p.start
|
|
622
|
+
|
|
623
|
+
// we cleared the current batch
|
|
624
|
+
if (p.appends === 0) this._pendingBitfield = null
|
|
620
625
|
|
|
621
|
-
if (p.length === 0) this._pendingBitfield = null
|
|
622
626
|
return
|
|
623
627
|
}
|
|
624
628
|
|
|
625
629
|
if (p === null) {
|
|
626
|
-
this._pendingBitfield = { truncated:
|
|
630
|
+
this._pendingBitfield = { truncated: false, start: b.start, appends: b.length }
|
|
627
631
|
return
|
|
628
632
|
}
|
|
629
633
|
|
|
630
|
-
|
|
631
|
-
if (b.start !== start + p.length) {
|
|
634
|
+
if (b.start !== p.start + p.appends) {
|
|
632
635
|
throw INVALID_OPERATION('Atomic operations must be contiguous')
|
|
633
636
|
}
|
|
634
637
|
|
|
635
|
-
p.
|
|
638
|
+
p.appends += b.length
|
|
636
639
|
}
|
|
637
640
|
|
|
638
641
|
async catchup (length) {
|