blind-peer 3.8.0 → 3.8.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 (2) hide show
  1. package/index.js +14 -4
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -55,6 +55,8 @@ class CoreTracker {
55
55
  }
56
56
 
57
57
  _onupdate() {
58
+ if (this.blindPeer.closing) return
59
+
58
60
  this.updated = true
59
61
  if (!this.record) return
60
62
 
@@ -65,6 +67,8 @@ class CoreTracker {
65
67
  }
66
68
 
67
69
  _onactive() {
70
+ if (this.blindPeer.closing) return
71
+
68
72
  this.activated = true
69
73
 
70
74
  if (this.record) {
@@ -94,6 +98,7 @@ class CoreTracker {
94
98
  }
95
99
 
96
100
  async refresh() {
101
+ if (this.destroyed || this.record) return
97
102
  await this.core.ready()
98
103
  if (this.destroyed) return
99
104
 
@@ -104,7 +109,7 @@ class CoreTracker {
104
109
  if (this.destroyed || this.record || !record) return
105
110
 
106
111
  this.record = record
107
- this.core.download({ start: this.record.blocksCleared, end: -1 })
112
+ this.downloadRange = this.core.download({ start: this.record.blocksCleared, end: -1 })
108
113
 
109
114
  if (this.updated) this._onupdate()
110
115
  if (this.activated) this._onactive()
@@ -140,6 +145,7 @@ class CoreTracker {
140
145
  destroy() {
141
146
  if (this.destroyed) return
142
147
  this.destroyed = true
148
+ this.downloadRange.destroy()
143
149
  }
144
150
  }
145
151
 
@@ -213,6 +219,7 @@ class BlindPeer extends ReadyResource {
213
219
  ipBanListKeys = [],
214
220
  banTimeout = 16_000,
215
221
  port,
222
+ bootstrap = null,
216
223
  announcingInterval = 100,
217
224
  wakeupGcTickTime = null,
218
225
  replicationLagThreshold = 100,
@@ -230,6 +237,7 @@ class BlindPeer extends ReadyResource {
230
237
  this.banTimeout = banTimeout
231
238
 
232
239
  this._port = port || 0
240
+ this.bootstrap = bootstrap
233
241
  this.announcingInterval = announcingInterval
234
242
  this.trustedPubKeys = new Set()
235
243
  for (const k of trustedPubKeys || []) this.addTrustedPubKey(k)
@@ -341,7 +349,7 @@ class BlindPeer extends ReadyResource {
341
349
  this.store.watch(this._oncoreopen.bind(this))
342
350
 
343
351
  if (this.swarm === null) {
344
- const swarmOpts = { keyPair: this.db.swarmingKeyPair }
352
+ const swarmOpts = { keyPair: this.db.swarmingKeyPair, bootstrap: this.bootstrap }
345
353
  if (this._port) {
346
354
  swarmOpts.port = typeof this._port === 'number' ? [this._port, this._port + 64] : this._port
347
355
  }
@@ -433,7 +441,7 @@ class BlindPeer extends ReadyResource {
433
441
 
434
442
  try {
435
443
  const tracker = this.activeReplication.get(id)
436
- if (!tracker.record) await tracker.refresh()
444
+ await tracker.refresh()
437
445
  const coreBytesCleared = tracker.gc()
438
446
  bytesCleared += coreBytesCleared
439
447
  } finally {
@@ -570,7 +578,7 @@ class BlindPeer extends ReadyResource {
570
578
  await core.ready()
571
579
 
572
580
  const tracker = this.activeReplication.get(b4a.toString(core.discoveryKey, 'hex'))
573
- if (tracker && !tracker.record) await tracker.refresh()
581
+ if (tracker) await tracker.refresh()
574
582
 
575
583
  if (record.announce) {
576
584
  await this._announceCore(core.key)
@@ -624,6 +632,7 @@ class BlindPeer extends ReadyResource {
624
632
  let activeSession = null
625
633
 
626
634
  core.on('append', () => {
635
+ if (this.closing) return
627
636
  const replicationLag = core.length - core.contiguousLength
628
637
  if (!activeSession.isClient && replicationLag > this.replicationLagThreshold) {
629
638
  activeSession.refresh({ server: true, client: true })
@@ -633,6 +642,7 @@ class BlindPeer extends ReadyResource {
633
642
  this.emit('core-append', core)
634
643
  })
635
644
  core.on('download', () => {
645
+ if (this.closing) return
636
646
  const replicationLag = core.length - core.contiguousLength
637
647
  if (replicationLag === 0) {
638
648
  if (activeSession.isClient) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blind-peer",
3
- "version": "3.8.0",
3
+ "version": "3.8.2",
4
4
  "description": "Blind peers help keep hypercores available",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -34,7 +34,7 @@
34
34
  "bare-process": "^4.2.2",
35
35
  "bare-prom-client": "^15.1.3",
36
36
  "blind-peer-router": "^0.2.2",
37
- "blind-peering": "^2.1.0",
37
+ "blind-peering": "^2.1.2",
38
38
  "brittle": "^3.7.0",
39
39
  "debounceify": "^1.1.0",
40
40
  "graceful-goodbye": "^1.3.3",