dht-rpc 5.0.0-rc.7 → 5.0.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/README.md +6 -11
- package/index.js +1 -1
- package/lib/io.js +1 -1
- package/lib/peer.js +12 -34
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
Make RPC calls over a [Kademlia](https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf) based DHT.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
npm install dht-rpc
|
|
6
|
+
npm install dht-rpc
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
## NOTE: v5
|
|
9
|
+
## NOTE: v5
|
|
10
10
|
|
|
11
|
-
Note that
|
|
12
|
-
To see the v4 documentation/code go to https://github.com/mafintosh/dht-rpc/tree/v4
|
|
11
|
+
Note that the latest release is v5. To see the v4 documentation/code go to https://github.com/mafintosh/dht-rpc/tree/v4
|
|
13
12
|
|
|
14
13
|
## Key Features
|
|
15
14
|
|
|
@@ -115,11 +114,6 @@ Options include:
|
|
|
115
114
|
|
|
116
115
|
``` js
|
|
117
116
|
{
|
|
118
|
-
// Whether or not this node is ephemeral or should join the routing table
|
|
119
|
-
ephemeral: false,
|
|
120
|
-
// If you don't explicitly specific the ephemerality, the node will automatically
|
|
121
|
-
// figure it out in adaptive mode, based on your NAT settings, uptime and some other heuristics
|
|
122
|
-
adaptive: true,
|
|
123
117
|
// A list of bootstrap nodes
|
|
124
118
|
bootstrap: [ 'bootstrap-node.com:24242', ... ],
|
|
125
119
|
// Optionally pass in your own UDP socket to use.
|
|
@@ -133,8 +127,9 @@ Options include:
|
|
|
133
127
|
}
|
|
134
128
|
```
|
|
135
129
|
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
Nodes per default use something called adaptive mode to decide whether or not they want to join other nodes' routing table.
|
|
131
|
+
This includes things like node uptime, if the node is firewalled etc. Adaptive mode is conservative, so it might take ~20-30 mins for the node to turn persistent. If you are making a test case with your own bootstrap network you'd usually want to turn this off to make sure your test finishes in a timely maner. You can do this by passing `ephemeral: false` in the constructor.
|
|
132
|
+
For the vast majority of use-cases you should always use adaptive mode to ensure good DHT health, ie the defaults.
|
|
138
133
|
|
|
139
134
|
Your DHT routing id is `hash(publicIp + publicPort)` and will be autoconfigured internally.
|
|
140
135
|
|
package/index.js
CHANGED
|
@@ -55,7 +55,7 @@ class DHT extends EventEmitter {
|
|
|
55
55
|
this._lastHost = null
|
|
56
56
|
this._onrow = (row) => row.on('full', (node) => this._onfullrow(node, row))
|
|
57
57
|
this._nonePersistentSamples = []
|
|
58
|
-
this._bootstrapping = this.bootstrap()
|
|
58
|
+
this._bootstrapping = this.bootstrap().catch(noop)
|
|
59
59
|
|
|
60
60
|
this.table.on('row', this._onrow)
|
|
61
61
|
|
package/lib/io.js
CHANGED
|
@@ -36,7 +36,7 @@ module.exports = class IO {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
onmessage (socket, buffer, rinfo) {
|
|
39
|
-
if (buffer.byteLength < 2) return
|
|
39
|
+
if (buffer.byteLength < 2 || !(rinfo.port > 0 && rinfo.port < 65536)) return
|
|
40
40
|
|
|
41
41
|
const from = { id: null, host: rinfo.address, port: rinfo.port }
|
|
42
42
|
const state = { start: 1, end: buffer.byteLength, buffer }
|
package/lib/peer.js
CHANGED
|
@@ -1,49 +1,27 @@
|
|
|
1
1
|
const sodium = require('sodium-universal')
|
|
2
2
|
const c = require('compact-encoding')
|
|
3
|
-
|
|
4
|
-
const addr = Buffer.alloc(6)
|
|
5
|
-
let i = 0
|
|
3
|
+
const net = require('compact-encoding-net')
|
|
6
4
|
|
|
7
5
|
const ipv4 = {
|
|
8
|
-
|
|
9
|
-
state.end += 6
|
|
10
|
-
},
|
|
11
|
-
encode (state, p) {
|
|
12
|
-
i = 0
|
|
13
|
-
state.buffer[state.start++] = num(p.host)
|
|
14
|
-
state.buffer[state.start++] = num(p.host)
|
|
15
|
-
state.buffer[state.start++] = num(p.host)
|
|
16
|
-
state.buffer[state.start++] = num(p.host)
|
|
17
|
-
state.buffer[state.start++] = p.port
|
|
18
|
-
state.buffer[state.start++] = p.port >>> 8
|
|
19
|
-
},
|
|
6
|
+
...net.ipv4Address,
|
|
20
7
|
decode (state) {
|
|
21
|
-
|
|
8
|
+
const ip = net.ipv4Address.decode(state)
|
|
22
9
|
return {
|
|
23
|
-
id: null, // populated
|
|
24
|
-
host:
|
|
25
|
-
port:
|
|
10
|
+
id: null, // populated by the callee
|
|
11
|
+
host: ip.host,
|
|
12
|
+
port: ip.port
|
|
26
13
|
}
|
|
27
14
|
}
|
|
28
15
|
}
|
|
29
16
|
|
|
30
17
|
module.exports = { id, ipv4, ipv4Array: c.array(ipv4) }
|
|
31
18
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function id (ip, port, out = Buffer.allocUnsafe(32)) {
|
|
40
|
-
i = 0
|
|
41
|
-
addr[0] = num(ip)
|
|
42
|
-
addr[1] = num(ip)
|
|
43
|
-
addr[2] = num(ip)
|
|
44
|
-
addr[3] = num(ip)
|
|
45
|
-
addr[4] = port
|
|
46
|
-
addr[5] = port >>> 8
|
|
19
|
+
function id (host, port, out = Buffer.allocUnsafe(32)) {
|
|
20
|
+
const addr = out.subarray(0, 6)
|
|
21
|
+
ipv4.encode(
|
|
22
|
+
{ start: 0, end: 6, buffer: addr },
|
|
23
|
+
{ host, port }
|
|
24
|
+
)
|
|
47
25
|
sodium.crypto_generichash(out, addr)
|
|
48
26
|
return out
|
|
49
27
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dht-rpc",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Make RPC calls over a Kademlia based DHT",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"bind-easy": "^1.0.0",
|
|
8
8
|
"compact-encoding": "^2.1.0",
|
|
9
|
+
"compact-encoding-net": "^1.0.1",
|
|
9
10
|
"fast-fifo": "^1.0.0",
|
|
10
11
|
"kademlia-routing-table": "^1.0.0",
|
|
11
12
|
"nat-sampler": "^1.0.1",
|