hypercore 11.27.2 → 11.27.3

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
@@ -117,6 +117,10 @@ class Hypercore extends EventEmitter {
117
117
  UPDATE_COMPAT(enableCompat)
118
118
  }
119
119
 
120
+ static setRecoveryPeers(peers) {
121
+ Core.setRecoveryPeers(peers)
122
+ }
123
+
120
124
  static key(manifest, { compat, version, namespace } = {}) {
121
125
  if (b4a.isBuffer(manifest)) {
122
126
  manifest = { version, signers: [{ publicKey: manifest, namespace }] }
package/lib/core.js CHANGED
@@ -67,6 +67,10 @@ module.exports = class Core {
67
67
  this.opening.catch(noop)
68
68
  }
69
69
 
70
+ static setRecoveryPeers(peers) {
71
+ SessionState.RECOVERY_PEERS = peers
72
+ }
73
+
70
74
  ready() {
71
75
  return this.opening
72
76
  }
@@ -16,7 +16,7 @@ const Mutex = require('./mutex')
16
16
  const Bitfield = require('./bitfield')
17
17
  const { MerkleTree, MerkleTreeBatch } = require('./merkle-tree')
18
18
 
19
- module.exports = class SessionState {
19
+ class SessionState {
20
20
  constructor(core, parent, storage, treeInfo, name) {
21
21
  this.core = core
22
22
  this.index = this.core.sessionStates.push(this) - 1
@@ -54,6 +54,8 @@ module.exports = class SessionState {
54
54
  this.ref()
55
55
  }
56
56
 
57
+ static RECOVERY_PEERS = null
58
+
57
59
  isSnapshot() {
58
60
  return this.storage.snapshotted
59
61
  }
@@ -574,14 +576,16 @@ module.exports = class SessionState {
574
576
  const replicator = this.core.replicator
575
577
 
576
578
  while (!this.closing) {
577
- if (replicator.peers.length < 1) {
579
+ let peers = getRecoveryPeers(replicator.peers)
580
+
581
+ if (peers.length < 1) {
578
582
  await new Promise((resolve) => setTimeout(resolve, 5000))
579
583
  continue
580
584
  }
581
585
 
582
- await new Promise((resolve) => setTimeout(resolve, 5000))
586
+ await new Promise((resolve) => setTimeout(resolve, 8000))
583
587
 
584
- const peers = replicator.peers
588
+ peers = getRecoveryPeers(replicator.peers)
585
589
 
586
590
  if (peers.length < 1 || this.closing) continue
587
591
  if (peers[0].remoteLength > this.length) continue
@@ -1189,6 +1193,8 @@ module.exports = class SessionState {
1189
1193
  }
1190
1194
  }
1191
1195
 
1196
+ module.exports = SessionState
1197
+
1192
1198
  function noop() {}
1193
1199
 
1194
1200
  function getBitfieldPage(index) {
@@ -1287,3 +1293,20 @@ function isRootIndex(index, roots) {
1287
1293
 
1288
1294
  return false
1289
1295
  }
1296
+
1297
+ function getRecoveryPeers(peers) {
1298
+ if (!SessionState.RECOVERY_PEERS) return peers
1299
+
1300
+ const actual = []
1301
+
1302
+ for (const p of peers) {
1303
+ for (const r of SessionState.RECOVERY_PEERS) {
1304
+ if (b4a.equals(p.remotePublicKey, r)) {
1305
+ actual.push(p)
1306
+ break
1307
+ }
1308
+ }
1309
+ }
1310
+
1311
+ return actual
1312
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.27.2",
3
+ "version": "11.27.3",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {