dht-rpc 6.20.2 → 6.22.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/README.md +3 -1
- package/index.js +10 -1
- package/lib/io.js +14 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,7 +123,9 @@ Options include:
|
|
|
123
123
|
// Optionally pass a UDX instance on which sockets will be created.
|
|
124
124
|
udx,
|
|
125
125
|
// dht-rpc will automatically detect if you are firewalled. If you know that you are not set this to false
|
|
126
|
-
firewalled: true
|
|
126
|
+
firewalled: true,
|
|
127
|
+
// dht-rpc will hint when a node is down if a request times out. Setting to false disables sending hints
|
|
128
|
+
sendDownHints: true
|
|
127
129
|
}
|
|
128
130
|
```
|
|
129
131
|
|
package/index.js
CHANGED
|
@@ -22,6 +22,11 @@ const REFRESH_TICKS = 60 // refresh every ~5min when idle
|
|
|
22
22
|
const RECENT_NODE = 12 // we've heard from a node less than 1min ago
|
|
23
23
|
const OLD_NODE = 360 // if an node has been around more than 30 min we consider it old
|
|
24
24
|
|
|
25
|
+
const DEFAULTS = {
|
|
26
|
+
concurrency: 10,
|
|
27
|
+
maxWindow: IO.DEFAULT_MAX_WINDOW
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
class DHT extends EventEmitter {
|
|
26
31
|
constructor(opts = {}) {
|
|
27
32
|
super()
|
|
@@ -37,7 +42,7 @@ class DHT extends EventEmitter {
|
|
|
37
42
|
ontimeout: this._ontimeout.bind(this)
|
|
38
43
|
})
|
|
39
44
|
|
|
40
|
-
this.concurrency = opts.concurrency ||
|
|
45
|
+
this.concurrency = opts.concurrency || DEFAULTS.concurrency
|
|
41
46
|
this.bootstrapped = false
|
|
42
47
|
this.ephemeral = true
|
|
43
48
|
this.firewalled = this.io.firewalled
|
|
@@ -72,6 +77,7 @@ class DHT extends EventEmitter {
|
|
|
72
77
|
this._nonePersistentSamples = []
|
|
73
78
|
this._bootstrapping = this._bootstrap()
|
|
74
79
|
this._bootstrapping.catch(noop)
|
|
80
|
+
this._sendDownHints = opts.sendDownHints !== false
|
|
75
81
|
|
|
76
82
|
this.table.on('row', this._onrow)
|
|
77
83
|
|
|
@@ -84,6 +90,8 @@ class DHT extends EventEmitter {
|
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
static DEFAULTS = DEFAULTS
|
|
94
|
+
|
|
87
95
|
static bootstrapper(port, host, opts) {
|
|
88
96
|
if (!port) throw new Error('Port is required')
|
|
89
97
|
if (!host) throw new Error('Host is required')
|
|
@@ -348,6 +356,7 @@ class DHT extends EventEmitter {
|
|
|
348
356
|
}
|
|
349
357
|
|
|
350
358
|
_request(to, force, internal, command, target, value, session, onresponse, onerror) {
|
|
359
|
+
if (!this._sendDownHints && command === DOWN_HINT) return null
|
|
351
360
|
const req = this.io.createRequest(to, null, internal, command, target, value, session)
|
|
352
361
|
if (req === null) return null
|
|
353
362
|
|
package/lib/io.js
CHANGED
|
@@ -9,13 +9,14 @@ const VERSION = 0b11
|
|
|
9
9
|
const RESPONSE_ID = (0b0001 << 4) | VERSION
|
|
10
10
|
const REQUEST_ID = (0b0000 << 4) | VERSION
|
|
11
11
|
const EMPTY_ARRAY = []
|
|
12
|
+
const MAX_WINDOW = 80
|
|
12
13
|
|
|
13
14
|
module.exports = class IO {
|
|
14
15
|
constructor(
|
|
15
16
|
table,
|
|
16
17
|
udx,
|
|
17
18
|
{
|
|
18
|
-
maxWindow =
|
|
19
|
+
maxWindow = MAX_WINDOW,
|
|
19
20
|
port = 0,
|
|
20
21
|
host = '0.0.0.0',
|
|
21
22
|
anyPort = true,
|
|
@@ -37,7 +38,13 @@ module.exports = class IO {
|
|
|
37
38
|
this.suspended = false
|
|
38
39
|
|
|
39
40
|
this.stats = {
|
|
40
|
-
requests: {
|
|
41
|
+
requests: {
|
|
42
|
+
active: 0,
|
|
43
|
+
total: 0,
|
|
44
|
+
responses: 0,
|
|
45
|
+
timeouts: 0,
|
|
46
|
+
retries: 0
|
|
47
|
+
},
|
|
41
48
|
commands: [
|
|
42
49
|
{ tx: 0, rx: 0 }, // tx = transmitted, rx = received
|
|
43
50
|
{ tx: 0, rx: 0 },
|
|
@@ -67,6 +74,8 @@ module.exports = class IO {
|
|
|
67
74
|
this._boundClientPort = 0
|
|
68
75
|
}
|
|
69
76
|
|
|
77
|
+
static DEFAULT_MAX_WINDOW = MAX_WINDOW
|
|
78
|
+
|
|
70
79
|
onmessage(socket, buffer, { host, port }) {
|
|
71
80
|
if (buffer.byteLength < 2 || !(port > 0 && port < 65536) || this.suspended === true) return
|
|
72
81
|
|
|
@@ -119,6 +128,7 @@ module.exports = class IO {
|
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
this.stats.requests.active--
|
|
131
|
+
this.stats.requests.responses++
|
|
122
132
|
|
|
123
133
|
this.onresponse(res, external)
|
|
124
134
|
req.onresponse(res, req)
|
|
@@ -575,9 +585,11 @@ function oncycle(req) {
|
|
|
575
585
|
req._timeout = null
|
|
576
586
|
req.oncycle(req)
|
|
577
587
|
if (req.sent >= req.retries) {
|
|
588
|
+
req._io.stats.requests.timeouts++
|
|
578
589
|
req.destroy(REQUEST_TIMEOUT())
|
|
579
590
|
req._io.ontimeout(req)
|
|
580
591
|
} else {
|
|
592
|
+
req._io.stats.requests.retries++
|
|
581
593
|
req.send()
|
|
582
594
|
}
|
|
583
595
|
}
|