hypercore 11.15.0 → 11.16.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/lib/bitfield.js +24 -0
- package/lib/replicator.js +1 -1
- package/lib/session-state.js +24 -0
- package/package.json +2 -1
package/lib/bitfield.js
CHANGED
|
@@ -400,6 +400,30 @@ module.exports = class Bitfield {
|
|
|
400
400
|
return this.findLast(false, position)
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
+
hasSet (start, length) {
|
|
404
|
+
const end = start + length
|
|
405
|
+
|
|
406
|
+
let j = start & (BITS_PER_SEGMENT - 1)
|
|
407
|
+
let i = (start - j) / BITS_PER_SEGMENT
|
|
408
|
+
|
|
409
|
+
while (i < this._segments.maxLength) {
|
|
410
|
+
const s = this._segments.get(i)
|
|
411
|
+
|
|
412
|
+
let index = -1
|
|
413
|
+
|
|
414
|
+
if (s) index = s.findFirst(true, j)
|
|
415
|
+
|
|
416
|
+
if (index !== -1) return (i * BITS_PER_SEGMENT + index) < end
|
|
417
|
+
|
|
418
|
+
j = 0
|
|
419
|
+
i++
|
|
420
|
+
|
|
421
|
+
if (i * BITS_PER_SEGMENT >= end) return false
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return false
|
|
425
|
+
}
|
|
426
|
+
|
|
403
427
|
count (start, length, val) {
|
|
404
428
|
let j = start & (BITS_PER_PAGE - 1)
|
|
405
429
|
let i = (start - j) / BITS_PER_PAGE
|
package/lib/replicator.js
CHANGED
|
@@ -1752,8 +1752,8 @@ module.exports = class Replicator {
|
|
|
1752
1752
|
|
|
1753
1753
|
while (session.length > 0) {
|
|
1754
1754
|
const ref = session[session.length - 1]
|
|
1755
|
-
ref.context.detach(ref, err)
|
|
1756
1755
|
updated.add(ref.context.replicator)
|
|
1756
|
+
ref.context.detach(ref, err)
|
|
1757
1757
|
}
|
|
1758
1758
|
|
|
1759
1759
|
for (const replicator of updated) {
|
package/lib/session-state.js
CHANGED
|
@@ -476,6 +476,22 @@ module.exports = class SessionState {
|
|
|
476
476
|
try {
|
|
477
477
|
const tx = this.createWriteBatch()
|
|
478
478
|
|
|
479
|
+
const ite = flat.iterator(start * 2)
|
|
480
|
+
while (!isRootIndex(ite.index, this.roots)) {
|
|
481
|
+
const a = ite.index
|
|
482
|
+
const b = ite.sibling()
|
|
483
|
+
ite.parent()
|
|
484
|
+
|
|
485
|
+
const [left, right] = flat.spans(b)
|
|
486
|
+
const s = left / 2
|
|
487
|
+
const e = (right / 2) + 1
|
|
488
|
+
const has = (s <= start && e <= end) ? false : this.core.bitfield.hasSet(s, e - s)
|
|
489
|
+
if (has) break
|
|
490
|
+
|
|
491
|
+
tx.deleteTreeNode(a)
|
|
492
|
+
tx.deleteTreeNode(b)
|
|
493
|
+
}
|
|
494
|
+
|
|
479
495
|
if (this.isDefault()) {
|
|
480
496
|
await storeBitfieldRange(this.storage, tx, start, end, false)
|
|
481
497
|
if (start < this.core.header.hints.contiguousLength) {
|
|
@@ -1134,3 +1150,11 @@ function getCoreHead (storage) {
|
|
|
1134
1150
|
b.tryFlush()
|
|
1135
1151
|
return p
|
|
1136
1152
|
}
|
|
1153
|
+
|
|
1154
|
+
function isRootIndex (index, roots) {
|
|
1155
|
+
for (const node of roots) {
|
|
1156
|
+
if (node.index === index) return true
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
return false
|
|
1160
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.16.1",
|
|
4
4
|
"description": "Hypercore is a secure, distributed append-only log",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"hyperswarm": "^4.3.6",
|
|
71
71
|
"rache": "^1.0.0",
|
|
72
72
|
"range-parser": "^1.2.1",
|
|
73
|
+
"resolve-reject-promise": "^1.1.0",
|
|
73
74
|
"speedometer": "^1.1.0",
|
|
74
75
|
"standard": "^17.0.0",
|
|
75
76
|
"test-tmp": "^1.0.2",
|