From 44c15764d2933d45a914b5b83f7b615da9080b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Wed, 13 Nov 2019 14:01:04 +0100 Subject: [PATCH 1/3] feat: apply changes --- README.md | 11 ++++++++--- examples/circuit-relaying/README.md | 2 +- examples/custom-libp2p/index.js | 10 +++++----- examples/custom-libp2p/package.json | 2 +- examples/exchange-files-in-browser/package.json | 4 +++- examples/exchange-files-in-browser/public/app.js | 9 ++++++--- package-list.json | 2 +- package.json | 5 +++-- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 908c21d2e8..39b31e2e19 100644 --- a/README.md +++ b/README.md @@ -1003,22 +1003,27 @@ The code above assumes you are running a local `signaling server` on port `9090` #### Is there a more stable alternative to webrtc-star that offers a similar functionality? -Yes, websocket-star! A WebSockets based transport that uses a Relay to route the messages. To enable it, just do: +Yes, stardust! A WebSockets based transport that uses a Relay to route the messages. To enable it, just do: ```JavaScript const node = await IPFS.create({ + libp2p: { + overrideFunction: require('stardust4ipfs') + }, config: { Addresses: { Swarm: [ - '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star' + '/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust' ] } } }) -// your instance with websocket-star is ready +// your instance with stardust is ready ``` +(You may need to install the stardust4ipfs module as well, with `npm install stardust4ipfs`) + #### I see some slowness when hopping between tabs Chrome with IPFS nodes, is there a reason why? Yes, unfortunately, due to [Chrome aggressive resource throttling policy](https://github.com/ipfs/js-ipfs/issues/611), it cuts freezes the execution of any background tab, turning an IPFS node that was running on that webpage into a vegetable state. diff --git a/examples/circuit-relaying/README.md b/examples/circuit-relaying/README.md index be33d79bab..6f84086acc 100644 --- a/examples/circuit-relaying/README.md +++ b/examples/circuit-relaying/README.md @@ -155,7 +155,7 @@ In order to enable the relay functionality in `go-ipfs` we need to edit it's con The two options we're looking for are `DisableRelay` and `EnableRelayHop`. We want the former (`DisableRelay`) set to `false` and the latter (`EnableRelayHop`) to `true`, just like in the example above. That should set our go node as a relay. -We also need to make sure our go node can be dialed from the browser. For that, we need to enable a transport that both the browser and the go node can communicate over. We will use the web sockets transport, although there are others that can be used, such as `webrtc-star` and `websocket-star`. To enable the transport and set the interface and port we need to edit the `~/.ipfs/config` one more time. Let's find the `Swarm` array and add our desired address there. I picked `/ip4/0.0.0.0/tcp/4004/ws` because it is a port I know is not being used by anything on my machine, but we can also use port `0` so that the OS chooses a random available port for us — either one should work. +We also need to make sure our go node can be dialed from the browser. For that, we need to enable a transport that both the browser and the go node can communicate over. We will use the web sockets transport, although there are others that can be used, such as `webrtc-star` and `stardust`. To enable the transport and set the interface and port we need to edit the `~/.ipfs/config` one more time. Let's find the `Swarm` array and add our desired address there. I picked `/ip4/0.0.0.0/tcp/4004/ws` because it is a port I know is not being used by anything on my machine, but we can also use port `0` so that the OS chooses a random available port for us — either one should work. ```json "Swarm": [ diff --git a/examples/custom-libp2p/index.js b/examples/custom-libp2p/index.js index fa1a097b86..d4f038041d 100644 --- a/examples/custom-libp2p/index.js +++ b/examples/custom-libp2p/index.js @@ -4,7 +4,7 @@ const Libp2p = require('libp2p') const IPFS = require('ipfs') const TCP = require('libp2p-tcp') const MulticastDNS = require('libp2p-mdns') -const WebSocketStar = require('libp2p-websocket-star') +const Stardust = require('libp2p-stardust') const Bootstrap = require('libp2p-bootstrap') const SPDY = require('libp2p-spdy') const KadDHT = require('libp2p-kad-dht') @@ -32,8 +32,8 @@ const libp2pBundle = (opts) => { const peerBook = opts.peerBook const bootstrapList = opts.config.Bootstrap - // Create our WebSocketStar transport and give it our PeerId, straight from the ipfs node - const wsstar = new WebSocketStar({ + // Create our Stardust transport and give it our PeerId, straight from the ipfs node + const stardust = new Stardust({ id: peerInfo.id }) @@ -50,7 +50,7 @@ const libp2pBundle = (opts) => { modules: { transport: [ TCP, - wsstar + stardust ], streamMuxer: [ MPLEX, @@ -62,7 +62,7 @@ const libp2pBundle = (opts) => { peerDiscovery: [ MulticastDNS, Bootstrap, - wsstar.discovery + stardust.discovery ], dht: KadDHT }, diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 904579511e..9da7b5d344 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -17,7 +17,7 @@ "libp2p-secio": "~0.11.1", "libp2p-spdy": "~0.13.3", "libp2p-tcp": "~0.13.0", - "libp2p-websocket-star": "~0.10.2", + "libp2p-stardust": "~0.1.2", "pull-mplex": "~0.1.0" } } diff --git a/examples/exchange-files-in-browser/package.json b/examples/exchange-files-in-browser/package.json index f2421f8793..793388ac17 100644 --- a/examples/exchange-files-in-browser/package.json +++ b/examples/exchange-files-in-browser/package.json @@ -9,7 +9,8 @@ "license": "MIT", "devDependencies": { "browserify": "^16.2.3", - "http-server": "~0.11.1" + "http-server": "~0.11.1", + "stardust4ipfs": "~0.1.3" }, "dependencies": { "ipfs": "file:../../" @@ -18,3 +19,4 @@ "ipfs": "ipfs/dist" } } + diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index f23ca84f14..3bfd4ff317 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -46,9 +46,12 @@ async function start () { if (!node) { const options = { repo: 'ipfs-' + Math.random(), + libp2p: { + overrideFunction: require('stardust4ipfs') + }, 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'] } } } @@ -154,7 +157,7 @@ const publishHash = (hash) => { const sendFileList = () => Promise.all(FILES.map(publishHash)) const updateProgress = (bytesLoaded) => { - let percent = 100 - ((bytesLoaded / fileSize) * 100) + const percent = 100 - ((bytesLoaded / fileSize) * 100) $progressBar.style.transform = `translateX(${-percent}%)` } @@ -261,7 +264,7 @@ async function connectToPeer (event) { await node.swarm.connect(multiaddr) - onSuccess(`Successfully connected to peer.`) + onSuccess('Successfully connected to peer.') $multiaddrInput.value = '' } diff --git a/package-list.json b/package-list.json index efd98007cc..94ab5e2a9e 100644 --- a/package-list.json +++ b/package-list.json @@ -49,8 +49,8 @@ ["libp2p/js-libp2p-bootstrap", "libp2p-bootstrap"], ["libp2p/js-libp2p-secio", "libp2p-secio"], ["libp2p/js-libp2p-tcp", "libp2p-tcp"], + ["libp2p/js-libp2p-stardust", "libp2p-stardust"], ["libp2p/js-libp2p-webrtc-star", "libp2p-webrtc-star"], - ["libp2p/js-libp2p-websocket-star", "libp2p-websocket-star"], ["libp2p/js-libp2p-websockets", "libp2p-websockets"], ["libp2p/pull-mplex", "pull-mplex"], diff --git a/package.json b/package.json index b25720bb48..bc585f7aeb 100644 --- a/package.json +++ b/package.json @@ -144,7 +144,6 @@ "libp2p-secio": "~0.11.0", "libp2p-tcp": "^0.13.0", "libp2p-webrtc-star": "~0.16.0", - "libp2p-websocket-star-multi": "~0.4.3", "libp2p-websockets": "~0.12.3", "lodash": "^4.17.15", "lodash.flatten": "^4.4.0", @@ -207,12 +206,13 @@ "interface-ipfs-core": "^0.118.0", "ipfs-interop": "^0.1.1", "ipfsd-ctl": "^0.47.2", - "libp2p-websocket-star": "~0.10.2", + "libp2p-stardust": "~0.1.2", "ncp": "^2.0.0", "p-event": "^4.1.0", "qs": "^6.5.2", "rimraf": "^3.0.0", "sinon": "^7.4.2", + "stardust4ipfs": "^0.1.3", "stream-to-promise": "^2.2.0", "temp-write": "^4.0.0" }, @@ -358,3 +358,4 @@ "Максим Ильин " ] } + From e55996f4e395246af264d383835bf13bf081d2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Wed, 13 Nov 2019 14:16:54 +0100 Subject: [PATCH 2/3] fix: rm wsstar --- src/core/runtime/libp2p-browser.js | 15 +-------------- src/core/runtime/libp2p-nodejs.js | 17 ++--------------- test/core/libp2p.spec.js | 22 ++++++++-------------- 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index 7c8a921886..369a188c4a 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -2,23 +2,15 @@ const WS = require('libp2p-websockets') const WebRTCStar = require('libp2p-webrtc-star') -const WebSocketStarMulti = require('libp2p-websocket-star-multi') const Multiplex = require('pull-mplex') const SECIO = require('libp2p-secio') const Bootstrap = require('libp2p-bootstrap') const KadDHT = require('libp2p-kad-dht') const GossipSub = require('libp2p-gossipsub') -const multiaddr = require('multiaddr') module.exports = ({ peerInfo, options }) => { const wrtcstar = new WebRTCStar({ id: peerInfo.id }) - // this can be replaced once optional listening is supported with the below code. ref: https://github.com/libp2p/interface-transport/issues/41 - // const wsstar = new WebSocketStar({ id: _options.peerInfo.id }) - const wsstarServers = peerInfo.multiaddrs.toArray().map(String).filter(addr => addr.includes('p2p-websocket-star')) - peerInfo.multiaddrs.replace(wsstarServers.map(multiaddr), '/p2p-websocket-star') // the ws-star-multi module will replace this with the chosen ws-star servers - const wsstar = new WebSocketStarMulti({ servers: wsstarServers, id: peerInfo.id, ignore_no_online: !wsstarServers.length || options.wsStarIgnoreErrors }) - return { switch: { denyTTL: 2 * 60 * 1e3, // 2 minute base @@ -30,8 +22,7 @@ module.exports = ({ peerInfo, options }) => { modules: { transport: [ WS, - wrtcstar, - wsstar + wrtcstar ], streamMuxer: [ Multiplex @@ -41,7 +32,6 @@ module.exports = ({ peerInfo, options }) => { ], peerDiscovery: [ wrtcstar.discovery, - wsstar.discovery, Bootstrap ], dht: KadDHT, @@ -55,9 +45,6 @@ module.exports = ({ peerInfo, options }) => { }, webRTCStar: { enabled: true - }, - websocketStar: { - enabled: true } }, dht: { diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index fb8d488752..aa923e2261 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -3,21 +3,13 @@ const TCP = require('libp2p-tcp') const MulticastDNS = require('libp2p-mdns') const WS = require('libp2p-websockets') -const WebSocketStarMulti = require('libp2p-websocket-star-multi') const Bootstrap = require('libp2p-bootstrap') const KadDHT = require('libp2p-kad-dht') const GossipSub = require('libp2p-gossipsub') const Multiplex = require('pull-mplex') const SECIO = require('libp2p-secio') -const multiaddr = require('multiaddr') module.exports = ({ peerInfo, options }) => { - // this can be replaced once optional listening is supported with the below code. ref: https://github.com/libp2p/interface-transport/issues/41 - // const wsstar = new WebSocketStar({ id: _options.peerInfo.id }) - const wsstarServers = peerInfo.multiaddrs.toArray().map(String).filter(addr => addr.includes('p2p-websocket-star')) - peerInfo.multiaddrs.replace(wsstarServers.map(multiaddr), '/p2p-websocket-star') // the ws-star-multi module will replace this with the chosen ws-star servers - const wsstar = new WebSocketStarMulti({ servers: wsstarServers, id: peerInfo.id, ignore_no_online: !wsstarServers.length || options.wsStarIgnoreErrors }) - return { switch: { denyTTL: 2 * 60 * 1e3, // 2 minute base @@ -29,8 +21,7 @@ module.exports = ({ peerInfo, options }) => { modules: { transport: [ TCP, - WS, - wsstar + WS ], streamMuxer: [ Multiplex @@ -40,8 +31,7 @@ module.exports = ({ peerInfo, options }) => { ], peerDiscovery: [ MulticastDNS, - Bootstrap, - wsstar.discovery + Bootstrap ], dht: KadDHT, pubsub: GossipSub @@ -54,9 +44,6 @@ module.exports = ({ peerInfo, options }) => { }, bootstrap: { enabled: true - }, - websocketStar: { - enabled: true } }, dht: { diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js index e9d5f47547..9bba95f14f 100644 --- a/test/core/libp2p.spec.js +++ b/test/core/libp2p.spec.js @@ -6,7 +6,7 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha') const MemoryStore = require('interface-datastore').MemoryDatastore const PeerInfo = require('peer-info') const PeerBook = require('peer-book') -const WebSocketStar = require('libp2p-websocket-star') +const Stardust = require('libp2p-stardust') const Multiplex = require('pull-mplex') const SECIO = require('libp2p-secio') const KadDHT = require('libp2p-kad-dht') @@ -71,14 +71,14 @@ describe('libp2p customization', function () { _print: console.log, _options: { libp2p: (opts) => { - const wsstar = new WebSocketStar({ id: opts.peerInfo.id }) + const stardust = new Stardust({ id: opts.peerInfo.id }) return new Libp2p({ peerInfo: opts.peerInfo, peerBook: opts.peerBook, modules: { transport: [ - wsstar + stardust ], streamMuxer: [ Multiplex @@ -87,7 +87,7 @@ describe('libp2p customization', function () { SECIO ], peerDiscovery: [ - wsstar.discovery + stardust.discovery ], dht: KadDHT } @@ -170,9 +170,6 @@ describe('libp2p customization', function () { }, webRTCStar: { enabled: false - }, - websocketStar: { - enabled: true } }, pubsub: { @@ -182,13 +179,13 @@ describe('libp2p customization', function () { strictSigning: true } }) - expect(_libp2p._transport).to.have.length(3) + expect(_libp2p._transport).to.have.length(2) done() }) }) it('should allow for overriding via options', (done) => { - const wsstar = new WebSocketStar({ id: peerInfo.id }) + const stardust = new Stardust({ id: peerInfo.id }) const ipfs = { _repo: { @@ -212,10 +209,10 @@ describe('libp2p customization', function () { libp2p: { modules: { transport: [ - wsstar + stardust ], peerDiscovery: [ - wsstar.discovery + stardust.discovery ] } } @@ -238,9 +235,6 @@ describe('libp2p customization', function () { }, webRTCStar: { enabled: false - }, - websocketStar: { - enabled: true } } }) From ad240fdd739afe87b1337c79d3b0c1ba7a263081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Wed, 13 Nov 2019 14:27:39 +0100 Subject: [PATCH 3/3] feat: upgrade stardust4ipfs --- README.md | 4 +--- examples/exchange-files-in-browser/package.json | 2 +- examples/exchange-files-in-browser/public/app.js | 4 +--- package.json | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 39b31e2e19..0cebb96987 100644 --- a/README.md +++ b/README.md @@ -1007,9 +1007,7 @@ Yes, stardust! A WebSockets based transport that uses a Relay to route the messa ```JavaScript const node = await IPFS.create({ - libp2p: { - overrideFunction: require('stardust4ipfs') - }, + libp2p: require('stardust4ipfs'), config: { Addresses: { Swarm: [ diff --git a/examples/exchange-files-in-browser/package.json b/examples/exchange-files-in-browser/package.json index 793388ac17..99d0eb6c3f 100644 --- a/examples/exchange-files-in-browser/package.json +++ b/examples/exchange-files-in-browser/package.json @@ -10,7 +10,7 @@ "devDependencies": { "browserify": "^16.2.3", "http-server": "~0.11.1", - "stardust4ipfs": "~0.1.3" + "stardust4ipfs": "~0.2.0" }, "dependencies": { "ipfs": "file:../../" diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js index 3bfd4ff317..e5303d60f8 100644 --- a/examples/exchange-files-in-browser/public/app.js +++ b/examples/exchange-files-in-browser/public/app.js @@ -46,9 +46,7 @@ async function start () { if (!node) { const options = { repo: 'ipfs-' + Math.random(), - libp2p: { - overrideFunction: require('stardust4ipfs') - }, + libp2p: require('stardust4ipfs'), config: { Addresses: { Swarm: ['/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust'] diff --git a/package.json b/package.json index bc585f7aeb..776494c135 100644 --- a/package.json +++ b/package.json @@ -212,7 +212,7 @@ "qs": "^6.5.2", "rimraf": "^3.0.0", "sinon": "^7.4.2", - "stardust4ipfs": "^0.1.3", + "stardust4ipfs": "^0.2.0", "stream-to-promise": "^2.2.0", "temp-write": "^4.0.0" },