hypercore 11.23.0 → 11.23.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 CHANGED
@@ -495,6 +495,12 @@ module.exports = class Bitfield {
495
495
  }
496
496
 
497
497
  *want(start, length) {
498
+ if (start & 31) {
499
+ const d = start & 31
500
+ start -= d
501
+ length += d
502
+ }
503
+
498
504
  let j = start & (BITS_PER_SEGMENT - 1)
499
505
  let i = (start - j) / BITS_PER_SEGMENT
500
506
 
package/lib/wants.js CHANGED
@@ -1,4 +1,5 @@
1
- const BATCH_UINTS = 128
1
+ const COMPAT = true // should be flipped once this is widely deployed
2
+ const BATCH_UINTS = COMPAT ? 65536 : 128
2
3
  const BATCH_BYTES = BATCH_UINTS * 4
3
4
  const BATCH = BATCH_BYTES * 8 // in bits
4
5
  const MAX_REMOTE_BATCHES = 4
@@ -25,6 +26,14 @@ class LocalWants {
25
26
  if (this.destroyed) return null
26
27
  if (this.any === null) this.any = []
27
28
 
29
+ if (COMPAT) {
30
+ let r = start & (BATCH - 1)
31
+ start -= r
32
+ length += r
33
+ r = length & (BATCH - 1)
34
+ if (r) length = length - r + BATCH
35
+ }
36
+
28
37
  for (let i = 0; i < this.any.length; i++) {
29
38
  const w = this.any[i]
30
39
  if (w.start === start && w.length === length) {
@@ -38,7 +47,7 @@ class LocalWants {
38
47
  this.any.push(w)
39
48
  handle.addWant(w)
40
49
 
41
- return { start, length, any: true }
50
+ return { start, length, any: !COMPAT }
42
51
  }
43
52
 
44
53
  removeAnyRange(start, length, handle) {
@@ -54,7 +63,7 @@ class LocalWants {
54
63
 
55
64
  const head = this.any.pop()
56
65
  if (head !== w) this.any[i] = head
57
- return { start, length, any: true }
66
+ return { start, length, any: !COMPAT }
58
67
  }
59
68
 
60
69
  return null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.23.0",
3
+ "version": "11.23.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {