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

Commit

Permalink
feat: add stardust behind flag "EXPERIMENTAL.stardust"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkg20001 committed Jan 12, 2019
1 parent f7ece99 commit e96f041
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
3 changes: 2 additions & 1 deletion src/core/runtime/config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = () => ({
'/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
'/dns4/nyc-2.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
'/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6'
'/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6',
'/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust'
]
})
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 })
}

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 })
}

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

0 comments on commit e96f041

Please sign in to comment.