dht-rpc 6.24.2 → 6.24.3
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 +11 -0
- package/lib/health.js +36 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -140,6 +140,17 @@ class DHT extends EventEmitter {
|
|
|
140
140
|
return this.firewalled ? this.io.clientSocket : this.io.serverSocket
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
get config() {
|
|
144
|
+
return {
|
|
145
|
+
concurrency: this.concurrency,
|
|
146
|
+
maxWindow: this.io.congestion._maxWindow,
|
|
147
|
+
randomPunchInterval: this._randomPunchInterval,
|
|
148
|
+
connectionKeepAlive: this.connectionKeepAlive,
|
|
149
|
+
sendDownHints: this._sendDownHints,
|
|
150
|
+
downHintsRateLimit: this._downHintsRateLimit
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
143
154
|
onmessage(socket, buf, rinfo) {
|
|
144
155
|
if (buf.byteLength > 1) this.io.onmessage(socket, buf, rinfo)
|
|
145
156
|
}
|
package/lib/health.js
CHANGED
|
@@ -15,6 +15,39 @@ module.exports = class NetworkHealth {
|
|
|
15
15
|
this.degraded = false
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
get oldest() {
|
|
19
|
+
return this._window[this._tail]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get newest() {
|
|
23
|
+
return this._window[this._head]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get responses() {
|
|
27
|
+
if (!this.newest) return 0
|
|
28
|
+
return this.newest.responses - this.oldest.responses
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get timeouts() {
|
|
32
|
+
if (!this.newest) return 0
|
|
33
|
+
return this.newest.timeouts - this.oldest.timeouts
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get timeoutsRate() {
|
|
37
|
+
if (this.timeouts === 0) return 0
|
|
38
|
+
return this.timeouts / (this.responses + this.timeouts)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get stats() {
|
|
42
|
+
return {
|
|
43
|
+
online: this.online,
|
|
44
|
+
degraded: this.degraded,
|
|
45
|
+
responses: this.responses,
|
|
46
|
+
timeouts: this.timeouts,
|
|
47
|
+
timeoutsRate: this.timeoutsRate
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
18
51
|
get _tail() {
|
|
19
52
|
return (this._head + 1) % this._maxHealthWindow
|
|
20
53
|
}
|
|
@@ -40,12 +73,9 @@ module.exports = class NetworkHealth {
|
|
|
40
73
|
|
|
41
74
|
if (this.cold) return
|
|
42
75
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const responses = newest.responses - oldest.responses
|
|
47
|
-
const timeouts = newest.timeouts - oldest.timeouts
|
|
48
|
-
const timeoutsRate = timeouts / (responses + timeouts)
|
|
76
|
+
const responses = this.responses
|
|
77
|
+
const timeouts = this.timeouts
|
|
78
|
+
const timeoutsRate = this.timeoutsRate
|
|
49
79
|
|
|
50
80
|
if (responses > 0) {
|
|
51
81
|
this.online = true
|