forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libp2p-nodejs.js
51 lines (41 loc) · 1.23 KB
/
libp2p-nodejs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const TCP = require('libp2p-tcp')
const MulticastDNS = require('libp2p-mdns')
const WS = require('libp2p-websockets')
const Railing = require('libp2p-railing')
const KadDHT = require('libp2p-kad-dht')
const Multiplex = require('libp2p-multiplex')
const SECIO = require('libp2p-secio')
const libp2p = require('libp2p')
class Node extends libp2p {
constructor (peerInfo, peerBook, options) {
options = options || {}
const modules = {
transport: [new TCP(), new WS()],
connection: {
muxer: [Multiplex],
crypto: [SECIO]
},
discovery: []
}
if (options.dht) {
modules.DHT = KadDHT
}
if (options.mdns) {
const mdns = new MulticastDNS(peerInfo, 'ipfs.local')
modules.discovery.push(mdns)
}
if (options.bootstrap) {
const r = new Railing(options.bootstrap)
modules.discovery.push(r)
}
if (options.modules && options.modules.transport) {
options.modules.transport.forEach((t) => modules.transport.push(t))
}
if (options.modules && options.modules.discovery) {
options.modules.discovery.forEach((d) => modules.discovery.push(d))
}
super(modules, peerInfo, peerBook, options)
}
}
module.exports = Node