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

Commit 9969981

Browse files
committed
feat: websocket-star? what's that. only heard of stardust!
(...psst, we're replacing ws-star with stardust, which does the same things, except it's way faster & more secure)
1 parent a61d510 commit 9969981

File tree

10 files changed

+20
-35
lines changed

10 files changed

+20
-35
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1003,22 +1003,24 @@ The code above assumes you are running a local `signaling server` on port `9090`
10031003
10041004
#### Is there a more stable alternative to webrtc-star that offers a similar functionality?
10051005
1006-
Yes, websocket-star! A WebSockets based transport that uses a Relay to route the messages. To enable it, just do:
1006+
Yes, stardust! A WebSockets based transport that uses a Relay to route the messages. To enable it, just do:
10071007
10081008
```JavaScript
10091009
const node = await IPFS.create({
10101010
config: {
10111011
Addresses: {
10121012
Swarm: [
1013-
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
1013+
'/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust'
10141014
]
10151015
}
10161016
}
10171017
})
10181018

1019-
// your instance with websocket-star is ready
1019+
// your instance with stardust is ready
10201020
```
10211021
1022+
(You may need to install the stardust module as well, with `npm install libp2p-stardust`)
1023+
10221024
#### I see some slowness when hopping between tabs Chrome with IPFS nodes, is there a reason why?
10231025
10241026
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.

examples/circuit-relaying/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ In order to enable the relay functionality in `go-ipfs` we need to edit it's con
155155

156156
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.
157157

158-
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.
158+
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.
159159

160160
```json
161161
"Swarm": [

examples/custom-libp2p/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Libp2p = require('libp2p')
44
const IPFS = require('ipfs')
55
const TCP = require('libp2p-tcp')
66
const MulticastDNS = require('libp2p-mdns')
7-
const WebSocketStar = require('libp2p-websocket-star')
7+
const Stardust = require('libp2p-stardust')
88
const Bootstrap = require('libp2p-bootstrap')
99
const SPDY = require('libp2p-spdy')
1010
const KadDHT = require('libp2p-kad-dht')
@@ -32,8 +32,8 @@ const libp2pBundle = (opts) => {
3232
const peerBook = opts.peerBook
3333
const bootstrapList = opts.config.Bootstrap
3434

35-
// Create our WebSocketStar transport and give it our PeerId, straight from the ipfs node
36-
const wsstar = new WebSocketStar({
35+
// Create our Stardust transport and give it our PeerId, straight from the ipfs node
36+
const wsstar = new Stardust({
3737
id: peerInfo.id
3838
})
3939

@@ -50,7 +50,7 @@ const libp2pBundle = (opts) => {
5050
modules: {
5151
transport: [
5252
TCP,
53-
wsstar
53+
stardust
5454
],
5555
streamMuxer: [
5656
MPLEX,
@@ -62,7 +62,7 @@ const libp2pBundle = (opts) => {
6262
peerDiscovery: [
6363
MulticastDNS,
6464
Bootstrap,
65-
wsstar.discovery
65+
stardust.discovery
6666
],
6767
dht: KadDHT
6868
},

examples/custom-libp2p/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"libp2p-secio": "~0.11.1",
1818
"libp2p-spdy": "~0.13.3",
1919
"libp2p-tcp": "~0.13.0",
20-
"libp2p-websocket-star": "~0.10.2",
20+
"libp2p-stardust": "~0.1.2",
2121
"pull-mplex": "~0.1.0"
2222
}
2323
}

examples/exchange-files-in-browser/public/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function start () {
4848
repo: 'ipfs-' + Math.random(),
4949
config: {
5050
Addresses: {
51-
Swarm: ['/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star']
51+
Swarm: ['/dns4/stardust.mkg20001.io/tcp/443/wss/p2p-stardust']
5252
}
5353
}
5454
}

package-list.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
["libp2p/js-libp2p-bootstrap", "libp2p-bootstrap"],
5050
["libp2p/js-libp2p-secio", "libp2p-secio"],
5151
["libp2p/js-libp2p-tcp", "libp2p-tcp"],
52+
["libp2p/js-libp2p-stardust", "libp2p-stardust"],
5253
["libp2p/js-libp2p-webrtc-star", "libp2p-webrtc-star"],
53-
["libp2p/js-libp2p-websocket-star", "libp2p-websocket-star"],
5454
["libp2p/js-libp2p-websockets", "libp2p-websockets"],
5555
["libp2p/pull-mplex", "pull-mplex"],
5656

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
"libp2p-secio": "~0.11.0",
145145
"libp2p-tcp": "^0.13.0",
146146
"libp2p-webrtc-star": "~0.16.0",
147-
"libp2p-websocket-star-multi": "~0.4.3",
148147
"libp2p-websockets": "~0.12.3",
149148
"lodash": "^4.17.15",
150149
"lodash.flatten": "^4.4.0",
@@ -207,7 +206,7 @@
207206
"interface-ipfs-core": "^0.117.2",
208207
"ipfs-interop": "^0.1.1",
209208
"ipfsd-ctl": "^0.47.2",
210-
"libp2p-websocket-star": "~0.10.2",
209+
"libp2p-stardust": "~0.1.2",
211210
"ncp": "^2.0.0",
212211
"p-event": "^4.1.0",
213212
"qs": "^6.5.2",

src/core/runtime/libp2p-browser.js

-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const WS = require('libp2p-websockets')
44
const WebRTCStar = require('libp2p-webrtc-star')
5-
const WebSocketStarMulti = require('libp2p-websocket-star-multi')
65
const Multiplex = require('pull-mplex')
76
const SECIO = require('libp2p-secio')
87
const Bootstrap = require('libp2p-bootstrap')
@@ -16,12 +15,6 @@ class Node extends libp2p {
1615
constructor (_options) {
1716
const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id })
1817

19-
// this can be replaced once optional listening is supported with the below code. ref: https://github.com/libp2p/interface-transport/issues/41
20-
// const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
21-
const wsstarServers = _options.peerInfo.multiaddrs.toArray().map(String).filter(addr => addr.includes('p2p-websocket-star'))
22-
_options.peerInfo.multiaddrs.replace(wsstarServers.map(multiaddr), '/p2p-websocket-star') // the ws-star-multi module will replace this with the chosen ws-star servers
23-
const wsstar = new WebSocketStarMulti({ servers: wsstarServers, id: _options.peerInfo.id, ignore_no_online: !wsstarServers.length || _options.wsStarIgnoreErrors })
24-
2518
const defaults = {
2619
switch: {
2720
denyTTL: 2 * 60 * 1e3, // 2 minute base
@@ -44,7 +37,6 @@ class Node extends libp2p {
4437
],
4538
peerDiscovery: [
4639
wrtcstar.discovery,
47-
wsstar.discovery,
4840
Bootstrap
4941
],
5042
dht: KadDHT,

src/core/runtime/libp2p-nodejs.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const TCP = require('libp2p-tcp')
44
const MulticastDNS = require('libp2p-mdns')
55
const WS = require('libp2p-websockets')
6-
const WebSocketStarMulti = require('libp2p-websocket-star-multi')
76
const Bootstrap = require('libp2p-bootstrap')
87
const KadDHT = require('libp2p-kad-dht')
98
const GossipSub = require('libp2p-gossipsub')
@@ -15,12 +14,6 @@ const multiaddr = require('multiaddr')
1514

1615
class Node extends libp2p {
1716
constructor (_options) {
18-
// this can be replaced once optional listening is supported with the below code. ref: https://github.com/libp2p/interface-transport/issues/41
19-
// const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
20-
const wsstarServers = _options.peerInfo.multiaddrs.toArray().map(String).filter(addr => addr.includes('p2p-websocket-star'))
21-
_options.peerInfo.multiaddrs.replace(wsstarServers.map(multiaddr), '/p2p-websocket-star') // the ws-star-multi module will replace this with the chosen ws-star servers
22-
const wsstar = new WebSocketStarMulti({ servers: wsstarServers, id: _options.peerInfo.id, ignore_no_online: !wsstarServers.length || _options.wsStarIgnoreErrors })
23-
2417
const defaults = {
2518
switch: {
2619
denyTTL: 2 * 60 * 1e3, // 2 minute base
@@ -43,8 +36,7 @@ class Node extends libp2p {
4336
],
4437
peerDiscovery: [
4538
MulticastDNS,
46-
Bootstrap,
47-
wsstar.discovery
39+
Bootstrap
4840
],
4941
dht: KadDHT,
5042
pubsub: GossipSub

test/core/libp2p.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { expect } = require('interface-ipfs-core/src/utils/mocha')
66
const MemoryStore = require('interface-datastore').MemoryDatastore
77
const PeerInfo = require('peer-info')
88
const PeerBook = require('peer-book')
9-
const WebSocketStar = require('libp2p-websocket-star')
9+
const Stardust = require('libp2p-stardust')
1010
const Multiplex = require('pull-mplex')
1111
const SECIO = require('libp2p-secio')
1212
const KadDHT = require('libp2p-kad-dht')
@@ -71,14 +71,14 @@ describe('libp2p customization', function () {
7171
_print: console.log,
7272
_options: {
7373
libp2p: (opts) => {
74-
const wsstar = new WebSocketStar({ id: opts.peerInfo.id })
74+
const stardust = new Stardust({ id: opts.peerInfo.id })
7575

7676
return new Libp2p({
7777
peerInfo: opts.peerInfo,
7878
peerBook: opts.peerBook,
7979
modules: {
8080
transport: [
81-
wsstar
81+
stardust
8282
],
8383
streamMuxer: [
8484
Multiplex
@@ -87,7 +87,7 @@ describe('libp2p customization', function () {
8787
SECIO
8888
],
8989
peerDiscovery: [
90-
wsstar.discovery
90+
stardust.discovery
9191
],
9292
dht: KadDHT
9393
}

0 commit comments

Comments
 (0)