dht-rpc 6.26.1 → 6.26.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.
- package/index.js +1 -1
- package/lib/health.js +8 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -179,7 +179,6 @@ class DHT extends EventEmitter {
|
|
|
179
179
|
this._onwakeup()
|
|
180
180
|
log('Resuming io')
|
|
181
181
|
await this.io.resume()
|
|
182
|
-
this.health.reset()
|
|
183
182
|
log('Done, dht resumed')
|
|
184
183
|
this.io.networkInterfaces.on('change', (interfaces) => this._onnetworkchange(interfaces))
|
|
185
184
|
this.refresh()
|
|
@@ -557,6 +556,7 @@ class DHT extends EventEmitter {
|
|
|
557
556
|
this._stableTicks = MORE_STABLE_TICKS
|
|
558
557
|
this._refreshTicks = 1 // triggers a refresh next tick (allow network time to wake up also)
|
|
559
558
|
this._lastHost = null // clear network cache check
|
|
559
|
+
this.health.reset()
|
|
560
560
|
|
|
561
561
|
if (this.adaptive) {
|
|
562
562
|
// TODO: re-enable this as soon as we find out why this is over triggering in some edge cases
|
package/lib/health.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const MAX_HEALTH_WINDOW = 4
|
|
2
2
|
const TIMEOUTS_THRESHOLD = 0.5
|
|
3
|
+
const IDLE_THRESHOLD = 4
|
|
3
4
|
|
|
4
5
|
module.exports = class NetworkHealth {
|
|
5
6
|
static DEFAULT_MAX_HEALTH_WINDOW = MAX_HEALTH_WINDOW
|
|
@@ -50,14 +51,19 @@ module.exports = class NetworkHealth {
|
|
|
50
51
|
return this.timeouts / (this.responses + this.timeouts)
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
get cold() {
|
|
55
|
+
return this._window.length < this._maxHealthWindow
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
get idle() {
|
|
54
|
-
return this.recentResponses
|
|
59
|
+
return this.recentResponses + this.recentTimeouts < IDLE_THRESHOLD
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
get stats() {
|
|
58
63
|
return {
|
|
59
64
|
online: this.online,
|
|
60
65
|
degraded: this.degraded,
|
|
66
|
+
cold: this.cold,
|
|
61
67
|
idle: this.idle,
|
|
62
68
|
responses: this.responses,
|
|
63
69
|
timeouts: this.timeouts,
|
|
@@ -74,9 +80,6 @@ module.exports = class NetworkHealth {
|
|
|
74
80
|
reset() {
|
|
75
81
|
this._window = []
|
|
76
82
|
this._head = -1
|
|
77
|
-
this.online = true
|
|
78
|
-
this.degraded = false
|
|
79
|
-
this._dht._online()
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
update() {
|
|
@@ -86,7 +89,7 @@ module.exports = class NetworkHealth {
|
|
|
86
89
|
timeouts: this._dht.stats.requests.timeouts
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
if (this.idle) return
|
|
92
|
+
if (this.cold || this.idle) return
|
|
90
93
|
|
|
91
94
|
this.online = this.recentResponses > 0
|
|
92
95
|
this.degraded = this.online && this.timeoutsRate > TIMEOUTS_THRESHOLD
|