hypercore 10.0.0-alpha.34 → 10.0.0-alpha.37

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 CHANGED
@@ -124,7 +124,7 @@ module.exports = class Hypercore extends EventEmitter {
124
124
  }
125
125
  if (opts.keepAlive !== false) {
126
126
  noiseStream.setKeepAlive(5000)
127
- noiseStream.setTimeout(7000)
127
+ noiseStream.setTimeout(10000)
128
128
  }
129
129
  noiseStream.userData = protocol
130
130
  }
@@ -329,6 +329,13 @@ module.exports = class Hypercore extends EventEmitter {
329
329
  const noiseStream = protocolStream.noiseStream
330
330
  const protocol = noiseStream.userData
331
331
 
332
+ // If the user wants to, we can make this replication run in a session
333
+ // that way the core wont close "under them" during replication
334
+ if (opts.session) {
335
+ const s = this.session()
336
+ protocolStream.on('close', () => s.close().catch(noop))
337
+ }
338
+
332
339
  if (this.opened) {
333
340
  this.replicator.attachTo(protocol)
334
341
  } else {
@@ -228,6 +228,7 @@ class ReorgBatch extends MerkleTreeBatch {
228
228
 
229
229
  let diff = null
230
230
  const ite = flat.iterator(this.diff.index)
231
+ const startingDiff = this.diff
231
232
 
232
233
  while ((ite.index & 1) !== 0) {
233
234
  const left = n.get(ite.leftChild())
@@ -243,6 +244,7 @@ class ReorgBatch extends MerkleTreeBatch {
243
244
 
244
245
  if ((this.diff.index & 1) === 0) return true
245
246
  if (diff === null) return false
247
+ if (startingDiff !== this.diff) return false
246
248
 
247
249
  return this._updateDiffRoot(diff)
248
250
  }
@@ -255,10 +257,6 @@ class ReorgBatch extends MerkleTreeBatch {
255
257
  const end = Math.min(this.treeLength, spans[1] / 2 + 1)
256
258
  const len = end - start
257
259
 
258
- if (this.diff !== null && len >= this.want.end - this.want.start) {
259
- return false
260
- }
261
-
262
260
  this.ancestors = start
263
261
  this.diff = diff
264
262
 
package/lib/replicator.js CHANGED
@@ -717,7 +717,7 @@ class Peer {
717
717
  }
718
718
 
719
719
  _requestBlock (b) {
720
- if (this.remoteBitfield.get(b.index) === false) return false
720
+ if (this.remoteBitfield.get(b.index) === false || b.fork !== this.remoteFork) return false
721
721
 
722
722
  const req = this._makeRequest(b.fork, b.index >= this.core.tree.length)
723
723
  if (req === null) return false
@@ -1286,14 +1286,14 @@ module.exports = class Replicator {
1286
1286
 
1287
1287
  if (f.batch) {
1288
1288
  await f.batch.update(data)
1289
- } else {
1289
+ } else if (data.upgrade) {
1290
1290
  f.batch = await this.core.tree.reorg(data)
1291
1291
 
1292
1292
  // Remove "older" reorgs in progress as we just verified this one.
1293
1293
  this._clearOldReorgs(f.fork)
1294
1294
  }
1295
1295
 
1296
- if (f.batch.finished) {
1296
+ if (f.batch && f.batch.finished) {
1297
1297
  if (this._addUpgradeMaybe() !== null) {
1298
1298
  await this._applyReorg(f)
1299
1299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.0.0-alpha.34",
3
+ "version": "10.0.0-alpha.37",
4
4
  "description": "Hypercore 10",
5
5
  "main": "index.js",
6
6
  "scripts": {