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

Commit 21fd4d1

Browse files
mkg20001Alan Shaw
authored andcommitted
feat: use ws-star-multi instead of ws-star (#1793)
Co-Authored-By: mkg20001 <mkg20001@gmail.com>
1 parent 6066c97 commit 21fd4d1

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"libp2p-secio": "~0.11.0",
140140
"libp2p-tcp": "~0.13.0",
141141
"libp2p-webrtc-star": "~0.15.5",
142-
"libp2p-websocket-star": "~0.10.0",
142+
"libp2p-websocket-star-multi": "~0.4.0",
143143
"libp2p-websockets": "~0.12.0",
144144
"lodash": "^4.17.11",
145145
"mafmt": "^6.0.2",

src/core/runtime/libp2p-browser.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
const WS = require('libp2p-websockets')
44
const WebRTCStar = require('libp2p-webrtc-star')
5-
const WebSocketStar = require('libp2p-websocket-star')
5+
const WebSocketStarMulti = require('libp2p-websocket-star-multi')
66
const Multiplex = require('libp2p-mplex')
77
const SECIO = require('libp2p-secio')
88
const Bootstrap = require('libp2p-bootstrap')
99
const libp2p = require('libp2p')
1010
const defaultsDeep = require('@nodeutils/defaults-deep')
11+
const multiaddr = require('multiaddr')
1112

1213
class Node extends libp2p {
1314
constructor (_options) {
1415
const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id })
15-
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
16+
17+
// this can be replaced once optional listening is supported with the below code. ref: https://github.com/libp2p/interface-transport/issues/41
18+
// const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
19+
const wsstarServers = _options.peerInfo.multiaddrs.toArray().map(String).filter(addr => addr.includes('p2p-websocket-star'))
20+
_options.peerInfo.multiaddrs.replace(wsstarServers.map(multiaddr), '/p2p-websocket-star') // the ws-star-multi module will replace this with the chosen ws-star servers
21+
const wsstar = new WebSocketStarMulti({ servers: wsstarServers, id: _options.peerInfo.id, ignore_no_online: !wsstarServers.length || _options.wsStarIgnoreErrors })
1622

1723
const defaults = {
1824
modules: {

src/core/runtime/libp2p-nodejs.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
const TCP = require('libp2p-tcp')
44
const MulticastDNS = require('libp2p-mdns')
55
const WS = require('libp2p-websockets')
6-
const WebSocketStar = require('libp2p-websocket-star')
6+
const WebSocketStarMulti = require('libp2p-websocket-star-multi')
77
const Bootstrap = require('libp2p-bootstrap')
88
const KadDHT = require('libp2p-kad-dht')
99
const Multiplex = require('libp2p-mplex')
1010
const SECIO = require('libp2p-secio')
1111
const libp2p = require('libp2p')
1212
const defaultsDeep = require('@nodeutils/defaults-deep')
13+
const multiaddr = require('multiaddr')
1314

1415
class Node extends libp2p {
1516
constructor (_options) {
16-
const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
17+
// this can be replaced once optional listening is supported with the below code. ref: https://github.com/libp2p/interface-transport/issues/41
18+
// const wsstar = new WebSocketStar({ id: _options.peerInfo.id })
19+
const wsstarServers = _options.peerInfo.multiaddrs.toArray().map(String).filter(addr => addr.includes('p2p-websocket-star'))
20+
_options.peerInfo.multiaddrs.replace(wsstarServers.map(multiaddr), '/p2p-websocket-star') // the ws-star-multi module will replace this with the chosen ws-star servers
21+
const wsstar = new WebSocketStarMulti({ servers: wsstarServers, id: _options.peerInfo.id, ignore_no_online: !wsstarServers.length || _options.wsStarIgnoreErrors })
1722

1823
const defaults = {
1924
modules: {

0 commit comments

Comments
 (0)