dht-rpc 6.25.1 → 6.26.1
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/lib/health.js +28 -27
- package/lib/io.js +1 -1
- package/lib/query.js +0 -1
- package/package.json +1 -1
package/lib/health.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
const MAX_HEALTH_WINDOW =
|
|
2
|
-
const RESPONSES_SANITY = 0
|
|
3
|
-
const TIMEOUTS_SANITY = 0
|
|
1
|
+
const MAX_HEALTH_WINDOW = 4
|
|
4
2
|
const TIMEOUTS_THRESHOLD = 0.5
|
|
5
3
|
|
|
6
4
|
module.exports = class NetworkHealth {
|
|
@@ -19,17 +17,31 @@ module.exports = class NetworkHealth {
|
|
|
19
17
|
return this._window[this._tail]
|
|
20
18
|
}
|
|
21
19
|
|
|
20
|
+
get previous() {
|
|
21
|
+
return this._window[(this._head - 1 + this._maxHealthWindow) % this._maxHealthWindow]
|
|
22
|
+
}
|
|
23
|
+
|
|
22
24
|
get newest() {
|
|
23
25
|
return this._window[this._head]
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
get recentResponses() {
|
|
29
|
+
if (!this.newest || !this.previous) return 0
|
|
30
|
+
return this.newest.responses - this.previous.responses
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get recentTimeouts() {
|
|
34
|
+
if (!this.newest || !this.previous) return 0
|
|
35
|
+
return this.newest.timeouts - this.previous.timeouts
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
get responses() {
|
|
27
|
-
if (!this.newest) return 0
|
|
39
|
+
if (!this.newest || !this.oldest) return 0
|
|
28
40
|
return this.newest.responses - this.oldest.responses
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
get timeouts() {
|
|
32
|
-
if (!this.newest) return 0
|
|
44
|
+
if (!this.newest || !this.oldest) return 0
|
|
33
45
|
return this.newest.timeouts - this.oldest.timeouts
|
|
34
46
|
}
|
|
35
47
|
|
|
@@ -38,13 +50,20 @@ module.exports = class NetworkHealth {
|
|
|
38
50
|
return this.timeouts / (this.responses + this.timeouts)
|
|
39
51
|
}
|
|
40
52
|
|
|
53
|
+
get idle() {
|
|
54
|
+
return this.recentResponses === 0 && this.recentTimeouts === 0
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
get stats() {
|
|
42
58
|
return {
|
|
43
59
|
online: this.online,
|
|
44
60
|
degraded: this.degraded,
|
|
61
|
+
idle: this.idle,
|
|
45
62
|
responses: this.responses,
|
|
46
63
|
timeouts: this.timeouts,
|
|
47
|
-
timeoutsRate: this.timeoutsRate
|
|
64
|
+
timeoutsRate: this.timeoutsRate,
|
|
65
|
+
recentResponses: this.recentResponses,
|
|
66
|
+
recentTimeouts: this.recentTimeouts
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
|
|
@@ -52,10 +71,6 @@ module.exports = class NetworkHealth {
|
|
|
52
71
|
return (this._head + 1) % this._maxHealthWindow
|
|
53
72
|
}
|
|
54
73
|
|
|
55
|
-
get cold() {
|
|
56
|
-
return this._window.length < this._maxHealthWindow
|
|
57
|
-
}
|
|
58
|
-
|
|
59
74
|
reset() {
|
|
60
75
|
this._window = []
|
|
61
76
|
this._head = -1
|
|
@@ -71,24 +86,10 @@ module.exports = class NetworkHealth {
|
|
|
71
86
|
timeouts: this._dht.stats.requests.timeouts
|
|
72
87
|
}
|
|
73
88
|
|
|
74
|
-
if (this.
|
|
75
|
-
|
|
76
|
-
const responses = this.responses
|
|
77
|
-
const timeouts = this.timeouts
|
|
78
|
-
const timeoutsRate = this.timeoutsRate
|
|
79
|
-
|
|
80
|
-
if (responses > 0) {
|
|
81
|
-
this.online = true
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (responses > RESPONSES_SANITY * this._window.length) {
|
|
85
|
-
this.degraded = timeoutsRate > TIMEOUTS_THRESHOLD
|
|
86
|
-
}
|
|
89
|
+
if (this.idle) return
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.degraded = false
|
|
91
|
-
}
|
|
91
|
+
this.online = this.recentResponses > 0
|
|
92
|
+
this.degraded = this.online && this.timeoutsRate > TIMEOUTS_THRESHOLD
|
|
92
93
|
|
|
93
94
|
if (this.online && !this.degraded) this._dht._online()
|
|
94
95
|
else if (this.degraded) this._dht._degraded()
|
package/lib/io.js
CHANGED
|
@@ -595,7 +595,7 @@ function noop() {}
|
|
|
595
595
|
function oncycle(req) {
|
|
596
596
|
req._timeout = null
|
|
597
597
|
req.oncycle(req)
|
|
598
|
-
if (req.sent
|
|
598
|
+
if (req.sent > req.retries) {
|
|
599
599
|
req._io.stats.requests.timeouts++
|
|
600
600
|
req.destroy(REQUEST_TIMEOUT())
|
|
601
601
|
req._io.ontimeout(req)
|
package/lib/query.js
CHANGED
|
@@ -27,7 +27,6 @@ module.exports = class Query extends Readable {
|
|
|
27
27
|
this.map = opts.map || defaultMap
|
|
28
28
|
this.retries =
|
|
29
29
|
opts.retries === 0 ? 0 : opts.retries || (this.internal && command === DOWN_HINT ? 3 : 5)
|
|
30
|
-
this.maxSlow = opts.maxSlow === 0 ? 0 : opts.maxSlow || 5
|
|
31
30
|
this.closestReplies = []
|
|
32
31
|
|
|
33
32
|
this._slow = 0
|