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

Commit b9db5d4

Browse files
authoredJun 22, 2020
chore: throw error no swarm on multiaddrs using websocket-star (#3051)
On `[email protected]`, we removed the `websocket-star` module from the libp2p default configuration for browser nodes in `js-ipfs`. We removed it because this module was not refactored during #1670, since the libp2p goal is to [sunset the star protocols](libp2p/js-libp2p#385) and we preferred to use the time refactoring `websocket-star` into improving the browser support. In the refactor, the `webrtc-star` module was refactored so that browser users could discover other peers in the network. In addition, `circuit-relay` may be used for establishing connections between browser nodes using `websockets`. However, this migration has not been smooth for `js-ipfs` users. Users previously using `websocket-star` swarm addresses, did not have enough visibility of this change, since the removal of `websocket-star` was transparent for them and on the default `js-ipfs` release and not technically a programmable breaking change. With the above in mind, once `js-ipfs` users updated they started getting errors from `js-libp2p` in scenarios where they were providing only `websocket-star` swarm addresses. When `js-libp2p` receives listening multiaddrs, it throws an error if it cannot use any to listen on the configured transports, which was the case here (For instance #2779). In `js-libp2p`, we added an option to tolerate these errors [libp2p/js-libp2p#643](libp2p/js-libp2p#643), which was also mentioned for some other cases earlier. After syncing about this issue, we decided to temporarily throw an error when `js-ipfs` receives `websocket-star` multiaddrs. This aims to help users who still need to migrate to identify the problem faster.
1 parent a93d6d9 commit b9db5d4

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎packages/ipfs/src/core/components/start.js

+12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
'use strict'
22

3+
const log = require('debug')('ipfs:components:start')
34
const Bitswap = require('ipfs-bitswap')
45
const multiaddr = require('multiaddr')
56
const get = require('dlv')
67
const defer = require('p-defer')
8+
const errCode = require('err-code')
79
const IPNS = require('../ipns')
810
const routingConfig = require('../ipns/routing/config')
911
const { AlreadyInitializedError, NotEnabledError } = require('../errors')
1012
const Components = require('./')
1113
const createMfsPreload = require('../mfs-preload')
1214
const { withTimeoutOption } = require('../utils')
1315

16+
const WEBSOCKET_STAR_PROTO_CODE = 479
17+
1418
module.exports = ({
1519
apiManager,
1620
options: constructorOptions,
@@ -26,6 +30,8 @@ module.exports = ({
2630
repo
2731
}) => withTimeoutOption(async function start () {
2832
const startPromise = defer()
33+
startPromise.promise.catch((err) => log(err))
34+
2935
const { cancel } = apiManager.update({ start: () => startPromise.promise })
3036

3137
try {
@@ -41,6 +47,12 @@ module.exports = ({
4147
config.Addresses.Swarm.forEach(addr => {
4248
let ma = multiaddr(addr)
4349

50+
// Temporary error for users migrating using websocket-star multiaddrs for listenning on libp2p
51+
// websocket-star support was removed from ipfs and libp2p
52+
if (ma.protoCodes().includes(WEBSOCKET_STAR_PROTO_CODE)) {
53+
throw errCode(new Error('websocket-star swarm addresses are not supported. See https://github.com/ipfs/js-ipfs/issues/2779'), 'ERR_WEBSOCKET_STAR_SWARM_ADDR_NOT_SUPPORTED')
54+
}
55+
4456
// multiaddrs that go via a signalling server or other intermediary (e.g. stardust,
4557
// webrtc-star) can have the intermediary's peer ID in the address, so append our
4658
// peer ID to the end of it

‎packages/ipfs/test/core/create-node.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,21 @@ describe('create node', function () {
250250

251251
await node.stop()
252252
})
253+
254+
it('should error when receiving websocket-star swarm addresses', async () => {
255+
const node = await IPFS.create({
256+
repo: tempRepo,
257+
init: { bits: 512 },
258+
start: false,
259+
config: {
260+
Addresses: {
261+
Swarm: ['/ip4/127.0.0.1/tcp/13579/wss/p2p-websocket-star']
262+
},
263+
Bootstrap: []
264+
},
265+
preload: { enabled: false }
266+
})
267+
268+
await expect(node.start()).to.eventually.be.rejected().with.property('code', 'ERR_WEBSOCKET_STAR_SWARM_ADDR_NOT_SUPPORTED')
269+
})
253270
})

0 commit comments

Comments
 (0)
This repository has been archived.