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

[WIP] feat: add stardust behind flag "EXPERIMENTAL.stardust" #1812

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/exchange-files-in-browser/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ function start () {
if (!node) {
const options = {
EXPERIMENTAL: {
pubsub: true
pubsub: true,
stardust: true
},
repo: 'ipfs-' + Math.random(),
config: {
Addresses: {
Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']
Swarm: ['/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust']
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"is-stream": "^1.1.0",
"joi": "^14.3.0",
"joi-browser": "^13.4.0",
"joi-multiaddr": "^3.0.0",
"joi-multiaddr": "^4.0.0",
"libp2p": "~0.24.1",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.14.1",
Expand All @@ -137,6 +137,7 @@
"libp2p-mplex": "~0.8.4",
"libp2p-record": "~0.6.1",
"libp2p-secio": "~0.10.1",
"libp2p-stardust": "0.0.2",
"libp2p-tcp": "~0.13.0",
"libp2p-webrtc-star": "~0.15.5",
"libp2p-websocket-star": "~0.10.0",
Expand All @@ -145,15 +146,15 @@
"mafmt": "^6.0.2",
"mime-types": "^2.1.21",
"mkdirp": "~0.5.1",
"multiaddr": "^6.0.0",
"multiaddr": "github:mkg20001/js-multiaddr#patch-1",
"multiaddr-to-uri": "^4.0.0",
"multibase": "~0.6.0",
"multihashes": "~0.4.14",
"multihashing-async": "~0.5.1",
"node-fetch": "^2.3.0",
"once": "^1.4.0",
"peer-book": "~0.9.0",
"peer-id": "~0.12.0",
"peer-id": "github:libp2p/js-peer-id#tmp-use-peer-id-with-encrypt",
"peer-info": "~0.15.0",
"progress": "^2.0.1",
"promisify-es6": "^1.0.3",
Expand Down
7 changes: 6 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = function libp2p (self) {
enabled: get(opts.options, 'config.Discovery.MDNS.Enabled',
get(opts.config, 'Discovery.MDNS.Enabled', true))
},
stardust: {
enabled: get(opts.options, 'config.Discovery.Stardust.Enabled',
get(opts.config, 'Discovery.Stardust.Enabled', true))
},
webRTCStar: {
enabled: get(opts.options, 'config.Discovery.webRTCStar.Enabled',
get(opts.config, 'Discovery.webRTCStar.Enabled', true))
Expand Down Expand Up @@ -55,7 +59,8 @@ module.exports = function libp2p (self) {
},
EXPERIMENTAL: {
dht: get(opts.options, 'EXPERIMENTAL.dht', false),
pubsub: get(opts.options, 'EXPERIMENTAL.pubsub', false)
pubsub: get(opts.options, 'EXPERIMENTAL.pubsub', false),
stardust: get(opts.options, 'EXPERIMENTAL.stardust', false)
}
},
connectionManager: get(opts.options, 'connectionManager',
Expand Down
13 changes: 11 additions & 2 deletions src/core/runtime/libp2p-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const WS = require('libp2p-websockets')
const WebRTCStar = require('libp2p-webrtc-star')
const WebSocketStar = require('libp2p-websocket-star')
const Multiplex = require('libp2p-mplex')
const Stardust = require('libp2p-stardust')
const SECIO = require('libp2p-secio')
const Bootstrap = require('libp2p-bootstrap')
const libp2p = require('libp2p')
Expand All @@ -14,12 +15,18 @@ class Node extends libp2p {
const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id })
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })

let stardust

if (_options.config.EXPERIMENTAL.stardust) {
stardust = new Stardust({ id: _options.peerInfo.id, softFail: true })
}

const defaults = {
modules: {
transport: [
WS,
wrtcstar,
wsstar
stardust || wsstar
],
streamMuxer: [
Multiplex
Expand All @@ -29,7 +36,7 @@ class Node extends libp2p {
],
peerDiscovery: [
wrtcstar.discovery,
wsstar.discovery,
stardust ? stardust.discovery : wsstar.discovery,
Bootstrap
]
},
Expand All @@ -52,6 +59,8 @@ class Node extends libp2p {
}
}

delete _options.config.EXPERIMENTAL.stardust

super(defaultsDeep(_options, defaults))
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/core/runtime/libp2p-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const WebSocketStar = require('libp2p-websocket-star')
const Bootstrap = require('libp2p-bootstrap')
const KadDHT = require('libp2p-kad-dht')
const Multiplex = require('libp2p-mplex')
const Stardust = require('libp2p-stardust')
const SECIO = require('libp2p-secio')
const libp2p = require('libp2p')
const defaultsDeep = require('@nodeutils/defaults-deep')
Expand All @@ -15,12 +16,18 @@ class Node extends libp2p {
constructor (_options) {
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })

let stardust

if (_options.config.EXPERIMENTAL.stardust) {
stardust = new Stardust({ id: _options.peerInfo.id, softFail: true })
}

const defaults = {
modules: {
transport: [
TCP,
WS,
wsstar
stardust || wsstar
],
streamMuxer: [
Multiplex
Expand All @@ -31,7 +38,7 @@ class Node extends libp2p {
peerDiscovery: [
MulticastDNS,
Bootstrap,
wsstar.discovery
stardust ? stardust.discovery : wsstar.discovery
],
dht: KadDHT
},
Expand All @@ -40,6 +47,9 @@ class Node extends libp2p {
mdns: {
enabled: true
},
stardust: {
enabled: true
},
bootstrap: {
enabled: true
},
Expand All @@ -57,6 +67,8 @@ class Node extends libp2p {
}
}

delete _options.config.EXPERIMENTAL.stardust

super(defaultsDeep(_options, defaults))
}
}
Expand Down