diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index 31fed7abcf..f3c794cf2a 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -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'] } } } diff --git a/package.json b/package.json index 7a4c204881..294a8a6192 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -145,7 +146,7 @@ "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", @@ -153,7 +154,7 @@ "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", diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index c5e3a40b1c..ad5b5c14fd 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -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)) @@ -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', diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index fec12fa9a3..c12dbc0fea 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -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') @@ -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 @@ -29,7 +36,7 @@ class Node extends libp2p { ], peerDiscovery: [ wrtcstar.discovery, - wsstar.discovery, + stardust ? stardust.discovery : wsstar.discovery, Bootstrap ] }, @@ -52,6 +59,8 @@ class Node extends libp2p { } } + delete _options.config.EXPERIMENTAL.stardust + super(defaultsDeep(_options, defaults)) } } diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index 1b59c435c7..a335e55ce6 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -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') @@ -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 @@ -31,7 +38,7 @@ class Node extends libp2p { peerDiscovery: [ MulticastDNS, Bootstrap, - wsstar.discovery + stardust ? stardust.discovery : wsstar.discovery ], dht: KadDHT }, @@ -40,6 +47,9 @@ class Node extends libp2p { mdns: { enabled: true }, + stardust: { + enabled: true + }, bootstrap: { enabled: true }, @@ -57,6 +67,8 @@ class Node extends libp2p { } } + delete _options.config.EXPERIMENTAL.stardust + super(defaultsDeep(_options, defaults)) } }