hypercore 10.26.0 → 10.26.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.
Files changed (3) hide show
  1. package/index.js +4 -3
  2. package/lib/core.js +3 -3
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -167,15 +167,16 @@ module.exports = class Hypercore extends EventEmitter {
167
167
  if (!noiseStream.userData) {
168
168
  const protocol = Protomux.from(noiseStream)
169
169
 
170
- if (opts.ondiscoverykey) {
171
- protocol.pair({ protocol: 'hypercore/alpha' }, opts.ondiscoverykey)
172
- }
173
170
  if (opts.keepAlive !== false) {
174
171
  noiseStream.setKeepAlive(5000)
175
172
  }
176
173
  noiseStream.userData = protocol
177
174
  }
178
175
 
176
+ if (opts.ondiscoverykey) {
177
+ noiseStream.userData.pair({ protocol: 'hypercore/alpha' }, opts.ondiscoverykey)
178
+ }
179
+
179
180
  return outerStream
180
181
  }
181
182
 
package/lib/core.js CHANGED
@@ -225,10 +225,10 @@ module.exports = class Core {
225
225
 
226
226
  while (pos < length) {
227
227
  const segmentStart = maximumSegmentStart(pos, src.bitfield, this.bitfield)
228
- const segmentEnd = minimumSegmentEnd(segmentStart, src.bitfield, this.bitfield)
229
-
230
228
  if (segmentStart >= length || segmentStart < 0) break
231
229
 
230
+ const segmentEnd = Math.min(length, minimumSegmentEnd(segmentStart, src.bitfield, this.bitfield))
231
+
232
232
  const segment = []
233
233
 
234
234
  pos = segmentStart
@@ -240,7 +240,7 @@ module.exports = class Core {
240
240
  const [offset] = await src.tree.byteRange(2 * segmentStart)
241
241
  await this.blocks.putBatch(segmentStart, segment, offset)
242
242
 
243
- this.bitfield.setRange(segmentStart, segmentEnd, true)
243
+ this.bitfield.setRange(segmentStart, segmentEnd - segmentStart, true)
244
244
 
245
245
  pos = segmentEnd + 1
246
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.26.0",
3
+ "version": "10.26.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {