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

Commit 0348766

Browse files
committed
feat: add stardust behind flag "EXPERIMENTAL.stardust"
This adds support for the stardust protocol behind the flag EXPERIMENTAL.stardust This pr is part of the endeavour to replace ws-star with stardust for the time being until a better solution is found. See the discussion at libp2p/js-libp2p-websocket-star#70 (comment) for more information
1 parent f7ece99 commit 0348766

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"libp2p-mplex": "~0.8.4",
138138
"libp2p-record": "~0.6.1",
139139
"libp2p-secio": "~0.10.1",
140+
"libp2p-stardust": "0.0.2",
140141
"libp2p-tcp": "~0.13.0",
141142
"libp2p-webrtc-star": "~0.15.5",
142143
"libp2p-websocket-star": "~0.10.0",

src/core/components/libp2p.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ module.exports = function libp2p (self) {
2626
enabled: get(opts.options, 'config.Discovery.MDNS.Enabled',
2727
get(opts.config, 'Discovery.MDNS.Enabled', true))
2828
},
29+
stardust: {
30+
enabled: get(opts.options, 'config.Discovery.Stardust.Enabled',
31+
get(opts.config, 'Discovery.Stardust.Enabled', true))
32+
},
2933
webRTCStar: {
3034
enabled: get(opts.options, 'config.Discovery.webRTCStar.Enabled',
3135
get(opts.config, 'Discovery.webRTCStar.Enabled', true))
@@ -55,7 +59,8 @@ module.exports = function libp2p (self) {
5559
},
5660
EXPERIMENTAL: {
5761
dht: get(opts.options, 'EXPERIMENTAL.dht', false),
58-
pubsub: get(opts.options, 'EXPERIMENTAL.pubsub', false)
62+
pubsub: get(opts.options, 'EXPERIMENTAL.pubsub', false),
63+
stardust: get(opts.options, 'EXPERIMENTAL.stardust', false)
5964
}
6065
},
6166
connectionManager: get(opts.options, 'connectionManager',

src/core/runtime/config-browser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = () => ({
44
Addresses: {
55
Swarm: [
6+
'/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust' // until it's actually stable it would be good to have this enabled here so `EXPERIMENTAL.stardust` actually does something
67
],
78
API: '',
89
Gateway: ''

src/core/runtime/libp2p-browser.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const WS = require('libp2p-websockets')
44
const WebRTCStar = require('libp2p-webrtc-star')
55
const WebSocketStar = require('libp2p-websocket-star')
66
const Multiplex = require('libp2p-mplex')
7+
const Stardust = require('libp2p-stardust')
78
const SECIO = require('libp2p-secio')
89
const Bootstrap = require('libp2p-bootstrap')
910
const libp2p = require('libp2p')
@@ -14,12 +15,18 @@ class Node extends libp2p {
1415
const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id })
1516
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
1617

18+
let stardust
19+
20+
if (_options.config.EXPERIMENTAL.stardust) {
21+
stardust = new Stardust({ id: _options.peerInfo.id })
22+
}
23+
1724
const defaults = {
1825
modules: {
1926
transport: [
2027
WS,
2128
wrtcstar,
22-
wsstar
29+
stardust || wsstar
2330
],
2431
streamMuxer: [
2532
Multiplex
@@ -29,7 +36,7 @@ class Node extends libp2p {
2936
],
3037
peerDiscovery: [
3138
wrtcstar.discovery,
32-
wsstar.discovery,
39+
stardust ? stardust.discovery : wsstar.discovery,
3340
Bootstrap
3441
]
3542
},
@@ -52,6 +59,8 @@ class Node extends libp2p {
5259
}
5360
}
5461

62+
delete _options.config.EXPERIMENTAL.stardust
63+
5564
super(defaultsDeep(_options, defaults))
5665
}
5766
}

src/core/runtime/libp2p-nodejs.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const WebSocketStar = require('libp2p-websocket-star')
77
const Bootstrap = require('libp2p-bootstrap')
88
const KadDHT = require('libp2p-kad-dht')
99
const Multiplex = require('libp2p-mplex')
10+
const Stardust = require('libp2p-stardust')
1011
const SECIO = require('libp2p-secio')
1112
const libp2p = require('libp2p')
1213
const defaultsDeep = require('@nodeutils/defaults-deep')
@@ -15,12 +16,18 @@ class Node extends libp2p {
1516
constructor (_options) {
1617
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
1718

19+
let stardust
20+
21+
if (_options.config.EXPERIMENTAL.stardust) {
22+
stardust = new Stardust({ id: _options.peerInfo.id })
23+
}
24+
1825
const defaults = {
1926
modules: {
2027
transport: [
2128
TCP,
2229
WS,
23-
wsstar
30+
stardust || wsstar
2431
],
2532
streamMuxer: [
2633
Multiplex
@@ -31,7 +38,7 @@ class Node extends libp2p {
3138
peerDiscovery: [
3239
MulticastDNS,
3340
Bootstrap,
34-
wsstar.discovery
41+
stardust ? stardust.discovery : wsstar.discovery
3542
],
3643
dht: KadDHT
3744
},
@@ -40,6 +47,9 @@ class Node extends libp2p {
4047
mdns: {
4148
enabled: true
4249
},
50+
stardust: {
51+
enabled: true
52+
},
4353
bootstrap: {
4454
enabled: true
4555
},
@@ -57,6 +67,8 @@ class Node extends libp2p {
5767
}
5868
}
5969

70+
delete _options.config.EXPERIMENTAL.stardust
71+
6072
super(defaultsDeep(_options, defaults))
6173
}
6274
}

0 commit comments

Comments
 (0)