blind-peer 3.0.0 → 3.1.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 +25 -3
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -196,7 +196,8 @@ class BlindPeer extends ReadyResource {
|
|
|
196
196
|
trustedPubKeys,
|
|
197
197
|
port,
|
|
198
198
|
announcingInterval = 100,
|
|
199
|
-
wakeupGcTickTime = null
|
|
199
|
+
wakeupGcTickTime = null,
|
|
200
|
+
replicationLagThreshold = 100
|
|
200
201
|
} = {}
|
|
201
202
|
) {
|
|
202
203
|
super()
|
|
@@ -221,6 +222,7 @@ class BlindPeer extends ReadyResource {
|
|
|
221
222
|
this.enableGc = enableGc
|
|
222
223
|
this.lock = new ScopeLock({ debounce: true })
|
|
223
224
|
this.announcedCores = new Map()
|
|
225
|
+
this.replicationLagThreshold = replicationLagThreshold
|
|
224
226
|
|
|
225
227
|
this.stats = {
|
|
226
228
|
bytesGcd: 0,
|
|
@@ -467,17 +469,37 @@ class BlindPeer extends ReadyResource {
|
|
|
467
469
|
const core = this.store.get({ key })
|
|
468
470
|
this.announcedCores.set(coreId, core)
|
|
469
471
|
|
|
472
|
+
let activeSession = null
|
|
473
|
+
|
|
470
474
|
core.on('append', () => {
|
|
475
|
+
const replicationLag = core.length - core.contiguousLength
|
|
476
|
+
if (!activeSession.isClient && replicationLag > this.replicationLagThreshold) {
|
|
477
|
+
activeSession.refresh({ server: true, client: true })
|
|
478
|
+
this.emit('core-client-mode-changed', core, true)
|
|
479
|
+
}
|
|
480
|
+
|
|
471
481
|
this.emit('core-append', core)
|
|
472
482
|
})
|
|
473
483
|
core.on('download', () => {
|
|
474
|
-
|
|
484
|
+
const replicationLag = core.length - core.contiguousLength
|
|
485
|
+
if (replicationLag === 0) {
|
|
486
|
+
if (activeSession.isClient) {
|
|
487
|
+
activeSession.refresh({ server: true, client: false })
|
|
488
|
+
this.emit('core-client-mode-changed', core, false)
|
|
489
|
+
}
|
|
490
|
+
|
|
475
491
|
this.emit('core-downloaded', core)
|
|
476
492
|
}
|
|
477
493
|
})
|
|
478
494
|
|
|
479
495
|
await core.ready()
|
|
480
|
-
|
|
496
|
+
|
|
497
|
+
const replicationLag = core.length - core.contiguousLength
|
|
498
|
+
if (replicationLag > this.replicationLagThreshold || core.length === 0) {
|
|
499
|
+
activeSession = this.swarm.join(core.discoveryKey, { server: true, client: true })
|
|
500
|
+
} else {
|
|
501
|
+
activeSession = this.swarm.join(core.discoveryKey, { server: true, client: false })
|
|
502
|
+
}
|
|
481
503
|
|
|
482
504
|
// WARNING: we do not yet handle the case where
|
|
483
505
|
// data of an announced core is cleared
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blind-peer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Blind peers help keep hypercores available",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"hypercore": "^11.0.12",
|
|
13
13
|
"hypercore-crypto": "^3.5.0",
|
|
14
14
|
"hypercore-id-encoding": "^1.3.0",
|
|
15
|
-
"hyperdb": "^
|
|
15
|
+
"hyperdb": "^5.0.0",
|
|
16
16
|
"hyperschema": "^1.10.3",
|
|
17
17
|
"hyperswarm": "^4.13.1",
|
|
18
18
|
"protomux-rpc": "^1.7.1",
|