Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 098adac

Browse files
committed
wip
1 parent 4e51a69 commit 098adac

File tree

2 files changed

+67
-47
lines changed

2 files changed

+67
-47
lines changed

src/core/components/libp2p.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,33 @@ module.exports = function libp2p (self) {
1515
return callback(err)
1616
}
1717

18-
const options = {
19-
mdns: get(config, 'Discovery.MDNS.Enabled'),
20-
webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'),
21-
bootstrap: get(config, 'Bootstrap'),
18+
const libp2pOptions = {
19+
peerInfo: self._peerInfo,
20+
peerBook: self._peerInfoBook,
2221
modules: self._libp2pModules,
23-
// EXPERIMENTAL
24-
pubsub: get(self._options, 'EXPERIMENTAL.pubsub', false),
25-
dht: get(self._options, 'EXPERIMENTAL.dht', false),
26-
relay: {
27-
enabled: get(self._options, 'EXPERIMENTAL.relay.enabled',
28-
get(config, 'EXPERIMENTAL.relay.enabled', false)),
29-
hop: {
30-
enabled: get(self._options, 'EXPERIMENTAL.relay.hop.enabled',
31-
get(config, 'EXPERIMENTAL.relay.hop.enabled', false)),
32-
active: get(self._options, 'EXPERIMENTAL.relay.hop.active',
33-
get(config, 'EXPERIMENTAL.relay.hop.active', false))
22+
config: {
23+
mdns: get(config, 'Discovery.MDNS.Enabled'),
24+
webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'),
25+
bootstrap: get(config, 'Bootstrap')
26+
},
27+
EXPERIMENTAL: {
28+
// TODO move all of this to the config!
29+
pubsub: get(self._options, 'EXPERIMENTAL.pubsub', false),
30+
dht: get(self._options, 'EXPERIMENTAL.dht', false),
31+
relay: {
32+
enabled: get(self._options, 'EXPERIMENTAL.relay.enabled',
33+
get(config, 'EXPERIMENTAL.relay.enabled', false)),
34+
hop: {
35+
enabled: get(self._options, 'EXPERIMENTAL.relay.hop.enabled',
36+
get(config, 'EXPERIMENTAL.relay.hop.enabled', false)),
37+
active: get(self._options, 'EXPERIMENTAL.relay.hop.active',
38+
get(config, 'EXPERIMENTAL.relay.hop.active', false))
39+
}
3440
}
3541
}
3642
}
3743

38-
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)
44+
self._libp2pNode = new Node(libp2pOptions)
3945

4046
self._libp2pNode.on('peer:discovery', (peerInfo) => {
4147
const dial = () => {

src/core/runtime/libp2p-nodejs.js

+45-31
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,63 @@ const TCP = require('libp2p-tcp')
44
const MulticastDNS = require('libp2p-mdns')
55
const WS = require('libp2p-websockets')
66
const WebSocketStar = require('libp2p-websocket-star')
7-
const Railing = require('libp2p-railing')
7+
const Bootstrap = require('libp2p-railing')
88
const KadDHT = require('libp2p-kad-dht')
99
const Multiplex = require('libp2p-mplex')
1010
const SECIO = require('libp2p-secio')
1111
const libp2p = require('libp2p')
12+
const defaultsDeep = require('lodash.defaultsdeep')
1213

1314
class Node extends libp2p {
14-
constructor (peerInfo, peerBook, options) {
15-
options = options || {}
16-
const wsstar = new WebSocketStar({id: peerInfo.id})
15+
constructor (_options) {
16+
const wsstar = new WebSocketStar({id: _options.peerInfo.id})
17+
const mdns = new MulticastDNS(_options.peerInfo, 'ipfs.local')
1718

18-
const modules = {
19-
transport: [new TCP(), new WS(), wsstar],
20-
connection: {
21-
muxer: [Multiplex],
22-
crypto: [SECIO]
19+
const defaults = {
20+
modules: {
21+
transport: [
22+
TCP,
23+
WS
24+
],
25+
streamMuxer: [
26+
Multiplex
27+
],
28+
connEncryption: [
29+
SECIO
30+
],
31+
peerDiscovery: [
32+
MulticastDNS,
33+
Bootstrap
34+
],
35+
peerRouting: [],
36+
contentRouting: [],
37+
dht: KadDHT
2338
},
24-
discovery: [wsstar.discovery]
25-
}
26-
27-
if (options.dht) {
28-
modules.DHT = KadDHT
29-
}
30-
31-
if (options.mdns) {
32-
const mdns = new MulticastDNS(peerInfo, 'ipfs.local')
33-
modules.discovery.push(mdns)
34-
}
35-
36-
if (options.bootstrap) {
37-
const r = new Railing(options.bootstrap)
38-
modules.discovery.push(r)
39+
config: {
40+
peerDiscovery: {
41+
bootstrap: {
42+
list: _options.bootstrapList
43+
}
44+
},
45+
peerRouting: {},
46+
contentRouting: {},
47+
dht: {
48+
kBucketSize: 20
49+
}
50+
},
51+
EXPERIMENTAL: {
52+
dht: false,
53+
pubsub: false
54+
}
3955
}
4056

41-
if (options.modules && options.modules.transport) {
42-
options.modules.transport.forEach((t) => modules.transport.push(t))
43-
}
57+
defaultsDeep(_options, defaults)
4458

45-
if (options.modules && options.modules.discovery) {
46-
options.modules.discovery.forEach((d) => modules.discovery.push(d))
47-
}
59+
_options.modules.transport.push(wsstar)
60+
_options.modules.peerDiscovery.push(wsstar)
61+
_options.modules.peerDiscovery.push(mdns)
4862

49-
super(modules, peerInfo, peerBook, options)
63+
super(_options)
5064
}
5165
}
5266

0 commit comments

Comments
 (0)