blind-peer 3.8.1 → 3.9.0
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 +22 -5
- 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
|
|
|
@@ -218,13 +224,14 @@ class BlindPeer extends ReadyResource {
|
|
|
218
224
|
wakeupGcTickTime = null,
|
|
219
225
|
replicationLagThreshold = 100,
|
|
220
226
|
topK = {},
|
|
221
|
-
adminRouter = null
|
|
227
|
+
adminRouter = null,
|
|
228
|
+
activeCorestore = false
|
|
222
229
|
} = {}
|
|
223
230
|
) {
|
|
224
231
|
super()
|
|
225
232
|
|
|
226
233
|
this.rocks = typeof rocks === 'string' ? new RocksDB(rocks) : rocks
|
|
227
|
-
this.store = store || new Corestore(this.rocks, { active:
|
|
234
|
+
this.store = store || new Corestore(this.rocks, { active: activeCorestore })
|
|
228
235
|
this.swarm = swarm || null
|
|
229
236
|
const ipBanNs = this.store.namespace('ip-ban-lists')
|
|
230
237
|
this.ipBanLists = ipBanListKeys.map((key) => new IpBanList(ipBanNs, { key }))
|
|
@@ -435,7 +442,7 @@ class BlindPeer extends ReadyResource {
|
|
|
435
442
|
|
|
436
443
|
try {
|
|
437
444
|
const tracker = this.activeReplication.get(id)
|
|
438
|
-
|
|
445
|
+
await tracker.refresh()
|
|
439
446
|
const coreBytesCleared = tracker.gc()
|
|
440
447
|
bytesCleared += coreBytesCleared
|
|
441
448
|
} finally {
|
|
@@ -572,7 +579,7 @@ class BlindPeer extends ReadyResource {
|
|
|
572
579
|
await core.ready()
|
|
573
580
|
|
|
574
581
|
const tracker = this.activeReplication.get(b4a.toString(core.discoveryKey, 'hex'))
|
|
575
|
-
if (tracker
|
|
582
|
+
if (tracker) await tracker.refresh()
|
|
576
583
|
|
|
577
584
|
if (record.announce) {
|
|
578
585
|
await this._announceCore(core.key)
|
|
@@ -626,6 +633,7 @@ class BlindPeer extends ReadyResource {
|
|
|
626
633
|
let activeSession = null
|
|
627
634
|
|
|
628
635
|
core.on('append', () => {
|
|
636
|
+
if (this.closing) return
|
|
629
637
|
const replicationLag = core.length - core.contiguousLength
|
|
630
638
|
if (!activeSession.isClient && replicationLag > this.replicationLagThreshold) {
|
|
631
639
|
activeSession.refresh({ server: true, client: true })
|
|
@@ -635,6 +643,7 @@ class BlindPeer extends ReadyResource {
|
|
|
635
643
|
this.emit('core-append', core)
|
|
636
644
|
})
|
|
637
645
|
core.on('download', () => {
|
|
646
|
+
if (this.closing) return
|
|
638
647
|
const replicationLag = core.length - core.contiguousLength
|
|
639
648
|
if (replicationLag === 0) {
|
|
640
649
|
if (activeSession.isClient) {
|
|
@@ -1057,6 +1066,14 @@ class BlindPeer extends ReadyResource {
|
|
|
1057
1066
|
this.set(self.rocks.stats.writeBatches)
|
|
1058
1067
|
}
|
|
1059
1068
|
})
|
|
1069
|
+
|
|
1070
|
+
new promClient.Gauge({
|
|
1071
|
+
name: 'blind_peer_corestore_active',
|
|
1072
|
+
help: 'Whether the corestore is active (1) or passive (0)',
|
|
1073
|
+
collect() {
|
|
1074
|
+
this.set(self.store.active ? 1 : 0)
|
|
1075
|
+
}
|
|
1076
|
+
})
|
|
1060
1077
|
}
|
|
1061
1078
|
}
|
|
1062
1079
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blind-peer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
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.
|
|
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",
|