|
3 | 3 | const TCP = require('libp2p-tcp')
|
4 | 4 | const MulticastDNS = require('libp2p-mdns')
|
5 | 5 | const WS = require('libp2p-websockets')
|
6 |
| -const Railing = require('libp2p-railing') |
| 6 | +const Bootstrap = require('libp2p-railing') |
7 | 7 | const spdy = require('libp2p-spdy')
|
8 | 8 | const KadDHT = require('libp2p-kad-dht')
|
9 | 9 | const mplex = require('libp2p-mplex')
|
10 | 10 | const secio = require('libp2p-secio')
|
| 11 | +const defaultsDeep = require('@nodeutils/defaults-deep') |
11 | 12 | const libp2p = require('../../..')
|
12 | 13 |
|
13 | 14 | function mapMuxers (list) {
|
@@ -36,44 +37,40 @@ function getMuxers (muxers) {
|
36 | 37 | }
|
37 | 38 |
|
38 | 39 | class Node extends libp2p {
|
39 |
| - constructor (peerInfo, peerBook, options) { |
40 |
| - options = options || {} |
41 |
| - |
42 |
| - const modules = { |
43 |
| - transport: [ |
44 |
| - new TCP(), |
45 |
| - new WS() |
46 |
| - ], |
47 |
| - connection: { |
48 |
| - muxer: getMuxers(options.muxer), |
49 |
| - crypto: [ secio ] |
| 40 | + constructor (_options) { |
| 41 | + const defaults = { |
| 42 | + modules: { |
| 43 | + transport: [ |
| 44 | + TCP, |
| 45 | + WS |
| 46 | + ], |
| 47 | + streamMuxer: getMuxers(_options.muxer), |
| 48 | + connEncryption: [ secio ], |
| 49 | + peerDiscovery: [ |
| 50 | + MulticastDNS, |
| 51 | + Bootstrap |
| 52 | + ], |
| 53 | + dht: KadDHT |
50 | 54 | },
|
51 |
| - discovery: [] |
52 |
| - } |
53 |
| - |
54 |
| - if (options.dht) { |
55 |
| - modules.DHT = KadDHT |
56 |
| - } |
57 |
| - |
58 |
| - if (options.mdns) { |
59 |
| - const mdns = new MulticastDNS(peerInfo, 'ipfs.local') |
60 |
| - modules.discovery.push(mdns) |
61 |
| - } |
62 |
| - |
63 |
| - if (options.bootstrap) { |
64 |
| - const r = new Railing(options.bootstrap) |
65 |
| - modules.discovery.push(r) |
66 |
| - } |
67 |
| - |
68 |
| - if (options.modules && options.modules.transport) { |
69 |
| - options.modules.transport.forEach((t) => modules.transport.push(t)) |
70 |
| - } |
71 |
| - |
72 |
| - if (options.modules && options.modules.discovery) { |
73 |
| - options.modules.discovery.forEach((d) => modules.discovery.push(d)) |
| 55 | + config: { |
| 56 | + peerDiscovery: { |
| 57 | + mdns: { |
| 58 | + interval: 10000, |
| 59 | + enabled: false |
| 60 | + }, |
| 61 | + bootstrap: { |
| 62 | + interval: 10000, |
| 63 | + enabled: false, |
| 64 | + list: _options.bootstrapList |
| 65 | + } |
| 66 | + }, |
| 67 | + dht: { |
| 68 | + kBucketSize: 20 |
| 69 | + } |
| 70 | + } |
74 | 71 | }
|
75 | 72 |
|
76 |
| - super(modules, peerInfo, peerBook, options) |
| 73 | + super(defaultsDeep(_options, defaults)) |
77 | 74 | }
|
78 | 75 | }
|
79 | 76 |
|
|
0 commit comments